supla-device
Loading...
Searching...
No Matches
max44009.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4// Dependencies:
5// https://github.com/RobTillaart/Max44009
6
7// Defualt I2C address: 0x4A
8// Alternative I2C address: 0x4B
9
10#ifndef SRC_SUPLA_SENSOR_MAX44009_H_
11#define SRC_SUPLA_SENSOR_MAX44009_H_
12
13#include <supla/sensor/general_purpose_measurement.h>
14
15#include <math.h>
16#include <Wire.h>
17#include <Max44009.h>
18#include <supla/log_wrapper.h>
19
20namespace Supla {
21namespace Sensor {
23 public:
24 explicit Max44009(int i2cAddress = 0x4A, TwoWire *wire = &Wire)
25 : GeneralPurposeMeasurement(nullptr, false), sensor(i2cAddress, wire) {
27 getChannel()->setDefaultIcon(14);
28 }
29
30 void onInit() override {
31 channel.setNewValue(getValue());
32 }
33
34 protected:
35 double getValue() override {
36 double value = sensor.getLux();
37 if (isnan(value) || value <= 0) {
38 if (invalidCounter < 3) {
39 invalidCounter++;
40 return lastValue;
41 }
42 lastValue = NAN;
43 return lastValue;
44 }
45 invalidCounter = 0;
46 lastValue = value;
47 return value;
48 }
49
50 ::Max44009 sensor;
51
52 double lastValue = NAN;
53 int invalidCounter = 0;
54};
55
56} // namespace Sensor
57} // namespace Supla
58
59#endif // SRC_SUPLA_SENSOR_MAX44009_H_
void setDefaultIcon(uint8_t iconId)
Sets default icon.
Definition channel.cpp:1562
void setDefaultUnitAfterValue(const char *unit)
Sets default unit which is displayed after value.
Definition general_purpose_channel_base.cpp:197
Definition general_purpose_measurement.h:11
Definition max44009.h:22
void onInit() override
Supla::Element::onInit() - called by SuplaDeviceClass::begin() during initialization.
Definition max44009.h:30
double getValue() override
Method used to obtain new value for channel.
Definition max44009.h:35