void temp_OnTempUpdated(object sender, CpuTempEventArgs e) { float? actualtemp = e.currentTemp; ushort hueTemp = 0; lblCpuTemp.Content = $"{Temp.temperature:0.0}ºC"; if (!(bool)btnTestGradient.IsChecked) { return; } gradientStartColor = slHueGradientStart.Value; gradientStopColor = slHueGradientStop.Value; gradientStopTemp = (double)dudUpperTemp.Value; gradientStartTemp = (double)dudLowerTemp.Value; if ((bool)btnTestGradient.IsChecked) { if (actualtemp == null) { hueTemp = (ushort)gradientStartColor; } else { double gradientRange = gradientStartColor - gradientStopColor; double tempRange = gradientStopTemp - gradientStartTemp; if (gradientRange > 0) { double multiplier = gradientStartColor / tempRange; hueTemp = (ushort)(gradientStartColor - (multiplier * (actualtemp - gradientStartTemp))); } else { hueTemp = (ushort)((gradientStopColor * actualtemp) / gradientStopTemp); } } if (cbObject.SelectedItem is KeyValuePair <string, Light> ) { BridgeStore.SelectedBridge.SetState <Light>(new State() { hue = hueTemp, bri = 255, sat = 255, @on = true, transitiontime = 9 }, ((KeyValuePair <string, Light>)cbObject.SelectedItem).Key); } else { BridgeStore.SelectedBridge.SetState <Group>(new HueLib2.Action() { hue = hueTemp, bri = 255, sat = 255, @on = true, transitiontime = 9 }, ((KeyValuePair <string, Group>)cbObject.SelectedItem).Key); } } }
void temp_OnTempUpdated(object sender, CpuTempEventArgs e) { float? actualtemp = e.currentTemp; ushort hueTemp = 0; if (actualtemp == null) { hueTemp = (ushort)_gradientStartColor; } else { double gradientRange = _gradientStartColor - _gradientStopColor; double tempRange = _gradientStopTemp - _gradientStartTemp; // Check for the order of the sliders. Is the first slider before the 2nd or the other way around. if (gradientRange > 0) { double multiplier = _gradientStartColor / tempRange; hueTemp = (ushort)(_gradientStartColor - (multiplier * (actualtemp - _gradientStartTemp))); } else { hueTemp = (ushort)((_gradientStopColor * actualtemp) / _gradientStopTemp); } } if (_objectType == true) { BridgeStore.SelectedBridge.SetState <Light>(new State() { hue = hueTemp, bri = _userBri, sat = _userSat, @on = true, transitiontime = 9 }, _objectId); } else { BridgeStore.SelectedBridge.SetState <Group>(new HueLib2.Action() { hue = hueTemp, bri = _userBri, sat = _userSat, @on = true, transitiontime = 9 }, _objectId); } }