CuteHMI - Modbus (CuteHMI.Modbus.4)
Register1Controller.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_REGISTER1CONTROLLER_HPP
2#define H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_REGISTER1CONTROLLER_HPP
3
4#include "internal/common.hpp"
5#include "internal/RegisterControllerMixin.hpp"
6#include "AbstractDevice.hpp"
7#include "Register1.hpp"
8#include "AbstractRegisterController.hpp"
9
10#include <QObject>
11#include <QBasicTimer>
12#include <QQmlEngine>
13
14namespace cutehmi {
15namespace modbus {
16
20class CUTEHMI_MODBUS_API Register1Controller:
22 protected internal::RegisterControllerMixin<Register1Controller>
23{
24 Q_OBJECT
25 QML_NAMED_ELEMENT(Register1Controller)
26 QML_UNCREATABLE("Register1Controller is an abstract class")
27
30
31 public:
32 static constexpr bool INITIAL_VALUE = false;
33
34 Q_PROPERTY(bool value READ value WRITE setValue NOTIFY valueChanged)
35
36 Register1Controller(QObject * parent = nullptr);
37
38 ~Register1Controller() override;
39
40 bool value() const;
41
42 void setValue(bool value);
43
44 public slots:
45 void writeValue();
46
47 signals:
49
51
53
55
57
58 protected:
59 virtual Register1 * registerAt(quint16 address) const = 0;
60
62
64
65 virtual void requestWriteRegister(quint16 address, bool value, QUuid * requestId) const = 0;
66
67 void timerEvent(QTimerEvent * event) override;
68
69 quint16 bytes() const override;
70
71 void onDeviceDestroyed() override;
72
73 protected slots:
74 void onRequestCompleted(QJsonObject request, QJsonObject reply) override;
75
76 void resetRegister();
77
78 private:
79 void updateValue();
80
81 void updateValue(bool value);
82
83 void updateValue(const QJsonValue & value);
84
85 void requestWrite(bool value);
86
87 bool verifyRegisterValue() const;
88
89 private:
90 struct Members {
91 bool value;
92 bool postponedWritePending;
93 bool adjustingValue;
94 bool requestedValue;
95 Register1 * register1;
96 QUuid requestId;
97 QBasicTimer writeTimer;
98
99 Members():
100 value(INITIAL_VALUE),
101 postponedWritePending(false),
102 adjustingValue(false),
103 requestedValue(0.0),
104 register1(nullptr)
105 {
106 }
107 };
108
110};
111
112}
113}
114
115#endif
116
117//(c)C: Copyright © 2022, Michał Policht <michal@policht.pl>. All rights reserved.
118//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
119//(c)C: This file is a part of CuteHMI.
120//(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
121//(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
122//(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>.
123//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
124//(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
125//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
126//(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Function
Definition: AbstractDevice.hpp:56
Abstract register controller.
Definition: AbstractRegisterController.hpp:20
Register controller for 1 bit registers.
Definition: Register1Controller.hpp:23
virtual AbstractDevice::Function writeRegisterFunction() const =0
virtual AbstractDevice::Function readRegistersFunction() const =0
virtual Register1 * registerAt(quint16 address) const =0
virtual void requestWriteRegister(quint16 address, bool value, QUuid *requestId) const =0
Cached properties of 1 bit register.
Definition: Register1.hpp:15
Definition: RegisterControllerMixin.hpp:18