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 -
// ------------------
@ -89,8 +97,7 @@ void LedDisplayController::disp_start_set()
// 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))) ||
// 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 =
// current entry is not active
@ -100,10 +107,7 @@ void LedDisplayController::disp_start_set()
// 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
((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))
@ -126,11 +130,7 @@ void LedDisplayController::disp_start_set()
}
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))
)
)
(((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);
@ -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();
}
}

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