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
// 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"
]
}

View File

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

View File

@ -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<NeoGrbFeature, Neo800KbpsMethod> *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();
};

View File

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

View File

@ -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);

View File

@ -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;
}

View File

@ -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()