Skip to content

Commit

Permalink
Changed color temperature control from percent to kelvin
Browse files Browse the repository at this point in the history
  • Loading branch information
bombcheck committed Aug 20, 2018
1 parent 0e8467a commit f7c7bd0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
3 changes: 3 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
$NoTimerAlertMsg="Timer ist deaktiviert";
$FileVer="2.45";

$MilightRgbcctMinKelvin=2700;
$MilightRgbcctMaxKelvin=6500;

//config.xml dateisystem rechte überprüfen
if(!file_exists($CONFIG_FILENAME)) {
echo "Kann die Konfiguration (".$CONFIG_FILENAME.") nicht finden!\n";
Expand Down
7 changes: 4 additions & 3 deletions includes/incl_devs.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,15 @@ function showmilightpanel(milight) {
<!-- SECOND LINE: Temperature & Saturation -->
<div id="milight_<?php echo $device->id; ?>_temperature_controls" class="<?php echo ( $device->milight->mode == 'Weiß' ) ? 'show' : 'hide' ?>">
<br><br>
<button data-theme="<?php echo $theme_row; ?>" data-mini="true" data-inline="true" onclick="if (parseInt(document.getElementById('milight_<?php echo $device->id; ?>_temperature').value) > 0) { $('#milight_<?php echo $device->id; ?>_temperature').attr('value',(parseInt(document.getElementById('milight_<?php echo $device->id; ?>_temperature').value) - 5) + '%').button().button('refresh'); }">Kälter</button>&nbsp;&nbsp;
<button data-theme="<?php echo $theme_row; ?>" data-mini="true" data-inline="true" onclick="if (parseInt(document.getElementById('milight_<?php echo $device->id; ?>_temperature').value) < 100) { $('#milight_<?php echo $device->id; ?>_temperature').attr('value',(parseInt(document.getElementById('milight_<?php echo $device->id; ?>_temperature').value) + 5) + '%'); $('#milight_<?php echo $device->id; ?>_temperature_kelvin').attr('value',(TemperaturePercentToKelvin(parseInt(document.getElementById('milight_<?php echo $device->id; ?>_temperature').value))) + 'K').button().button('refresh'); }">Wärmer</button>&nbsp;&nbsp;
<?php
$ThisTemperature = 0;
$ThisTemperature = $device->milight->temperature;
if ($ThisTemperature == "") $ThisTemperature = 0;
?>
<button name="milight_<?php echo $device->id; ?>_temperature" id="milight_<?php echo $device->id; ?>_temperature" data-theme="<?php echo $theme_row; ?>" data-mini="true" data-inline="true" value="<?php echo $ThisTemperature; ?>%" onclick="send_milight_rgbcct('<?php echo $device->id; ?>','SetWhiteTemperature',parseInt(this.value))"></button>&nbsp;&nbsp;
<button data-theme="<?php echo $theme_row; ?>" data-mini="true" data-inline="true" onclick="if (parseInt(document.getElementById('milight_<?php echo $device->id; ?>_temperature').value) < 100) { $('#milight_<?php echo $device->id; ?>_temperature').attr('value',(parseInt(document.getElementById('milight_<?php echo $device->id; ?>_temperature').value) + 5) + '%').button().button('refresh'); }">Wärmer</button>
<input type="hidden" name="milight_<?php echo $device->id; ?>_temperature" id="milight_<?php echo $device->id; ?>_temperature" value="<?php echo $ThisTemperature; ?>%" />
<button name="milight_<?php echo $device->id; ?>_temperature_kelvin" id="milight_<?php echo $device->id; ?>_temperature_kelvin" data-theme="<?php echo $theme_row; ?>" data-mini="true" data-inline="true" value="<?php echo TemperaturePercentToKelvin($ThisTemperature); ?>K" onclick="send_milight_rgbcct('<?php echo $device->id; ?>','SetWhiteTemperature',parseInt(document.getElementById('milight_<?php echo $device->id; ?>_temperature').value))"></button>&nbsp;&nbsp;
<button data-theme="<?php echo $theme_row; ?>" data-mini="true" data-inline="true" onclick="if (parseInt(document.getElementById('milight_<?php echo $device->id; ?>_temperature').value) > 0) { $('#milight_<?php echo $device->id; ?>_temperature').attr('value',(parseInt(document.getElementById('milight_<?php echo $device->id; ?>_temperature').value) - 5) + '%'); $('#milight_<?php echo $device->id; ?>_temperature_kelvin').attr('value',(TemperaturePercentToKelvin(parseInt(document.getElementById('milight_<?php echo $device->id; ?>_temperature').value))) + 'K').button().button('refresh'); }">Kälter</button>
</div>

<div id="milight_<?php echo $device->id; ?>_saturation_controls" class="<?php echo ( $device->milight->mode == 'Farbe' ) ? 'show' : 'hide' ?>">
Expand Down
7 changes: 3 additions & 4 deletions includes/incl_functions.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php
function TemperaturePercentToKelvin($percent) {
$MinKelvin=2700;
$MaxKelvin=6500;
$Diff = $MaxKelvin - $MinKelvin;
global $MilightRgbcctMinKelvin,$MilightRgbcctMaxKelvin;
$Diff = $MilightRgbcctMaxKelvin - $MilightRgbcctMinKelvin;
$KelvinPerPercent = $Diff / 100;
$val = $KelvinPerPercent * $percent;
return $MaxKelvin - $val;
return $MilightRgbcctMaxKelvin - $val;
}
function colorHEXtoRGB($hex) {
list($r, $g, $b) = sscanf($hex, "#%02x%02x%02x");
Expand Down
4 changes: 3 additions & 1 deletion js/fbswitch_1.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,9 @@
{
$("#milight_"+Device[0]+"_brightness_controls").removeClass('hide').addClass('show');
if (Device[5] == 'milight_rgbcct') {
$("#milight_"+Device[0]+"_temperature").attr('value',Device[14] + '%').button().button('refresh');
//$("#milight_"+Device[0]+"_temperature").attr('value',Device[14] + '%').button().button('refresh');
$("#milight_"+Device[0]+"_temperature").attr('value',Device[14] + '%');
$("#milight_"+Device[0]+"_temperature_kelvin").attr('value',TemperaturePercentToKelvin(Device[14]) + 'K').button().button('refresh');
$("#milight_"+Device[0]+"_saturation").attr('value',Device[15] + '%').button().button('refresh');
}

Expand Down
4 changes: 2 additions & 2 deletions js/fbswitch_2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
var lastEventTimers = [0, 0];

function TemperaturePercentToKelvin(percent) {
var MinKelvin = 2700;
var MaxKelvin = 6500;
var MinKelvin = <?php echo $MilightRgbcctMinKelvin; ?>;
var MaxKelvin = <?php echo $MilightRgbcctMaxKelvin; ?>;
var Diff = MaxKelvin - MinKelvin;
var KelvinPerPercent = Diff / 100;
var val = KelvinPerPercent * percent;
Expand Down

0 comments on commit f7c7bd0

Please sign in to comment.