From beff4398105105220748f83061370a1d1752ba8d Mon Sep 17 00:00:00 2001 From: localhorst Date: Sat, 16 Feb 2019 20:35:00 +0100 Subject: [PATCH] added resistance for Driver-Board --- FilmLightController/lightmux.cpp | 120 ++++++++++++++++++----------- FilmLightController/lightmux.h | 24 +++++- FilmLightController/mainwindow.cpp | 10 +++ FilmLightController/mainwindow.h | 2 + FilmLightController/mainwindow.ui | 26 +++++++ 5 files changed, 137 insertions(+), 45 deletions(-) diff --git a/FilmLightController/lightmux.cpp b/FilmLightController/lightmux.cpp index a3ea4a5..b7fc2e7 100644 --- a/FilmLightController/lightmux.cpp +++ b/FilmLightController/lightmux.cpp @@ -10,71 +10,98 @@ LightMux::LightMux() adaptive_brightness = false; fullCommonColor = ((warmest_temperature + coldest_temperature) / 2); qDebug("full common color: %i\n", fullCommonColor); + + cold_resistance_range.low = 100.0; + cold_resistance_range.high = 900.0; + + warm_resistance_range.low = 100.0; + warm_resistance_range.high = 900.0; + } void LightMux::mux(){ + + struct powermix mixed; + if(adaptive_brightness == true){ qDebug("adaptiv\n"); - mux_adaptiv(); + mixed = mux_adaptiv(); } else { qDebug("linear\n"); - mux_linear(); - } -} - -void LightMux::mux_linear() { - - if(temperatur == fullCommonColor){ - qDebug("same as full common color\n"); - power_cold = 100; - power_warm = 100; - } else if(temperatur < fullCommonColor) { - qDebug("lower as full common color\n"); - // warm led dominant - // cold led recessive - power_warm = 100; - double a = double(((temperatur * (power_warm/100)) - ((power_warm/100) * warmest_temperature))); - double b = double((coldest_temperature - temperatur)); - double c = a / b * 100; - power_cold = static_cast(c + .5); - } else if(temperatur > fullCommonColor) { - qDebug("higher as full common color\n"); - // cold led dominant - // warm led recessive - power_cold = 100; - double a = double(((temperatur * (power_cold/100)) - ((power_cold/100) * coldest_temperature))); - double b = double((warmest_temperature - temperatur)); - double c = a / b * 100; - power_warm = static_cast(c + .5); + mixed = mux_linear(); } - power_cold = static_cast(double(power_cold * (double(brightness/100.0))) + .5); - power_warm = static_cast(double(power_warm * (double(brightness/100.0))) + .5); + power_cold = static_cast(double(mixed.cold * (double(brightness/100.0))) + .5); + power_warm = static_cast(double(mixed.warm * (double(brightness/100.0))) + .5); qDebug("cold color: %i\nwarm color: %i\n", power_cold, power_warm); power_combined = static_cast(double(power_cold+power_warm) / 2.0); + + resistance_cold = static_cast(double(map(power_cold, 0.0, 100.0, cold_resistance_range.low, cold_resistance_range.high))); + + resistance_warm = static_cast(double(map(power_warm, 0.0, 100.0, warm_resistance_range.low, warm_resistance_range.high))); + + + +} + +struct LightMux::powermix LightMux::mux_linear() { + + struct powermix tmp; + + if(temperatur == fullCommonColor){ + qDebug("same as full common color\n"); + tmp.cold = 100; + tmp.warm = 100; + + } else if(temperatur < fullCommonColor) { + qDebug("lower as full common color\n"); + // warm led dominant + // cold led recessive + tmp.warm = 100; + double a = double(((temperatur * (tmp.warm/100)) - ((tmp.warm/100) * warmest_temperature))); + double b = double((coldest_temperature - temperatur)); + double c = a / b * 100; + tmp.cold = static_cast(c + .5); + } else if(temperatur > fullCommonColor) { + qDebug("higher as full common color\n"); + // cold led dominant + // warm led recessive + tmp.cold = 100; + double a = double(((temperatur * (tmp.cold/100)) - ((tmp.cold/100) * coldest_temperature))); + double b = double((warmest_temperature - temperatur)); + double c = a / b * 100; + tmp.warm = static_cast(c + .5); + } + + return tmp; + } -void LightMux::mux_adaptiv(){ +struct LightMux::powermix LightMux::mux_adaptiv(){ + + struct powermix tmp; if(temperatur == fullCommonColor){ qDebug("same as full common color\n"); power_cold = 50; power_warm = 50; + tmp.cold = 50; + tmp.warm = 50; + } else if(temperatur < fullCommonColor) { qDebug("lower as full common color\n"); // warm led dominant // cold led recessive - double a = double((temperatur) - (warmest_temperature)); double b = double((-warmest_temperature + coldest_temperature)); double c = a / b * 100; - power_cold = static_cast(c + .5); - power_warm = 100 - power_cold; + tmp.cold = static_cast(c + .5); + tmp.warm = 100 - tmp.cold; } else if(temperatur > fullCommonColor) { qDebug("higher as full common color\n"); // cold led dominant @@ -83,16 +110,11 @@ void LightMux::mux_adaptiv(){ double a = double((temperatur) - (coldest_temperature)); double b = double((-coldest_temperature + warmest_temperature)); double c = a / b * 100; - power_warm = static_cast(c + .5); - power_cold = 100 - power_warm; + tmp.warm = static_cast(c + .5); + tmp.cold = 100 - tmp.warm; } - power_cold = static_cast(double(power_cold * (double(brightness/100.0))) + .5); - power_warm = static_cast(double(power_warm * (double(brightness/100.0))) + .5); - - qDebug("cold color: %i\nwarm color: %i\n", power_cold, power_warm); - - power_combined = static_cast(double(power_cold+power_warm) / 2.0); + return tmp; } @@ -184,6 +206,10 @@ void LightMux::toogleAdaptiveBrightness(){ } } +double LightMux::map(double value, double fromLow, double fromHigh, double toLow, double toHigh){ + return toLow + (toHigh - toLow) * ((value - fromLow) / (fromHigh - fromLow)); +} + int LightMux::getBrightness(){ return brightness; } @@ -211,3 +237,11 @@ int LightMux::getPowerWarm(){ int LightMux::getPowerCombined(){ return power_combined; } + +int LightMux::getResistanceCold(){ + return resistance_cold; +} + +int LightMux::getResistanceWarm(){ + return resistance_warm; +} diff --git a/FilmLightController/lightmux.h b/FilmLightController/lightmux.h index 30e2ad2..496f805 100644 --- a/FilmLightController/lightmux.h +++ b/FilmLightController/lightmux.h @@ -6,6 +6,16 @@ class LightMux { private: + struct range { + double low; + double high; + }; + + struct powermix { + int cold; + int warm; + }; + 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 @@ -17,10 +27,16 @@ private: int power_warm; // power of the warm LEDs of Panels in percent int power_combined; //combined power of both LEDs in percent + int resistance_cold; // Resistance of the DigiPot on Driver-Board + int resistance_warm; // Resistance of the DigiPot on Driver-Board + int fullCommonColor; // color mix with both LED´s at same brightess bool adaptive_brightness; // true indecates adaptive brightness is enabled + struct range cold_resistance_range; + struct range warm_resistance_range; + public: LightMux(); @@ -48,11 +64,15 @@ public: int getPowerCombined(); + int getResistanceCold(); + int getResistanceWarm(); + void toogleAdaptiveBrightness(); private: - void mux_linear(); // brightness will vary by different color temperature - void mux_adaptiv(); // same brightness by different color temperature + struct powermix mux_linear(); // brightness will vary by different color temperature + struct powermix mux_adaptiv(); // same brightness by different color temperature + double map(double value, double fromLow, double fromHigh, double toLow, double toHigh); // remaps the value }; #endif // LIGHTMUX_H diff --git a/FilmLightController/mainwindow.cpp b/FilmLightController/mainwindow.cpp index 685e566..8951804 100644 --- a/FilmLightController/mainwindow.cpp +++ b/FilmLightController/mainwindow.cpp @@ -38,6 +38,8 @@ void MainWindow::updateUI() setLablePowerCold(lmux->getPowerCold()); setLablePowerWarm(lmux->getPowerWarm()); setLablePowerCombined(lmux->getPowerCombined()); + setLableResistanceCold(lmux->getResistanceCold()); + setLableResistanceWarm(lmux->getResistanceWarm()); } @@ -56,6 +58,14 @@ void MainWindow::setLablePowerCombined(int val) ui->labelPowerCombined->setText("Combined Power: " + QString::number(val) + "%"); } +void MainWindow::setLableResistanceCold(int val){ + ui->labelResistanceCold->setText("Resistance Cold: " + QString::number(val) + "Ω"); +} + +void MainWindow::setLableResistanceWarm(int val){ + ui->labelResistanceWarm->setText("Resistance Warm: " + QString::number(val) + "Ω"); +} + void MainWindow::on_BtnIncreaseBrightness_clicked() { lmux->incBrightness(); diff --git a/FilmLightController/mainwindow.h b/FilmLightController/mainwindow.h index 3d4f5c5..fe71457 100644 --- a/FilmLightController/mainwindow.h +++ b/FilmLightController/mainwindow.h @@ -19,6 +19,8 @@ public: void setLablePowerCold(int val); void setLablePowerWarm(int val); void setLablePowerCombined(int val); + void setLableResistanceCold(int val); + void setLableResistanceWarm(int val); private slots: void on_BtnIncreaseBrightness_clicked(); diff --git a/FilmLightController/mainwindow.ui b/FilmLightController/mainwindow.ui index ae6319f..4a52e2e 100644 --- a/FilmLightController/mainwindow.ui +++ b/FilmLightController/mainwindow.ui @@ -298,6 +298,32 @@ adaptive brightness + + + + 220 + 240 + 161 + 20 + + + + Resistance Cold: + + + + + + 220 + 270 + 161 + 20 + + + + Resistance Warm: + +