supla-device
Loading...
Searching...
No Matches
virtual_impulse_counter.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#ifndef SRC_SUPLA_SENSOR_VIRTUAL_IMPULSE_COUNTER_H_
20#define SRC_SUPLA_SENSOR_VIRTUAL_IMPULSE_COUNTER_H_
21
22#include <supla-common/proto.h>
23#include <supla/action_handler.h>
24#include <supla/channel_element.h>
25
26namespace Supla {
27
28namespace Sensor {
29class VirtualImpulseCounter : public ChannelElement, public ActionHandler {
30 public:
31 VirtualImpulseCounter();
32
33 void onInit() override;
34 void onLoadState() override;
35 void onSaveState() override;
36 void iterateAlways() override;
37 void handleAction(int event, int action) override;
39
40 // Returns value of a counter at given Supla channel
41 uint64_t getCounter() const;
42
43 // Set counter to a given value
44 void setCounter(uint64_t value);
45
46 // Increment the counter by 1
47 void incCounter();
48
49 virtual void resetCounter();
50
51 void setForceStateSaveOnChange(bool value);
52 void setDefaultImpulsesPerUnit(uint32_t impulsesPerUnit);
53
54 protected:
55 Supla::ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result,
56 bool local) override;
57 void fillChannelConfig(void *channelConfig,
58 int *size,
59 uint8_t configType) override;
60
61 uint64_t counter = 0; // Actual count of impulses
62 uint32_t lastReadTime = 0;
63 uint32_t defaultImpulsesPerUnit = 1000;
64 bool forceStateSaveOnChange = false;
65};
66
67} // namespace Sensor
68} // namespace Supla
69
70#endif // SRC_SUPLA_SENSOR_VIRTUAL_IMPULSE_COUNTER_H_
Definition action_handler.h:21
void onInit() override
Third method called on element in SuplaDevice.begin().
Definition virtual_impulse_counter.cpp:38
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition virtual_impulse_counter.cpp:49
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition virtual_impulse_counter.cpp:71
int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request) override
Handles CALCFG requests from server.
Definition virtual_impulse_counter.cpp:99
void onSaveState() override
Method called periodically during SuplaDevice iteration.
Definition virtual_impulse_counter.cpp:45
Definition proto.h:3412
Definition proto.h:2593