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 protected:
52 uint64_t counter = 0; // Actual count of impulses
53 uint32_t lastReadTime = 0;
54};
55
56} // namespace Sensor
57} // namespace Supla
58
59#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:33
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition virtual_impulse_counter.cpp:44
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition virtual_impulse_counter.cpp:64
int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request) override
Handles CALCFG requests from server.
Definition virtual_impulse_counter.cpp:89
void onSaveState() override
Method called periodically during SuplaDevice iteration.
Definition virtual_impulse_counter.cpp:40
Definition proto.h:2246