From 236dc6a9b11b49a2f197bc7c99ce848b0937ad48 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sat, 9 Feb 2019 15:11:46 +0100 Subject: [PATCH] set Btn implemented --- FilmLightController/lightmux.cpp | 61 +++++++++++++++++++++++- FilmLightController/lightmux.h | 10 +++- FilmLightController/mainwindow.cpp | 40 ++++++++++++---- FilmLightController/mainwindow.h | 6 +++ FilmLightController/mainwindow.ui | 76 ++++++++++++++++++++++-------- 5 files changed, 162 insertions(+), 31 deletions(-) diff --git a/FilmLightController/lightmux.cpp b/FilmLightController/lightmux.cpp index 28ad9fb..825e8c6 100644 --- a/FilmLightController/lightmux.cpp +++ b/FilmLightController/lightmux.cpp @@ -2,8 +2,8 @@ LightMux::LightMux() { -temperatur = warmest_temperature; -brightness = 0; + temperatur = warmest_temperature; + brightness = 0; } @@ -21,6 +21,20 @@ void LightMux::incBrightness(){ } } +void LightMux::setBrightness(int val){ + + brightness = val; + + if(brightness < 0){ + brightness = 0; + } + + if(brightness > 100){ + brightness = 100; + } + +} + void LightMux::warm_Temperature(){ temperatur = temperatur - steps_temperature; if(temperatur < warmest_temperature){ @@ -35,6 +49,41 @@ void LightMux::cold_Temperature(){ } } +void LightMux::setTemperature(int requested_val){ + + int current_temp = warmest_temperature; + + /* out of range */ + + if(requested_val < warmest_temperature){ + temperatur = warmest_temperature; + return; + } + + if(requested_val > coldest_temperature){ + temperatur = coldest_temperature; + return; + } + + /* between range, map to steps */ + + while(true){ + if(requested_val <= current_temp){ + + temperatur = current_temp; + + int diff = current_temp - requested_val; + + if(diff > (steps_temperature/2)){ + warm_Temperature(); + } + + return; + } + current_temp = current_temp + steps_temperature; + } +} + int LightMux::getBrightness(){ return brightness; } @@ -42,3 +91,11 @@ int LightMux::getBrightness(){ int LightMux::getTemperature(){ return temperatur; } + +int LightMux::getColdest_temperature(){ + return coldest_temperature; +} + +int LightMux::getWarmest_temperature(){ + return warmest_temperature; +} diff --git a/FilmLightController/lightmux.h b/FilmLightController/lightmux.h index 1215ad0..54b8e09 100644 --- a/FilmLightController/lightmux.h +++ b/FilmLightController/lightmux.h @@ -1,9 +1,10 @@ #ifndef LIGHTMUX_H #define LIGHTMUX_H - +#include class LightMux { +private: int brightness; // total power of the LED Panels (both colors) in percent int temperatur; // muxed color temperature of the LED Panels, from coldest to warmest in Kelvin @@ -19,13 +20,20 @@ public: void incBrightness(); void decBrightness(); + void setBrightness(int val); // set total power of the LED Panels (both colors) in percent + void cold_Temperature(); void warm_Temperature(); + void setTemperature(int requested_val); // set muxed color temperature of the LED Panels, from coldest to warmest in Kelvin. Fitted to the nearest value that the steps allow + int getBrightness(); int getTemperature(); + int getColdest_temperature(); + int getWarmest_temperature(); + }; #endif // LIGHTMUX_H diff --git a/FilmLightController/mainwindow.cpp b/FilmLightController/mainwindow.cpp index 0bc10c5..94b610a 100644 --- a/FilmLightController/mainwindow.cpp +++ b/FilmLightController/mainwindow.cpp @@ -1,6 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -13,6 +13,8 @@ MainWindow::MainWindow(QWidget *parent) : ui->lcdBrightness->setDigitCount(3); ui->lcdTemperature->setDigitCount(4); + ui->lineBrightness->setValidator(new QIntValidator(0, 100, this)); + ui->lineTemperature->setValidator(new QIntValidator(lmux->getWarmest_temperature(), lmux->getColdest_temperature(), this)); updateUI(); @@ -26,43 +28,65 @@ MainWindow::~MainWindow() void MainWindow::updateUI(){ -ui->lcdBrightness->display(lmux->getBrightness()); -ui->lcdTemperature->display(lmux->getTemperature()); - + ui->lcdBrightness->display(lmux->getBrightness()); + ui->lcdTemperature->display(lmux->getTemperature()); + ui->lineTemperature->clear(); + ui->lineBrightness->clear(); } void MainWindow::setLablePowerCold(int val){ //ui->labelPowerCold->setText("Output Power Cold: " + QString::number(val) + " %"); + } void MainWindow::on_BtnIncreaseBrightness_clicked() { - //qDebug( "BtnIncreaseBrightness_clicked\n"); + lmux->incBrightness(); + updateUI(); } void MainWindow::on_BtnDecreaseBrightness_clicked() { - + lmux->decBrightness(); + updateUI(); } void MainWindow::on_BtnIncreaseTemperatur_clicked() { - + lmux->cold_Temperature(); + updateUI(); } void MainWindow::on_BtnDecreaseTemperatur_clicked() { - + lmux->warm_Temperature(); + updateUI(); } void MainWindow::on_BtnSetBrightness_clicked() { + lmux->setBrightness(ui->lineBrightness->text().toInt()); + updateUI(); } void MainWindow::on_BtnSetTemperatur_clicked() { + lmux->setTemperature(ui->lineTemperature->text().toInt()); + updateUI(); +} + + + +void MainWindow::on_lineBrightness_returnPressed() +{ + on_BtnSetBrightness_clicked(); +} + +void MainWindow::on_lineTemperature_returnPressed() +{ + on_BtnSetTemperatur_clicked(); } diff --git a/FilmLightController/mainwindow.h b/FilmLightController/mainwindow.h index d72b83d..93044fd 100644 --- a/FilmLightController/mainwindow.h +++ b/FilmLightController/mainwindow.h @@ -2,6 +2,7 @@ #define MAINWINDOW_H #include +#include #include "lightmux.h" namespace Ui { @@ -30,6 +31,11 @@ private slots: void on_BtnSetTemperatur_clicked(); + + void on_lineBrightness_returnPressed(); + + void on_lineTemperature_returnPressed(); + private: Ui::MainWindow *ui; LightMux *lmux; diff --git a/FilmLightController/mainwindow.ui b/FilmLightController/mainwindow.ui index 7d3b46b..bc0ef03 100644 --- a/FilmLightController/mainwindow.ui +++ b/FilmLightController/mainwindow.ui @@ -60,26 +60,6 @@ Temperature - - - - 20 - 150 - 71 - 27 - - - - - - - 230 - 150 - 71 - 27 - - - @@ -92,6 +72,15 @@ Increase + + true + + + 100 + + + 50 + @@ -105,6 +94,15 @@ Decrease + + true + + + 100 + + + 50 + @@ -118,6 +116,15 @@ Increase + + true + + + 100 + + + 70 + @@ -131,6 +138,15 @@ Decrease + + true + + + 100 + + + 70 + @@ -236,6 +252,26 @@ Output Power Warm: + + + + 10 + 150 + 81 + 26 + + + + + + + 220 + 150 + 71 + 26 + + +