diff --git a/src/AppConfiguration.cpp b/src/AppConfiguration.cpp index 2623f5f..3dbd51a 100644 --- a/src/AppConfiguration.cpp +++ b/src/AppConfiguration.cpp @@ -68,10 +68,11 @@ boolean AppConfiguration::readPreferences() { config.idleLightTimeout = doc["idleLightTimeout"] | 60000; config.mallGrab = doc["mallGrab"].as()| false; config.mtuSize = doc["mtuSize"] | 512; - config.oddevenActive = doc["oddevenActive"] | true; + config.oddevenActive = doc["oddevenActive"] | false; config.lightsSwitch = true; config.saveConfig = false; config.sendConfig = false; + config.sendConfigFinished = true; if(doc.overflowed()) { return false; @@ -113,6 +114,8 @@ boolean AppConfiguration::savePreferences() { doc["idleLightTimeout"] = config.idleLightTimeout; doc["mallGrab"] = config.mallGrab; doc["mtuSize"] = config.mtuSize; + doc["oddevenActive"] = config.oddevenActive; + String json = ""; serializeJson(doc, json); ESP_LOGI(TAG, "savePreferences: %s", json.c_str()); diff --git a/src/AppConfiguration.h b/src/AppConfiguration.h index faec98b..2013529 100644 --- a/src/AppConfiguration.h +++ b/src/AppConfiguration.h @@ -11,11 +11,11 @@ struct Config { BEGIN_VISITABLES(Config); VISITABLE(String, deviceName); - VISITABLE(boolean, otaUpdateActive); - VISITABLE(boolean, isNotificationEnabled); - VISITABLE(boolean, isBatteryNotificationEnabled); - VISITABLE(boolean, isCurrentNotificationEnabled); - VISITABLE(boolean, isErpmNotificationEnabled); + VISITABLE(bool, otaUpdateActive); + VISITABLE(bool, isNotificationEnabled); + VISITABLE(bool, isBatteryNotificationEnabled); + VISITABLE(bool, isCurrentNotificationEnabled); + VISITABLE(bool, isErpmNotificationEnabled); VISITABLE(double, minBatteryVoltage); VISITABLE(double, lowBatteryVoltage); VISITABLE(double, maxBatteryVoltage); @@ -40,24 +40,24 @@ struct Config { VISITABLE(int, lightColorSecondaryBlue); VISITABLE(int, lightbarTurnOffErpm); VISITABLE(int, lightbarMaxBrightness); - VISITABLE(boolean, brakeLightEnabled); + VISITABLE(bool, brakeLightEnabled); VISITABLE(int, numberPixelLight); VISITABLE(int, numberPixelBatMon); VISITABLE(int, vescId); - VISITABLE(boolean, saveConfig); - VISITABLE(boolean, sendConfig); + VISITABLE(bool, saveConfig); + VISITABLE(bool, sendConfig); VISITABLE(String , ledType); VISITABLE(String , lightBarLedType); VISITABLE(String , ledFrequency); VISITABLE(String , lightBarLedFrequency); - VISITABLE(boolean , isLightBarReversed); - VISITABLE(boolean , isLightBarLedTypeDifferent); + VISITABLE(bool , isLightBarReversed); + VISITABLE(bool , isLightBarLedTypeDifferent); VISITABLE(int , idleLightTimeout); VISITABLE(bool , mallGrab); VISITABLE(int , mtuSize); - VISITABLE(boolean , oddevenActive); - VISITABLE(boolean, lightsSwitch); - VISITABLE(boolean, sendConfigFinished); + VISITABLE(bool , oddevenActive); + VISITABLE(bool, lightsSwitch); + VISITABLE(bool, sendConfigFinished); END_VISITABLES; }; diff --git a/src/BleServer.cpp b/src/BleServer.cpp index b41fc23..4d913d2 100644 --- a/src/BleServer.cpp +++ b/src/BleServer.cpp @@ -251,6 +251,7 @@ void BleServer::onWrite(BLECharacteristic *pCharacteristic) { //Serial.println(String(key.c_str()) + String("=") + String(value.c_str())); + snprintf(buf, bufSize, "Updated param \"%s\" to %s", key.c_str(), value.c_str()); if (key == "config") { AppConfiguration::getInstance()->config.sendConfig = true; } else if (key == "save") { @@ -273,7 +274,6 @@ void BleServer::onWrite(BLECharacteristic *pCharacteristic) { AppConfiguration::getInstance()->config.startSoundIndex = parseInt(value); Buzzer::stopSound(); Buzzer::playSound(RTTTL_MELODIES(strtol(value.c_str(), nullptr, 10))); - snprintf(buf, bufSize, "Updated param \"StartSoundIndex\" to %s", value.c_str()); } else if (key == "startLightIndex") { AppConfiguration::getInstance()->config.startLightIndex = parseInt(value); } else if (key == "batteryWarningSoundIndex") { @@ -327,11 +327,11 @@ void BleServer::onWrite(BLECharacteristic *pCharacteristic) { } else if (key == "lightBarLedFrequency") { AppConfiguration::getInstance()->config.lightBarLedFrequency = value.c_str(); } else if (key == "isLightBarReversed") { - AppConfiguration::getInstance()->config.isLightBarReversed = value.c_str(); + AppConfiguration::getInstance()->config.isLightBarReversed = parseInt(value); } else if (key == "isLightBarLedTypeDifferent") { - AppConfiguration::getInstance()->config.isLightBarLedTypeDifferent = value.c_str(); + AppConfiguration::getInstance()->config.isLightBarLedTypeDifferent = parseInt(value); } else if (key == "mallGrab") { - AppConfiguration::getInstance()->config.mallGrab = value.c_str(); + AppConfiguration::getInstance()->config.mallGrab = parseInt(value); } else if (key == "mtuSize") { uint16_t mtu = strtol(value.c_str(), nullptr, 10); AppConfiguration::getInstance()->config.mtuSize = mtu; diff --git a/src/LightBarController.cpp b/src/LightBarController.cpp index 3155d50..56efc98 100644 --- a/src/LightBarController.cpp +++ b/src/LightBarController.cpp @@ -12,18 +12,17 @@ boolean pixelCountOdd = false; AdcState lastAdcState = AdcState::ADC_NONE; unsigned long lastAdcStateChange = 0; -LightBarController::LightBarController() { +LightBarController::LightBarController() {} + +void LightBarController::init() { pixel_count = AppConfiguration::getInstance()->config.numberPixelBatMon; min_voltage = (int) AppConfiguration::getInstance()->config.minBatteryVoltage * 100; max_voltage = (int) AppConfiguration::getInstance()->config.maxBatteryVoltage * 100; pixelCountOdd = pixel_count % 2 == 1; uint8_t ledType; - if(AppConfiguration::getInstance()->config.isLightBarLedTypeDifferent) - { + if(AppConfiguration::getInstance()->config.isLightBarLedTypeDifferent) { ledType = LedControllerFactory::getInstance()->determineLedType(true); - } - else - { + } else { ledType = LedControllerFactory::getInstance()->determineLedType(); } voltage_range = max_voltage - min_voltage; @@ -32,8 +31,7 @@ LightBarController::LightBarController() { lightPixels.begin(); // This initializes the NeoPixel library. for (int j = 0; j < pixel_count; j++) { int actualIndex = j; - if(AppConfiguration::getInstance()->config.isLightBarReversed) - { + if(AppConfiguration::getInstance()->config.isLightBarReversed) { actualIndex = pixel_count - 1 - j; } lightPixels.setPixelColor(actualIndex, 51, 153, 255); @@ -41,6 +39,7 @@ LightBarController::LightBarController() { lightPixels.show(); } + // updates the light bar, depending on the LED count void LightBarController::updateLightBar(double voltage, uint16_t switchstate, double adc1, double adc2, double erpm) { AdcState adcState = this->mapSwitchState(switchstate, adc1 > adc2); @@ -68,9 +67,9 @@ void LightBarController::updateLightBar(double voltage, uint16_t switchstate, do if (adcState != lastAdcState) { for (int i = 0; i < pixel_count; i++) { int actualIndex = i; - #ifdef REVERSE_LED_STRIP + if(AppConfiguration::getInstance()->config.isLightBarReversed) { actualIndex = pixel_count - 1 - i; - #endif + } lightPixels.setPixelColor(actualIndex, 0, 0, 0); switch (adcState) { case ADC_NONE: @@ -96,15 +95,14 @@ void LightBarController::updateLightBar(double voltage, uint16_t switchstate, do // update every pixel individually for (int i = 0; i < pixel_count; i++) { int actualIndex = i; - #ifdef REVERSE_LED_STRIP + if(AppConfiguration::getInstance()->config.isLightBarReversed) { actualIndex = pixel_count - 1 - i; - #endif + } if (i == whole) { // the last pixel, the battery voltage somewhere in the range of this pixel // the lower the remaining value the more the pixel goes from green to red int val = calcVal(remainder); - lightPixels.setPixelColor(i, AppConfiguration::getInstance()->config.lightbarMaxBrightness - val, val, - 0); + lightPixels.setPixelColor(i, AppConfiguration::getInstance()->config.lightbarMaxBrightness - val, val, 0); } if (i > whole) { // these pixels must be turned off, we already reached a lower battery voltage diff --git a/src/LightBarController.h b/src/LightBarController.h index 371d445..aa7b309 100644 --- a/src/LightBarController.h +++ b/src/LightBarController.h @@ -26,6 +26,7 @@ enum AdcState { class LightBarController { public: LightBarController(); + void init(); void updateLightBar(double voltage, uint16_t switchstate, double adc1, double adc2, double erpm); private: diff --git a/src/config.h b/src/config.h index ff8578c..5c33ae9 100644 --- a/src/config.h +++ b/src/config.h @@ -7,7 +7,7 @@ #define SOFTWARE_VERSION_MAJOR 2 #define SOFTWARE_VERSION_MINOR 5 -#define SOFTWARE_VERSION_PATCH 1 +#define SOFTWARE_VERSION_PATCH 3 #ifndef ESP32S3 #define HARDWARE_VERSION_MAJOR 3 diff --git a/src/main.cpp b/src/main.cpp index f33ecb7..17bc6a3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -106,6 +106,7 @@ void setup() { #endif // initialize the LED (either COB or Neopixel) ledController->init(); + lightbar->init(); Buzzer::startSequence(); ledController->startSequence();