supla-device
Loading...
Searching...
No Matches
general_purpose_meter.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_GENERAL_PURPOSE_METER_H_
20#define SRC_SUPLA_SENSOR_GENERAL_PURPOSE_METER_H_
21
22#include "general_purpose_channel_base.h"
23#include <supla/action_handler.h>
24
25namespace Supla {
26namespace Sensor {
27class GeneralPurposeMeter : public GeneralPurposeChannelBase,
28 public ActionHandler {
29 public:
30#pragma pack(push, 1)
32 uint8_t counterType = 0;
33 uint8_t includeValueAddedInHistory = 0;
34 uint8_t fillMissingData = 0;
35 };
36#pragma pack(pop)
37
38 explicit GeneralPurposeMeter(MeasurementDriver *driver = nullptr,
39 bool addMemoryVariableDriver = true);
40
41 void onLoadConfig(SuplaDeviceClass *sdc) override;
42 uint8_t applyChannelConfig(TSD_ChannelConfig *result, bool local) override;
43 void fillChannelConfig(void *channelConfig, int *size) override;
44 void handleAction(int event, int action) override;
46 void onLoadState() override;
47 void onSaveState() override;
48
49 // Set counter to a given value
50 void setCounter(double newValue);
51 // Increment the counter by incrementBy or by valueStep when incrementBy = 0
52 void incCounter(double incrementBy = 0);
53 // Decrement the counter by decrementBy or by valueStep when decrementBy = 0
54 void decCounter(double decrementBy = 0);
55 void setValueStep(double newValueStep);
56 void setResetToValue(double newResetToValue);
57
58 void setCounterResetSupportFlag(bool support);
59 // Enable or disable keeping state in Storage
60 void setKeepStateInStorage(bool keep);
61
62 uint8_t getCounterType() const;
63 uint8_t getIncludeValueAddedInHistory() const;
64 uint8_t getFillMissingData() const;
65
66 void setCounterType(uint8_t counterType, bool local = true);
67 void setIncludeValueAddedInHistory(uint8_t includeValueAddedInHistory,
68 bool local = true);
69 void setFillMissingData(uint8_t fillMissingData, bool local = true);
70
71 protected:
72 void saveMeterSpecificConfig();
73 double valueStep = 1;
74 double resetToValue = 0;
75 bool isCounterResetSupported = true;
76 bool keepStateInStorage = false;
77
78 GPMMeterSpecificConfig meterSpecificConfig = {};
79};
80
81}; // namespace Sensor
82}; // namespace Supla
83#endif // SRC_SUPLA_SENSOR_GENERAL_PURPOSE_METER_H_
Definition SuplaDevice.h:93
GeneralPurposeChannelBase(MeasurementDriver *driver=nullptr, bool addMemoryVariableDriver=true)
Constructor.
Definition general_purpose_channel_base.cpp:33
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition general_purpose_meter.cpp:304
void fillChannelConfig(void *channelConfig, int *size) override
Fills Channel Config.
Definition general_purpose_meter.cpp:121
uint8_t applyChannelConfig(TSD_ChannelConfig *result, bool local) override
Applies new Channel Config (i.e.
Definition general_purpose_meter.cpp:57
void onLoadConfig(SuplaDeviceClass *sdc) override
Supla::Element::onLoadConfig() - called by SuplaDeviceClass::loadConfig() during initialization.
Definition general_purpose_meter.cpp:38
void onSaveState() override
Method called periodically during SuplaDevice iteration.
Definition general_purpose_meter.cpp:297
int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request) override
Handles CALCFG requests from server.
Definition general_purpose_meter.cpp:245
Definition general_purpose_meter.h:31
Definition proto.h:2912
Definition proto.h:2246