Usermod class vars pt3:
Moved initDone, addToConfig and readFromConfig to Usermod superclass
Updated cleanup procedure:
Part 1
- remove bool enabled = false/true (now default false)
- remove static const char _name[] and _enabled[]
- add constructor which calls superclass (temp?): XXXUsermod(const char *name, bool enabled):Usermod(name, enabled) {}
- replace _enabled with "enabled"
- remove const char PROGMEM init for _name[] and _enabled[]
Part 2
- Remove bool initDone = false;
- addToConfig: replace createNestedObject with Usermod::addToConfig(root); JsonObject top = root[FPSTR(_name)];
- readFromConfig: replace !top.isNull and enabled with bool configComplete = Usermod::readFromConfig(root);JsonObject top = root[FPSTR(_name)];
See Temperature, MPU6050 and weather as examples (rest to be done)
This commit is contained in:
@@ -93,7 +93,6 @@ void IRAM_ATTR dmpDataReady() {
|
||||
class MPU6050Driver : public Usermod {
|
||||
private:
|
||||
MPU6050 mpu;
|
||||
bool initDone = false;
|
||||
unsigned long lastUMRun = millis();
|
||||
|
||||
// MPU control/status vars
|
||||
@@ -354,14 +353,14 @@ class MPU6050Driver : public Usermod {
|
||||
//{
|
||||
//}
|
||||
|
||||
void addToConfig(JsonObject& root)
|
||||
{
|
||||
JsonObject top = root.createNestedObject(FPSTR(_name));
|
||||
top[FPSTR("enabled")] = enabled;
|
||||
//JsonObject interruptPin = top.createNestedObject(FPSTR(_INT_pin));
|
||||
//interruptPin["pin"] = INTERRUPT_PIN;
|
||||
DEBUG_PRINTLN(F("MPU6050 IMU config saved."));
|
||||
}
|
||||
// void addToConfig(JsonObject& root)
|
||||
// {
|
||||
// Usermod::addToConfig(root);
|
||||
// JsonObject top = root[FPSTR(_name)];
|
||||
// // //JsonObject interruptPin = top.createNestedObject(FPSTR(_INT_pin));
|
||||
// // //interruptPin["pin"] = INTERRUPT_PIN;
|
||||
// // DEBUG_PRINTLN(F("MPU6050 IMU config saved."));
|
||||
// }
|
||||
|
||||
//WLEDMM: add appendConfigData
|
||||
void appendConfigData()
|
||||
@@ -380,6 +379,7 @@ class MPU6050Driver : public Usermod {
|
||||
|
||||
bool readFromConfig(JsonObject& root)
|
||||
{
|
||||
bool configComplete = Usermod::readFromConfig(root);
|
||||
JsonObject top = root[FPSTR(_name)];
|
||||
|
||||
if (top.isNull()) {
|
||||
@@ -388,8 +388,6 @@ class MPU6050Driver : public Usermod {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool configComplete = !top.isNull();
|
||||
configComplete &= getJsonValue(top[FPSTR("enabled")], enabled);
|
||||
//configComplete &= getJsonValue(top[FPSTR(_INT_pin)]["pin"], INTERRUPT_PIN);
|
||||
|
||||
DEBUG_PRINT(FPSTR(_name));
|
||||
|
||||
Reference in New Issue
Block a user