implemented automatic brightness adjustment

This commit is contained in:
Dorian Zedler 2020-10-18 16:26:24 +02:00
parent bd3deb2b7f
commit 16153f0d36
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
6 changed files with 60 additions and 49 deletions

View file

@ -6,7 +6,7 @@ LedDisplayBackend::LedDisplayBackend(QObject *parent) : QObject(parent)
this->bleClient->setUUIDs("92fecb20-1406-426a-afa5-cd5c1f306462", "92fecb21-1406-426a-afa5-cd5c1f306462", "92fecb22-1406-426a-afa5-cd5c1f306462");
this->displayTextModel = new LedDisplayTextModel(this);
this->textSetsBuffer.clear();
this->displayBrightness = -1;
this->displayBrightness = {{"displayBrightness", 0}, {"automaticBrightnessAdjustment", false}};
this->waitingCommands = 0;
this->settings = new QSettings();
@ -231,7 +231,7 @@ void LedDisplayBackend::handleBluetoothDataReceived(QString s){
break;
}
case GetDisplayBrightnessCommand: {
this->setDisplayBrightness(data["displayBrightness"].toInt());
this->setDisplayBrightness(data);
this->refreshLoadingState();
break;
}
@ -306,17 +306,17 @@ void LedDisplayBackend::setState(OmobiDisplayAppState state) {
this->bleClient->startScanningForDevices();
}
int LedDisplayBackend::getDisplayBrightness() {
QVariantMap LedDisplayBackend::getDisplayBrightness() {
return this->displayBrightness;
}
void LedDisplayBackend::setDisplayBrightness(int brightness) {
void LedDisplayBackend::setDisplayBrightness(QVariantMap brightness) {
if(brightness == this->displayBrightness)
return;
this->displayBrightness = brightness;
this->sendBluetoothCommand(SetDisplayBrightnessCommand, QVariantMap{{"displayBrightness",this->displayBrightness}});
this->sendBluetoothCommand(SetDisplayBrightnessCommand, this->displayBrightness);
emit this->displayBrightnessChanged();
}

View file

@ -16,7 +16,7 @@ class LedDisplayBackend : public QObject
Q_PROPERTY(QBluetoothLeUartClient* bleClient READ getBleClient NOTIFY bleClientChanged)
Q_PROPERTY(OmobiDisplayAppState state READ getState WRITE setState NOTIFY stateChanged)
Q_PROPERTY(LedDisplayTextModel* displayTextModel READ getDisplayTextModel NOTIFY displayTextModelChanged)
Q_PROPERTY(int displayBrightness READ getDisplayBrightness WRITE setDisplayBrightness NOTIFY displayBrightnessChanged)
Q_PROPERTY(QVariantMap displayBrightness READ getDisplayBrightness WRITE setDisplayBrightness NOTIFY displayBrightnessChanged)
public:
explicit LedDisplayBackend(QObject *parent = nullptr);
@ -65,7 +65,7 @@ private:
LedDisplayTextModel* displayTextModel;
int waitingCommands;
QList<QMap<int, QVariant>> textSetsBuffer;
int displayBrightness;
QVariantMap displayBrightness;
QSettings* settings;
QString lastDisplaySecret;
@ -76,8 +76,8 @@ public slots:
Q_INVOKABLE QBluetoothLeUartClient* getBleClient();
Q_INVOKABLE OmobiDisplayAppState getState();
Q_INVOKABLE LedDisplayTextModel* getDisplayTextModel();
Q_INVOKABLE int getDisplayBrightness();
Q_INVOKABLE void setDisplayBrightness(int brightness);
Q_INVOKABLE QVariantMap getDisplayBrightness();
Q_INVOKABLE void setDisplayBrightness(QVariantMap brightness);
Q_INVOKABLE void setDisplayCode(QString code);
Q_INVOKABLE void setDisplayName(QString name);

View file

@ -65,11 +65,15 @@ Page {
to: 255
stepSize: 1
value: backend.displayBrightness
value: backend.displayBrightness.displayBrightness
onPressedChanged: {
if(!pressed)
backend.displayBrightness = value
if(!pressed) {
backend.displayBrightness = {
"displayBrightness": value,
"automaticBrightnessAdjustment": false
}
}
}
ToolTip {

View file

@ -90,6 +90,8 @@ public:
// brightness control
int getBrightness();
bool setBrightness(int brightness);
bool getAutomaticBrightnessAdjustment();
void setAutomaticBrightnessAdjustment(bool automaticBrightnessAdjustment);
private:
// matrix objects
@ -135,6 +137,7 @@ private:
{
text_set_t sets[maximumTextSets];
int disp_brightness;
bool disp_automatic_brightness_adjustment;
char valid[3];
} sets_t;

View file

@ -2,8 +2,6 @@
LedDisplayController *ledDisplayControllerGlobal = nullptr;
// --------------------
// - Public functions -
// --------------------
@ -64,6 +62,16 @@ bool LedDisplayController::setBrightness(int brightness)
return true;
}
bool LedDisplayController::getAutomaticBrightnessAdjustment()
{
return this->text_sets.disp_automatic_brightness_adjustment;
}
void LedDisplayController::setAutomaticBrightnessAdjustment(bool automaticBrightnessAdjustment)
{
this->text_sets.disp_automatic_brightness_adjustment = automaticBrightnessAdjustment;
}
// ------------------
// - Matrix control -
// ------------------
@ -82,41 +90,37 @@ void LedDisplayController::disp_init()
}
void LedDisplayController::disp_start_set()
{
{
bool legal_entry_setting =
bool legal_entry_setting =
(0 == text_set_starttime) ||
// current entry is not scrolling: maximum of runtime is defined and runtime is over
((text_sets.sets[text_curr_nr].scroll == false) && ((text_sets.sets[text_curr_nr].runtime > 0) && ((millis() - text_set_starttime) >= text_sets.sets[text_curr_nr].runtime))) ||
((text_sets.sets[text_curr_nr].scroll == false) && ((text_sets.sets[text_curr_nr].runtime > 0) && ((millis() - text_set_starttime) >= text_sets.sets[text_curr_nr].runtime))) ||
// current entry is scrolling: but maximum number of scrolls is defined and reached
((text_sets.sets[text_curr_nr].scroll == true) && ((text_sets.sets[text_curr_nr].scrollCount > 0) && (text_pass >= text_sets.sets[text_curr_nr].scrollCount)))
;
bool illegal_entry_settings =
((text_sets.sets[text_curr_nr].scroll == true) && ((text_sets.sets[text_curr_nr].scrollCount > 0) && (text_pass >= text_sets.sets[text_curr_nr].scrollCount)));
bool illegal_entry_settings =
// 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
(text_sets.sets[text_curr_nr].text == '\0') ||
(text_sets.sets[text_curr_nr].text == '\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)) ||
((text_sets.sets[text_curr_nr].scroll == false) && (text_sets.sets[text_curr_nr].runtime == 0)) ||
// current entry is scrolling: but no scrollnumber defined
((text_sets.sets[text_curr_nr].scroll == true) && (text_sets.sets[text_curr_nr].scrollCount == 0))
;
((text_sets.sets[text_curr_nr].scroll == true) && (text_sets.sets[text_curr_nr].scrollCount == 0));
if (legal_entry_setting || illegal_entry_settings
//(((text_sets.sets[text_curr_nr].scrollCount == 0) || text_sets.sets[text_curr_nr].scroll == false) && (text_sets.sets[text_curr_nr].runtime == 0) ) //&& ((millis() - text_set_starttime) >= 10000))
)
)
{
//Serial.printf("[%lu] Meet start set condition. Curr set is %d. \n", millis(), text_curr_nr);
if (0 < text_set_starttime ) //|| text_sets.sets[text_curr_nr].text == '\0' || text_sets.sets[text_curr_nr].active == false)
if (0 < text_set_starttime) //|| text_sets.sets[text_curr_nr].text == '\0' || text_sets.sets[text_curr_nr].active == false)
text_curr_nr++;
if (text_curr_nr == maximumTextSets)
{
text_curr_nr = 0;
if(false == text_no_activ_legal_sets )
if (false == text_no_activ_legal_sets)
{
this->matrix->fillScreen(0);
this->matrix->Show();
@ -125,19 +129,15 @@ void LedDisplayController::disp_start_set()
text_no_activ_legal_sets = false;
}
text_pass = 0;
if (text_sets.sets[text_curr_nr].active &&
(
((text_sets.sets[text_curr_nr].scroll == false) && (text_sets.sets[text_curr_nr].runtime > 0))
|| ((text_sets.sets[text_curr_nr].scroll == true) && (text_sets.sets[text_curr_nr].scrollCount > 0))
)
)
if (text_sets.sets[text_curr_nr].active &&
(((text_sets.sets[text_curr_nr].scroll == false) && (text_sets.sets[text_curr_nr].runtime > 0)) || ((text_sets.sets[text_curr_nr].scroll == true) && (text_sets.sets[text_curr_nr].scrollCount > 0))))
{
text_no_activ_legal_sets = true;
//Serial.printf("[%lu] Set %d. Runtime %d. Text:'%s'\n", millis(), text_curr_nr, text_sets.sets[text_curr_nr].runtime, text_sets.sets[text_curr_nr].text);
this->matrix->fillScreen(0);
textpixel = 6 * strlen(text_sets.sets[text_curr_nr].text);
// scrolling text has always left or right allignment - depending on direction of scroll
if(true == text_sets.sets[text_curr_nr].scroll)
if (true == text_sets.sets[text_curr_nr].scroll)
text_sets.sets[text_curr_nr].alignment = AlignRight;
switch (text_sets.sets[text_curr_nr].alignment)
@ -166,12 +166,12 @@ void LedDisplayController::disp_start_set()
void LedDisplayController::disp_scroll_text()
{
if(millis() - last_display_show_ms > display_show_wait_ms)
if (millis() - last_display_show_ms > display_show_wait_ms)
{
last_display_show_ms = millis();
display_show_wait_ms = ((2*default_display_show_wait_ms)/text_sets.sets[text_curr_nr].scrollSpeed);
display_show_wait_ms = ((2 * default_display_show_wait_ms) / text_sets.sets[text_curr_nr].scrollSpeed);
//Serial.printf("speed %d, waittime: %d' \n", text_sets.sets[text_curr_nr].scrollSpeed, display_show_wait_ms);
this->matrix->fillScreen(0);
show_matrix(text_sets.sets[text_curr_nr].text, text_pos, text_sets.sets[text_curr_nr].color);
@ -227,7 +227,7 @@ LedDisplayController::GetSetTextSetParameterExitCode LedDisplayController::getSe
else if (strcmp(this->text_sets.valid, "OK") != 0)
return InternalError;
text_set_t* currentTextSet = &this->text_sets.sets[index];
text_set_t *currentTextSet = &this->text_sets.sets[index];
String returnValue = "";
switch (parameter)
@ -260,9 +260,9 @@ LedDisplayController::GetSetTextSetParameterExitCode LedDisplayController::getSe
case RuntimeParameter:
if (set)
currentTextSet->runtime = value->toInt()*1000;
currentTextSet->runtime = value->toInt() * 1000;
else
returnValue = String(round(currentTextSet->runtime/1000));
returnValue = String(round(currentTextSet->runtime / 1000));
//Serial.printf("Runtim is: %d \n", currentTextSet->runtime);
break;
@ -292,7 +292,7 @@ LedDisplayController::GetSetTextSetParameterExitCode LedDisplayController::getSe
break;
case ScrollDirectionParameter:
if(set)
if (set)
currentTextSet->scrollDirection = value->toInt();
else
returnValue = currentTextSet->scrollDirection;
@ -344,7 +344,8 @@ LedDisplayController::GetSetTextSetParameterExitCode LedDisplayController::getSe
bool LedDisplayController::storeTextSets()
{
Serial.println("Storing Text Sets...");
if (this->eepromUnit == nullptr) {
if (this->eepromUnit == nullptr)
{
Serial.println("ERROR");
return false;
}
@ -387,7 +388,8 @@ bool LedDisplayController::loadTextSets()
}
memcpy(&text_sets, &defaultTextSets, sizeof(sets_t));
text_sets.disp_brightness = 100;
text_sets.disp_brightness = 70;
text_sets.disp_automatic_brightness_adjustment = false;
return this->storeTextSets();
}
}
@ -396,12 +398,12 @@ bool LedDisplayController::loadTextSets()
// - Extern -
// ----------
void updateDisplayGlobal(void* object)
void updateDisplayGlobal(void *object)
{
for (;;)
{
esp_task_wdt_reset();
delay(1);
((LedDisplayController*)(object))->loop();
((LedDisplayController *)(object))->loop();
}
}

View file

@ -129,6 +129,7 @@ void OmobiLedDisplay::onDataReceived(String dataString)
case GetDisplayBrightnessCommand:
{
replyData["displayBrightness"] = this->ledDisplayController->getBrightness();
replyData["automaticBrightnessAdjustment"] = this->ledDisplayController->getAutomaticBrightnessAdjustment();
replyStatus = Success;
break;
}
@ -154,6 +155,7 @@ void OmobiLedDisplay::onDataReceived(String dataString)
case SetDisplayBrightnessCommand:
{
this->ledDisplayController->setBrightness(requestData["displayBrightness"]);
this->ledDisplayController->setAutomaticBrightnessAdjustment(requestData["automaticBrightnessAdjustment"]);
replyStatus = Success;
break;
}