diff --git a/vscode/OmobiLEDdisplayBluetooth/.vscode/extensions.json b/vscode/OmobiLEDdisplayBluetooth/.vscode/extensions.json index 0f0d740..080e70d 100644 --- a/vscode/OmobiLEDdisplayBluetooth/.vscode/extensions.json +++ b/vscode/OmobiLEDdisplayBluetooth/.vscode/extensions.json @@ -1,7 +1,10 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ] -} +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/vscode/OmobiLEDdisplayBluetooth/.vscode/settings.json b/vscode/OmobiLEDdisplayBluetooth/.vscode/settings.json index b46ce26..0b48d43 100644 --- a/vscode/OmobiLEDdisplayBluetooth/.vscode/settings.json +++ b/vscode/OmobiLEDdisplayBluetooth/.vscode/settings.json @@ -18,5 +18,6 @@ "numeric": "cpp", "streambuf": "cpp", "utility": "cpp" - } + }, + "svn.ignoreMissingSvnWarning": true } \ No newline at end of file diff --git a/vscode/OmobiLEDdisplayBluetooth/include/LedDisplayController.h b/vscode/OmobiLEDdisplayBluetooth/include/LedDisplayController.h index 0dc7981..49cdfe3 100644 --- a/vscode/OmobiLEDdisplayBluetooth/include/LedDisplayController.h +++ b/vscode/OmobiLEDdisplayBluetooth/include/LedDisplayController.h @@ -36,6 +36,8 @@ public: textpixel = 0; disp_show = false; + setsModiefiedLastTime_ms = 0; + setModifyingActive = false; this->brightness_init(); this->disp_init(); @@ -98,6 +100,11 @@ public: private: + // modified status + const unsigned long msToWaitBeforeModifyGetsInactive = 2000; //milliseconds + unsigned long setsModiefiedLastTime_ms; + bool setModifyingActive; + // matrix objects TaskHandle_t displayUpdateTask; NeoPixelBrightnessBusGfx *matrix; @@ -159,14 +166,19 @@ private: } sets_t; // storage variables - const text_set_t defaultTextSet {"", false, 0, "", AlignCenter, false, 0, 0, 0}; + const text_set_t defaultTextSet {"", false, 1, "ffffff", AlignCenter, false, 0, 0, 0}; sets_t text_sets; + //FIXME: Add a second set of data here - one is the active one that gets read and the other is the inaktive one that is written ... + // after a write occurs and after a second on no more write action the sets are switched ... this is to avoid races ... + // In case there was an deletion of a set ... the index has to be take into account ... it shell never point to an illegal aarea afterwards or + // or to another than before ... in case the delted set was the current active one ... // storage control EepromUnit* eepromUnit; GetSetTextSetParameterExitCode getSetTextSetParameter(int index, DisplayTextSetParameter parameter, String *value, bool set = false); bool storeTextSets(); bool loadTextSets(); + bool storeDataToEEPROM(); }; diff --git a/vscode/OmobiLEDdisplayBluetooth/include/OmobiLedDisplay.h b/vscode/OmobiLEDdisplayBluetooth/include/OmobiLedDisplay.h index fafbd58..b009620 100644 --- a/vscode/OmobiLEDdisplayBluetooth/include/OmobiLedDisplay.h +++ b/vscode/OmobiLEDdisplayBluetooth/include/OmobiLedDisplay.h @@ -48,6 +48,7 @@ protected: void onDataReceived(String data) override; private: + enum OmobiDisplayCommand { AuthenticateCommand = 0, diff --git a/vscode/OmobiLEDdisplayBluetooth/src/BluetoothLeUartServer.cpp b/vscode/OmobiLEDdisplayBluetooth/src/BluetoothLeUartServer.cpp index f6ec47a..112efa5 100644 --- a/vscode/OmobiLEDdisplayBluetooth/src/BluetoothLeUartServer.cpp +++ b/vscode/OmobiLEDdisplayBluetooth/src/BluetoothLeUartServer.cpp @@ -52,7 +52,9 @@ void BluetoothLeUartServer::setCallbacks(BluetoothLeUartServerCallbacks *callbac void BluetoothLeUartServer::sendData(String data) { - txCharacteristic->setValue(data.c_str()); + //txCharacteristic->setValue(data.c_str()); + //Serial.printf("String is : '%s' with length of %d\n", data.c_str(), data.length() ); + txCharacteristic->setValue((uint8_t*)data.c_str(),data.length()); txCharacteristic->notify(); } @@ -96,6 +98,8 @@ void BluetoothLeUartServer::onDisconnect(BLEServer *pServer) { this->deviceConnected = false; this->deviceConnectionId = -1; + bleServer->getAdvertising()->start(); + Serial.println("Restart advertising after disconnect ..."); if (this->callbacks != nullptr) this->callbacks->onDeviceConnectedChanged(this->deviceConnected); diff --git a/vscode/OmobiLEDdisplayBluetooth/src/LedDisplayController.cpp b/vscode/OmobiLEDdisplayBluetooth/src/LedDisplayController.cpp index 752c234..d09c94c 100644 --- a/vscode/OmobiLEDdisplayBluetooth/src/LedDisplayController.cpp +++ b/vscode/OmobiLEDdisplayBluetooth/src/LedDisplayController.cpp @@ -7,13 +7,14 @@ void LedDisplayController::loop() { //Serial.printf("Ligth: %d \n" , analogRead(36)); + storeDataToEEPROM(); if (this->disp_show) { measureBrightnessEnv(); disp_start_set(); if (true == text_sets.sets[text_curr_nr].active) { - if (text_sets.sets[text_curr_nr].text != '\0') + if (text_sets.sets[text_curr_nr].text[0] != '\0') { if (text_sets.sets[text_curr_nr].scroll) { @@ -24,6 +25,31 @@ void LedDisplayController::loop() } } +bool LedDisplayController::storeDataToEEPROM() +{ + + if(millis() - this->setsModiefiedLastTime_ms > this->msToWaitBeforeModifyGetsInactive) + { + if(true == this->setModifyingActive) + { + this->setModifyingActive = false; + Serial.println("Sets are not longer modified by external data ..."); + Serial.println("Storing Text Sets To EEPROM now..."); + if (this->eepromUnit == nullptr) + { + Serial.println("ERROR"); + return false; + } + + strncpy(this->text_sets.valid, "OK", sizeof(this->text_sets.valid)); + this->eepromUnit->write(this->text_sets); + Serial.println("OK"); + return true; + } + } + return true; +} + bool LedDisplayController::registerEepromUnit(EepromManager *eepromManager) { if (this->eepromUnit != nullptr) @@ -121,7 +147,7 @@ void LedDisplayController::disp_start_set() // current entry is not active (text_sets.sets[text_curr_nr].active == false) || // current entry has no text defined - (text_sets.sets[text_curr_nr].text == '\0') || + (text_sets.sets[text_curr_nr].text[0] == '\0') || // current entry is not scrolling: but no runtime is defined ((text_sets.sets[text_curr_nr].scroll == false) && (text_sets.sets[text_curr_nr].runtime == 0)) || // current entry is scrolling: but no scrollnumber defined @@ -441,16 +467,9 @@ LedDisplayController::GetSetTextSetParameterExitCode LedDisplayController::getSe bool LedDisplayController::storeTextSets() { - Serial.println("Storing Text Sets..."); - if (this->eepromUnit == nullptr) - { - Serial.println("ERROR"); - return false; - } - - strncpy(this->text_sets.valid, "OK", sizeof(this->text_sets.valid)); - this->eepromUnit->write(this->text_sets); - Serial.println("OK"); + Serial.println("Text Sets where modified ..."); + this->setsModiefiedLastTime_ms = millis(); + this->setModifyingActive = true; return true; } diff --git a/vscode/OmobiLEDdisplayBluetooth/src/OmobiLedDisplay.cpp b/vscode/OmobiLEDdisplayBluetooth/src/OmobiLedDisplay.cpp index 6d9e528..a897ae4 100644 --- a/vscode/OmobiLEDdisplayBluetooth/src/OmobiLedDisplay.cpp +++ b/vscode/OmobiLEDdisplayBluetooth/src/OmobiLedDisplay.cpp @@ -91,14 +91,14 @@ void OmobiLedDisplay::onDataReceived(String dataString) { if (this->ledDisplayController->getTextSetParameter(textSetIndex, LedDisplayController::TextParameter) == "") continue; - + Serial.println("Adding index " + String(textSetIndex) + " with text: " + this->ledDisplayController->getTextSetParameter(textSetIndex, LedDisplayController::TextParameter)); // if a set isn't empty, go through all parameters for (int textSetParameter = 0; textSetParameter < LedDisplayController::DisplayTextSetParameterCount; textSetParameter++) { // send each parameter to the client - const size_t capacity = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 200; + const size_t capacity = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + LedDisplayController::maximumTextLength; //200; DynamicJsonDocument doc(capacity); doc["header"] = GetTextSetParameterCommand; @@ -106,17 +106,21 @@ void OmobiLedDisplay::onDataReceived(String dataString) JsonObject data = doc.createNestedObject("data"); data["index"] = textSetIndex; data["parameter"] = textSetParameter; + data["value"] = this->ledDisplayController->getTextSetParameter( textSetIndex, LedDisplayController::DisplayTextSetParameter(textSetParameter)); - Serial.println("sending parameter: " + String(textSetParameter) + " with value: " + this->ledDisplayController->getTextSetParameter( + + Serial.println("sending parameter: " + String(textSetParameter) + " with value: '" + this->ledDisplayController->getTextSetParameter( textSetIndex, - LedDisplayController::DisplayTextSetParameter(textSetParameter))); + LedDisplayController::DisplayTextSetParameter(textSetParameter)) + "'"); String json; serializeJson(doc, json); + Serial.println("JSON: '" + json + "'"); this->bleServer->sendData(json); + } } @@ -192,6 +196,9 @@ void OmobiLedDisplay::onDataReceived(String dataString) String json; serializeJson(replyDoc, json); this->bleServer->sendData(json); + + + } bool OmobiLedDisplay::loadProperties()