BLE advertising reactivatet, data stored after write is done

This commit is contained in:
Jens Noack 2022-07-28 10:11:12 +02:00
parent 90e87d1b0d
commit ae659ac875
7 changed files with 73 additions and 26 deletions

View file

@ -1,7 +1,10 @@
{ {
// See http://go.microsoft.com/fwlink/?LinkId=827846 // See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format // for the documentation about the extensions.json format
"recommendations": [ "recommendations": [
"platformio.platformio-ide" "platformio.platformio-ide"
] ],
} "unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

View file

@ -18,5 +18,6 @@
"numeric": "cpp", "numeric": "cpp",
"streambuf": "cpp", "streambuf": "cpp",
"utility": "cpp" "utility": "cpp"
} },
"svn.ignoreMissingSvnWarning": true
} }

View file

@ -36,6 +36,8 @@ public:
textpixel = 0; textpixel = 0;
disp_show = false; disp_show = false;
setsModiefiedLastTime_ms = 0;
setModifyingActive = false;
this->brightness_init(); this->brightness_init();
this->disp_init(); this->disp_init();
@ -98,6 +100,11 @@ public:
private: private:
// modified status
const unsigned long msToWaitBeforeModifyGetsInactive = 2000; //milliseconds
unsigned long setsModiefiedLastTime_ms;
bool setModifyingActive;
// matrix objects // matrix objects
TaskHandle_t displayUpdateTask; TaskHandle_t displayUpdateTask;
NeoPixelBrightnessBusGfx<NeoGrbFeature, Neo800KbpsMethod> *matrix; NeoPixelBrightnessBusGfx<NeoGrbFeature, Neo800KbpsMethod> *matrix;
@ -159,14 +166,19 @@ private:
} sets_t; } sets_t;
// storage variables // 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; 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 // storage control
EepromUnit* eepromUnit; EepromUnit* eepromUnit;
GetSetTextSetParameterExitCode getSetTextSetParameter(int index, DisplayTextSetParameter parameter, String *value, bool set = false); GetSetTextSetParameterExitCode getSetTextSetParameter(int index, DisplayTextSetParameter parameter, String *value, bool set = false);
bool storeTextSets(); bool storeTextSets();
bool loadTextSets(); bool loadTextSets();
bool storeDataToEEPROM();
}; };

View file

@ -48,6 +48,7 @@ protected:
void onDataReceived(String data) override; void onDataReceived(String data) override;
private: private:
enum OmobiDisplayCommand enum OmobiDisplayCommand
{ {
AuthenticateCommand = 0, AuthenticateCommand = 0,

View file

@ -52,7 +52,9 @@ void BluetoothLeUartServer::setCallbacks(BluetoothLeUartServerCallbacks *callbac
void BluetoothLeUartServer::sendData(String data) 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(); txCharacteristic->notify();
} }
@ -96,6 +98,8 @@ void BluetoothLeUartServer::onDisconnect(BLEServer *pServer)
{ {
this->deviceConnected = false; this->deviceConnected = false;
this->deviceConnectionId = -1; this->deviceConnectionId = -1;
bleServer->getAdvertising()->start();
Serial.println("Restart advertising after disconnect ...");
if (this->callbacks != nullptr) if (this->callbacks != nullptr)
this->callbacks->onDeviceConnectedChanged(this->deviceConnected); this->callbacks->onDeviceConnectedChanged(this->deviceConnected);

View file

@ -7,13 +7,14 @@
void LedDisplayController::loop() void LedDisplayController::loop()
{ {
//Serial.printf("Ligth: %d \n" , analogRead(36)); //Serial.printf("Ligth: %d \n" , analogRead(36));
storeDataToEEPROM();
if (this->disp_show) if (this->disp_show)
{ {
measureBrightnessEnv(); measureBrightnessEnv();
disp_start_set(); disp_start_set();
if (true == text_sets.sets[text_curr_nr].active) 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) 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) bool LedDisplayController::registerEepromUnit(EepromManager *eepromManager)
{ {
if (this->eepromUnit != nullptr) if (this->eepromUnit != nullptr)
@ -121,7 +147,7 @@ void LedDisplayController::disp_start_set()
// current entry is not active // current entry is not active
(text_sets.sets[text_curr_nr].active == false) || (text_sets.sets[text_curr_nr].active == false) ||
// current entry has no text defined // 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 // 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)) || ((text_sets.sets[text_curr_nr].scroll == false) && (text_sets.sets[text_curr_nr].runtime == 0)) ||
// current entry is scrolling: but no scrollnumber defined // current entry is scrolling: but no scrollnumber defined
@ -441,16 +467,9 @@ LedDisplayController::GetSetTextSetParameterExitCode LedDisplayController::getSe
bool LedDisplayController::storeTextSets() bool LedDisplayController::storeTextSets()
{ {
Serial.println("Storing Text Sets..."); Serial.println("Text Sets where modified ...");
if (this->eepromUnit == nullptr) this->setsModiefiedLastTime_ms = millis();
{ this->setModifyingActive = true;
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;
} }

View file

@ -91,14 +91,14 @@ void OmobiLedDisplay::onDataReceived(String dataString)
{ {
if (this->ledDisplayController->getTextSetParameter(textSetIndex, LedDisplayController::TextParameter) == "") if (this->ledDisplayController->getTextSetParameter(textSetIndex, LedDisplayController::TextParameter) == "")
continue; continue;
Serial.println("Adding index " + String(textSetIndex) + " with text: " + this->ledDisplayController->getTextSetParameter(textSetIndex, LedDisplayController::TextParameter)); Serial.println("Adding index " + String(textSetIndex) + " with text: " + this->ledDisplayController->getTextSetParameter(textSetIndex, LedDisplayController::TextParameter));
// if a set isn't empty, go through all parameters // if a set isn't empty, go through all parameters
for (int textSetParameter = 0; textSetParameter < LedDisplayController::DisplayTextSetParameterCount; textSetParameter++) for (int textSetParameter = 0; textSetParameter < LedDisplayController::DisplayTextSetParameterCount; textSetParameter++)
{ {
// send each parameter to the client // 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); DynamicJsonDocument doc(capacity);
doc["header"] = GetTextSetParameterCommand; doc["header"] = GetTextSetParameterCommand;
@ -106,17 +106,21 @@ void OmobiLedDisplay::onDataReceived(String dataString)
JsonObject data = doc.createNestedObject("data"); JsonObject data = doc.createNestedObject("data");
data["index"] = textSetIndex; data["index"] = textSetIndex;
data["parameter"] = textSetParameter; data["parameter"] = textSetParameter;
data["value"] = this->ledDisplayController->getTextSetParameter( data["value"] = this->ledDisplayController->getTextSetParameter(
textSetIndex, textSetIndex,
LedDisplayController::DisplayTextSetParameter(textSetParameter)); 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, textSetIndex,
LedDisplayController::DisplayTextSetParameter(textSetParameter))); LedDisplayController::DisplayTextSetParameter(textSetParameter)) + "'");
String json; String json;
serializeJson(doc, json); serializeJson(doc, json);
Serial.println("JSON: '" + json + "'");
this->bleServer->sendData(json); this->bleServer->sendData(json);
} }
} }
@ -192,6 +196,9 @@ void OmobiLedDisplay::onDataReceived(String dataString)
String json; String json;
serializeJson(replyDoc, json); serializeJson(replyDoc, json);
this->bleServer->sendData(json); this->bleServer->sendData(json);
} }
bool OmobiLedDisplay::loadProperties() bool OmobiLedDisplay::loadProperties()