supla-device
Loading...
Searching...
No Matches
general_purpose_meter.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_SENSOR_GENERAL_PURPOSE_METER_H_
5#define SRC_SUPLA_SENSOR_GENERAL_PURPOSE_METER_H_
6
7#include "general_purpose_channel_base.h"
8#include <supla/action_handler.h>
9
10namespace Supla {
11namespace Sensor {
13 public ActionHandler {
14 public:
15#pragma pack(push, 1)
17 uint8_t counterType = 0;
18 uint8_t includeValueAddedInHistory = 0;
19 uint8_t fillMissingData = 0;
20 };
21#pragma pack(pop)
22
23 explicit GeneralPurposeMeter(MeasurementDriver *driver = nullptr,
24 bool addMemoryVariableDriver = true);
25
26 void onLoadConfig(SuplaDeviceClass *sdc) override;
27 Supla::ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result,
28 bool local) override;
29 void fillChannelConfig(void *channelConfig,
30 int *size, uint8_t configType) override;
31 void handleAction(int event, int action) override;
33 void onLoadState() override;
34 void onSaveState() override;
35
36 // Set counter to a given value
37 void setCounter(double newValue);
38 // Increment the counter by incrementBy or by valueStep when incrementBy = 0
39 void incCounter(double incrementBy = 0);
40 // Decrement the counter by decrementBy or by valueStep when decrementBy = 0
41 void decCounter(double decrementBy = 0);
42 void setValueStep(double newValueStep);
43 void setResetToValue(double newResetToValue);
44
45 void setCounterResetSupportFlag(bool support);
46 // Enable or disable keeping state in Storage
47 void setKeepStateInStorage(bool keep);
48
49 uint8_t getCounterType() const;
50 uint8_t getIncludeValueAddedInHistory() const;
51 uint8_t getFillMissingData() const;
52
53 void setCounterType(uint8_t counterType, bool local = true);
54 void setIncludeValueAddedInHistory(uint8_t includeValueAddedInHistory,
55 bool local = true);
56 void setFillMissingData(uint8_t fillMissingData, bool local = true);
57
58 protected:
59 void saveMeterSpecificConfig();
60 double valueStep = 1;
61 double resetToValue = 0;
62 bool isCounterResetSupported = true;
63 bool keepStateInStorage = false;
64
65 GPMMeterSpecificConfig meterSpecificConfig = {};
66};
67
68}; // namespace Sensor
69}; // namespace Supla
70#endif // SRC_SUPLA_SENSOR_GENERAL_PURPOSE_METER_H_
Definition SuplaDevice.h:167
Definition action_handler.h:8
Base class for General Purpose Measurement (GPM/KPOP) and General Purpose Meter (GPM/KLOP)
Definition general_purpose_channel_base.h:22
Definition general_purpose_meter.h:13
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition general_purpose_meter.cpp:293
void onLoadConfig(SuplaDeviceClass *sdc) override
Supla::Element::onLoadConfig() - called by SuplaDeviceClass::loadConfig() during initialization.
Definition general_purpose_meter.cpp:25
void onSaveState() override
Method called periodically during SuplaDevice iteration.
Definition general_purpose_meter.cpp:286
Supla::ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result, bool local) override
Applies new Channel Config (i.e.
Definition general_purpose_meter.cpp:44
int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request) override
Handles CALCFG requests from server.
Definition general_purpose_meter.cpp:234
void fillChannelConfig(void *channelConfig, int *size, uint8_t configType) override
Fills Channel Config.
Definition general_purpose_meter.cpp:105
Definition measurement_driver.h:9
Definition proto.h:3159
Definition proto.h:2315