Address comments

This commit is contained in:
Michael Bisbjerg 2024-05-14 17:54:43 +02:00
parent 68f6b3452e
commit f71d839009
4 changed files with 195 additions and 176 deletions

View File

@ -94,6 +94,9 @@ build_flags = ${common.build_flags} ${esp8266.build_flags}
; -D USERMOD_AUTO_SAVE ; -D USERMOD_AUTO_SAVE
; -D AUTOSAVE_AFTER_SEC=90 ; -D AUTOSAVE_AFTER_SEC=90
; ;
; Use AHT10/AHT15/AHT20 usermod
; -D USERMOD_AHT10
;
; Use 4 Line Display usermod with SPI display ; Use 4 Line Display usermod with SPI display
; -D USERMOD_FOUR_LINE_DISPLAY ; -D USERMOD_FOUR_LINE_DISPLAY
; -D USE_ALT_DISPlAY # mandatory ; -D USE_ALT_DISPlAY # mandatory

View File

@ -17,6 +17,9 @@ Dependencies, These must be added under `lib_deps` in your `platform.ini` (or `p
- `enjoyneering/AHT10@~1.1.0` (by [enjoyneering](https://registry.platformio.org/libraries/enjoyneering/AHT10)) - `enjoyneering/AHT10@~1.1.0` (by [enjoyneering](https://registry.platformio.org/libraries/enjoyneering/AHT10))
- `Wire` - `Wire`
## Author
[@LordMike](https://github.com/LordMike)
# Compiling # Compiling
To enable, compile with `USERMOD_AHT10` defined (e.g. in `platformio_override.ini`) To enable, compile with `USERMOD_AHT10` defined (e.g. in `platformio_override.ini`)

View File

@ -5,8 +5,9 @@
#define AHT10_SUCCESS 1 #define AHT10_SUCCESS 1
class UsermodAHT10 : public Usermod { class UsermodAHT10 : public Usermod
private: {
private:
static const char _name[]; static const char _name[];
unsigned long _lastLoopCheck = 0; unsigned long _lastLoopCheck = 0;
@ -25,12 +26,15 @@ class UsermodAHT10 : public Usermod {
AHT10* _aht = nullptr; AHT10* _aht = nullptr;
float truncateDecimals(float val) { float truncateDecimals(float val)
{
return roundf(val * _decimalFactor) / _decimalFactor; return roundf(val * _decimalFactor) / _decimalFactor;
} }
void initializeAht() { void initializeAht()
if (_aht != nullptr) { {
if (_aht != nullptr)
{
delete _aht; delete _aht;
} }
@ -41,17 +45,20 @@ class UsermodAHT10 : public Usermod {
_lastTemperature = 0; _lastTemperature = 0;
} }
~UsermodAHT10() { ~UsermodAHT10()
{
delete _aht; delete _aht;
_aht = nullptr; _aht = nullptr;
} }
public: public:
void setup() { void setup()
{
initializeAht(); initializeAht();
} }
void loop() { void loop()
{
// if usermod is disabled or called during strip updating just exit // if usermod is disabled or called during strip updating just exit
// NOTE: on very long strips strip.isUpdating() may always return true so update accordingly // NOTE: on very long strips strip.isUpdating() may always return true so update accordingly
if (!_enabled || strip.isUpdating()) if (!_enabled || strip.isUpdating())
@ -92,12 +99,17 @@ class UsermodAHT10 : public Usermod {
} }
} }
uint16_t getId()
{
return USERMOD_ID_AHT10;
}
void addToJsonInfo(JsonObject& root) override void addToJsonInfo(JsonObject& root) override
{ {
// if "u" object does not exist yet wee need to create it // if "u" object does not exist yet wee need to create it
JsonObject user = root["u"]; JsonObject user = root[F("u")];
if (user.isNull()) if (user.isNull())
user = root.createNestedObject("u"); user = root.createNestedObject(F("u"));
#ifdef USERMOD_AHT10_DEBUG #ifdef USERMOD_AHT10_DEBUG
JsonArray temp = user.createNestedArray(F("status")); JsonArray temp = user.createNestedArray(F("status"));
@ -154,9 +166,9 @@ class UsermodAHT10 : public Usermod {
if (!configComplete) if (!configComplete)
return false; return false;
configComplete &= getJsonValue(top["Enabled"], _enabled); configComplete &= getJsonValue(top[F("Enabled")], _enabled);
configComplete &= getJsonValue(top["I2CAddress"], _i2cAddress); configComplete &= getJsonValue(top[F("I2CAddress")], _i2cAddress);
configComplete &= getJsonValue(top["CheckInterval"], _checkInterval); configComplete &= getJsonValue(top[F("CheckInterval")], _checkInterval);
if (configComplete) if (configComplete)
{ {
if (1 <= _checkInterval && _checkInterval <= 600) if (1 <= _checkInterval && _checkInterval <= 600)
@ -166,7 +178,7 @@ class UsermodAHT10 : public Usermod {
_checkInterval = 60000; _checkInterval = 60000;
} }
configComplete &= getJsonValue(top["Decimals"], _decimalFactor); configComplete &= getJsonValue(top[F("Decimals")], _decimalFactor);
if (configComplete) if (configComplete)
{ {
if (0 <= _decimalFactor && _decimalFactor <= 5) if (0 <= _decimalFactor && _decimalFactor <= 5)
@ -177,14 +189,14 @@ class UsermodAHT10 : public Usermod {
} }
uint8_t tmpAhtType; uint8_t tmpAhtType;
configComplete &= getJsonValue(top["SensorType"], tmpAhtType); configComplete &= getJsonValue(top[F("SensorType")], tmpAhtType);
if (configComplete) if (configComplete)
{ {
if (0 <= tmpAhtType && tmpAhtType <= 2) if (0 <= tmpAhtType && tmpAhtType <= 2)
_ahtType = static_cast<ASAIR_I2C_SENSOR>(tmpAhtType); _ahtType = static_cast<ASAIR_I2C_SENSOR>(tmpAhtType);
else else
// Invalid input // Invalid input
_ahtType = 0; _ahtType = ASAIR_I2C_SENSOR::AHT10_SENSOR;
} }
if (_initDone) if (_initDone)

View File

@ -178,6 +178,7 @@
#define USERMOD_ID_HTTP_PULL_LIGHT_CONTROL 46 //usermod "usermod_v2_HttpPullLightControl.h" #define USERMOD_ID_HTTP_PULL_LIGHT_CONTROL 46 //usermod "usermod_v2_HttpPullLightControl.h"
#define USERMOD_ID_TETRISAI 47 //Usermod "usermod_v2_tetris.h" #define USERMOD_ID_TETRISAI 47 //Usermod "usermod_v2_tetris.h"
#define USERMOD_ID_MAX17048 48 //Usermod "usermod_max17048.h" #define USERMOD_ID_MAX17048 48 //Usermod "usermod_max17048.h"
#define USERMOD_ID_AHT10 49 //Usermod "usermod_aht10.h"
//Access point behavior //Access point behavior
#define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot #define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot