implemented automatic brightness adjustment
This commit is contained in:
parent
bd3deb2b7f
commit
16153f0d36
6 changed files with 60 additions and 49 deletions
|
@ -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->bleClient->setUUIDs("92fecb20-1406-426a-afa5-cd5c1f306462", "92fecb21-1406-426a-afa5-cd5c1f306462", "92fecb22-1406-426a-afa5-cd5c1f306462");
|
||||||
this->displayTextModel = new LedDisplayTextModel(this);
|
this->displayTextModel = new LedDisplayTextModel(this);
|
||||||
this->textSetsBuffer.clear();
|
this->textSetsBuffer.clear();
|
||||||
this->displayBrightness = -1;
|
this->displayBrightness = {{"displayBrightness", 0}, {"automaticBrightnessAdjustment", false}};
|
||||||
this->waitingCommands = 0;
|
this->waitingCommands = 0;
|
||||||
|
|
||||||
this->settings = new QSettings();
|
this->settings = new QSettings();
|
||||||
|
@ -231,7 +231,7 @@ void LedDisplayBackend::handleBluetoothDataReceived(QString s){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GetDisplayBrightnessCommand: {
|
case GetDisplayBrightnessCommand: {
|
||||||
this->setDisplayBrightness(data["displayBrightness"].toInt());
|
this->setDisplayBrightness(data);
|
||||||
this->refreshLoadingState();
|
this->refreshLoadingState();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -306,17 +306,17 @@ void LedDisplayBackend::setState(OmobiDisplayAppState state) {
|
||||||
this->bleClient->startScanningForDevices();
|
this->bleClient->startScanningForDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
int LedDisplayBackend::getDisplayBrightness() {
|
QVariantMap LedDisplayBackend::getDisplayBrightness() {
|
||||||
return this->displayBrightness;
|
return this->displayBrightness;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedDisplayBackend::setDisplayBrightness(int brightness) {
|
void LedDisplayBackend::setDisplayBrightness(QVariantMap brightness) {
|
||||||
if(brightness == this->displayBrightness)
|
if(brightness == this->displayBrightness)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this->displayBrightness = brightness;
|
this->displayBrightness = brightness;
|
||||||
|
|
||||||
this->sendBluetoothCommand(SetDisplayBrightnessCommand, QVariantMap{{"displayBrightness",this->displayBrightness}});
|
this->sendBluetoothCommand(SetDisplayBrightnessCommand, this->displayBrightness);
|
||||||
|
|
||||||
emit this->displayBrightnessChanged();
|
emit this->displayBrightnessChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ class LedDisplayBackend : public QObject
|
||||||
Q_PROPERTY(QBluetoothLeUartClient* bleClient READ getBleClient NOTIFY bleClientChanged)
|
Q_PROPERTY(QBluetoothLeUartClient* bleClient READ getBleClient NOTIFY bleClientChanged)
|
||||||
Q_PROPERTY(OmobiDisplayAppState state READ getState WRITE setState NOTIFY stateChanged)
|
Q_PROPERTY(OmobiDisplayAppState state READ getState WRITE setState NOTIFY stateChanged)
|
||||||
Q_PROPERTY(LedDisplayTextModel* displayTextModel READ getDisplayTextModel NOTIFY displayTextModelChanged)
|
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:
|
public:
|
||||||
explicit LedDisplayBackend(QObject *parent = nullptr);
|
explicit LedDisplayBackend(QObject *parent = nullptr);
|
||||||
|
@ -65,7 +65,7 @@ private:
|
||||||
LedDisplayTextModel* displayTextModel;
|
LedDisplayTextModel* displayTextModel;
|
||||||
int waitingCommands;
|
int waitingCommands;
|
||||||
QList<QMap<int, QVariant>> textSetsBuffer;
|
QList<QMap<int, QVariant>> textSetsBuffer;
|
||||||
int displayBrightness;
|
QVariantMap displayBrightness;
|
||||||
|
|
||||||
QSettings* settings;
|
QSettings* settings;
|
||||||
QString lastDisplaySecret;
|
QString lastDisplaySecret;
|
||||||
|
@ -76,8 +76,8 @@ public slots:
|
||||||
Q_INVOKABLE QBluetoothLeUartClient* getBleClient();
|
Q_INVOKABLE QBluetoothLeUartClient* getBleClient();
|
||||||
Q_INVOKABLE OmobiDisplayAppState getState();
|
Q_INVOKABLE OmobiDisplayAppState getState();
|
||||||
Q_INVOKABLE LedDisplayTextModel* getDisplayTextModel();
|
Q_INVOKABLE LedDisplayTextModel* getDisplayTextModel();
|
||||||
Q_INVOKABLE int getDisplayBrightness();
|
Q_INVOKABLE QVariantMap getDisplayBrightness();
|
||||||
Q_INVOKABLE void setDisplayBrightness(int brightness);
|
Q_INVOKABLE void setDisplayBrightness(QVariantMap brightness);
|
||||||
Q_INVOKABLE void setDisplayCode(QString code);
|
Q_INVOKABLE void setDisplayCode(QString code);
|
||||||
Q_INVOKABLE void setDisplayName(QString name);
|
Q_INVOKABLE void setDisplayName(QString name);
|
||||||
|
|
||||||
|
|
|
@ -65,11 +65,15 @@ Page {
|
||||||
to: 255
|
to: 255
|
||||||
stepSize: 1
|
stepSize: 1
|
||||||
|
|
||||||
value: backend.displayBrightness
|
value: backend.displayBrightness.displayBrightness
|
||||||
|
|
||||||
onPressedChanged: {
|
onPressedChanged: {
|
||||||
if(!pressed)
|
if(!pressed) {
|
||||||
backend.displayBrightness = value
|
backend.displayBrightness = {
|
||||||
|
"displayBrightness": value,
|
||||||
|
"automaticBrightnessAdjustment": false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolTip {
|
ToolTip {
|
||||||
|
|
|
@ -90,6 +90,8 @@ public:
|
||||||
// brightness control
|
// brightness control
|
||||||
int getBrightness();
|
int getBrightness();
|
||||||
bool setBrightness(int brightness);
|
bool setBrightness(int brightness);
|
||||||
|
bool getAutomaticBrightnessAdjustment();
|
||||||
|
void setAutomaticBrightnessAdjustment(bool automaticBrightnessAdjustment);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// matrix objects
|
// matrix objects
|
||||||
|
@ -135,6 +137,7 @@ private:
|
||||||
{
|
{
|
||||||
text_set_t sets[maximumTextSets];
|
text_set_t sets[maximumTextSets];
|
||||||
int disp_brightness;
|
int disp_brightness;
|
||||||
|
bool disp_automatic_brightness_adjustment;
|
||||||
char valid[3];
|
char valid[3];
|
||||||
} sets_t;
|
} sets_t;
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
LedDisplayController *ledDisplayControllerGlobal = nullptr;
|
LedDisplayController *ledDisplayControllerGlobal = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
// - Public functions -
|
// - Public functions -
|
||||||
// --------------------
|
// --------------------
|
||||||
|
@ -64,6 +62,16 @@ bool LedDisplayController::setBrightness(int brightness)
|
||||||
return true;
|
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 -
|
// - Matrix control -
|
||||||
// ------------------
|
// ------------------
|
||||||
|
@ -89,8 +97,7 @@ void LedDisplayController::disp_start_set()
|
||||||
// current entry is not scrolling: maximum of runtime is defined and runtime is over
|
// 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
|
// 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)))
|
((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 =
|
bool illegal_entry_settings =
|
||||||
// current entry is not active
|
// current entry is not active
|
||||||
|
@ -100,10 +107,7 @@ void LedDisplayController::disp_start_set()
|
||||||
// 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
|
||||||
((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
|
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))
|
//(((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))
|
||||||
|
@ -111,12 +115,12 @@ void LedDisplayController::disp_start_set()
|
||||||
{
|
{
|
||||||
|
|
||||||
//Serial.printf("[%lu] Meet start set condition. Curr set is %d. \n", millis(), text_curr_nr);
|
//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++;
|
text_curr_nr++;
|
||||||
if (text_curr_nr == maximumTextSets)
|
if (text_curr_nr == maximumTextSets)
|
||||||
{
|
{
|
||||||
text_curr_nr = 0;
|
text_curr_nr = 0;
|
||||||
if(false == text_no_activ_legal_sets )
|
if (false == text_no_activ_legal_sets)
|
||||||
{
|
{
|
||||||
this->matrix->fillScreen(0);
|
this->matrix->fillScreen(0);
|
||||||
this->matrix->Show();
|
this->matrix->Show();
|
||||||
|
@ -126,18 +130,14 @@ void LedDisplayController::disp_start_set()
|
||||||
}
|
}
|
||||||
text_pass = 0;
|
text_pass = 0;
|
||||||
if (text_sets.sets[text_curr_nr].active &&
|
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_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;
|
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);
|
//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);
|
this->matrix->fillScreen(0);
|
||||||
textpixel = 6 * strlen(text_sets.sets[text_curr_nr].text);
|
textpixel = 6 * strlen(text_sets.sets[text_curr_nr].text);
|
||||||
// scrolling text has always left or right allignment - depending on direction of scroll
|
// 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;
|
text_sets.sets[text_curr_nr].alignment = AlignRight;
|
||||||
|
|
||||||
switch (text_sets.sets[text_curr_nr].alignment)
|
switch (text_sets.sets[text_curr_nr].alignment)
|
||||||
|
@ -167,11 +167,11 @@ void LedDisplayController::disp_start_set()
|
||||||
void LedDisplayController::disp_scroll_text()
|
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();
|
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);
|
//Serial.printf("speed %d, waittime: %d' \n", text_sets.sets[text_curr_nr].scrollSpeed, display_show_wait_ms);
|
||||||
this->matrix->fillScreen(0);
|
this->matrix->fillScreen(0);
|
||||||
show_matrix(text_sets.sets[text_curr_nr].text, text_pos, text_sets.sets[text_curr_nr].color);
|
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)
|
else if (strcmp(this->text_sets.valid, "OK") != 0)
|
||||||
return InternalError;
|
return InternalError;
|
||||||
|
|
||||||
text_set_t* currentTextSet = &this->text_sets.sets[index];
|
text_set_t *currentTextSet = &this->text_sets.sets[index];
|
||||||
String returnValue = "";
|
String returnValue = "";
|
||||||
|
|
||||||
switch (parameter)
|
switch (parameter)
|
||||||
|
@ -260,9 +260,9 @@ LedDisplayController::GetSetTextSetParameterExitCode LedDisplayController::getSe
|
||||||
|
|
||||||
case RuntimeParameter:
|
case RuntimeParameter:
|
||||||
if (set)
|
if (set)
|
||||||
currentTextSet->runtime = value->toInt()*1000;
|
currentTextSet->runtime = value->toInt() * 1000;
|
||||||
else
|
else
|
||||||
returnValue = String(round(currentTextSet->runtime/1000));
|
returnValue = String(round(currentTextSet->runtime / 1000));
|
||||||
//Serial.printf("Runtim is: %d \n", currentTextSet->runtime);
|
//Serial.printf("Runtim is: %d \n", currentTextSet->runtime);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ LedDisplayController::GetSetTextSetParameterExitCode LedDisplayController::getSe
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ScrollDirectionParameter:
|
case ScrollDirectionParameter:
|
||||||
if(set)
|
if (set)
|
||||||
currentTextSet->scrollDirection = value->toInt();
|
currentTextSet->scrollDirection = value->toInt();
|
||||||
else
|
else
|
||||||
returnValue = currentTextSet->scrollDirection;
|
returnValue = currentTextSet->scrollDirection;
|
||||||
|
@ -344,7 +344,8 @@ LedDisplayController::GetSetTextSetParameterExitCode LedDisplayController::getSe
|
||||||
bool LedDisplayController::storeTextSets()
|
bool LedDisplayController::storeTextSets()
|
||||||
{
|
{
|
||||||
Serial.println("Storing Text Sets...");
|
Serial.println("Storing Text Sets...");
|
||||||
if (this->eepromUnit == nullptr) {
|
if (this->eepromUnit == nullptr)
|
||||||
|
{
|
||||||
Serial.println("ERROR");
|
Serial.println("ERROR");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -387,7 +388,8 @@ bool LedDisplayController::loadTextSets()
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&text_sets, &defaultTextSets, sizeof(sets_t));
|
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();
|
return this->storeTextSets();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -396,12 +398,12 @@ bool LedDisplayController::loadTextSets()
|
||||||
// - Extern -
|
// - Extern -
|
||||||
// ----------
|
// ----------
|
||||||
|
|
||||||
void updateDisplayGlobal(void* object)
|
void updateDisplayGlobal(void *object)
|
||||||
{
|
{
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
esp_task_wdt_reset();
|
esp_task_wdt_reset();
|
||||||
delay(1);
|
delay(1);
|
||||||
((LedDisplayController*)(object))->loop();
|
((LedDisplayController *)(object))->loop();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -129,6 +129,7 @@ void OmobiLedDisplay::onDataReceived(String dataString)
|
||||||
case GetDisplayBrightnessCommand:
|
case GetDisplayBrightnessCommand:
|
||||||
{
|
{
|
||||||
replyData["displayBrightness"] = this->ledDisplayController->getBrightness();
|
replyData["displayBrightness"] = this->ledDisplayController->getBrightness();
|
||||||
|
replyData["automaticBrightnessAdjustment"] = this->ledDisplayController->getAutomaticBrightnessAdjustment();
|
||||||
replyStatus = Success;
|
replyStatus = Success;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -154,6 +155,7 @@ void OmobiLedDisplay::onDataReceived(String dataString)
|
||||||
case SetDisplayBrightnessCommand:
|
case SetDisplayBrightnessCommand:
|
||||||
{
|
{
|
||||||
this->ledDisplayController->setBrightness(requestData["displayBrightness"]);
|
this->ledDisplayController->setBrightness(requestData["displayBrightness"]);
|
||||||
|
this->ledDisplayController->setAutomaticBrightnessAdjustment(requestData["automaticBrightnessAdjustment"]);
|
||||||
replyStatus = Success;
|
replyStatus = Success;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue