From c8af704c9be1d03688a0a7fa7b32a8f143d72b6f Mon Sep 17 00:00:00 2001 From: Yorick Rommers Date: Tue, 1 Dec 2015 15:00:49 +0100 Subject: [PATCH] sliders working --- HueUWP/APIHandler.cs | 3 ++- HueUWP/DetailView.xaml | 6 +++--- HueUWP/DetailView.xaml.cs | 19 ++++++++++++++++++- HueUWP/Light.cs | 17 +++++++++-------- HueUWP/MainPage.xaml.cs | 3 --- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/HueUWP/APIHandler.cs b/HueUWP/APIHandler.cs index a6935a5..9f27ed9 100755 --- a/HueUWP/APIHandler.cs +++ b/HueUWP/APIHandler.cs @@ -44,7 +44,8 @@ namespace HueUWP { if(l.IsOn) { - var json = await nwh.SetLightInfo(l.ID, $"{{\"bri\": {l.Brightness-1},\"hue\": {(l.Hue/360)*65535},\"sat\": {l.Saturation*254}}}"); + Debug.WriteLine(l.Hue); + var json = await nwh.SetLightInfo(l.ID, $"{{\"bri\": {l.Brightness},\"hue\": {(l.Hue)},\"sat\": {l.Saturation}}}"); Debug.WriteLine(json); } diff --git a/HueUWP/DetailView.xaml b/HueUWP/DetailView.xaml index b518b35..d8cb6ef 100644 --- a/HueUWP/DetailView.xaml +++ b/HueUWP/DetailView.xaml @@ -19,9 +19,9 @@ - - - + + + diff --git a/HueUWP/DetailView.xaml.cs b/HueUWP/DetailView.xaml.cs index 67ba713..3a756dc 100644 --- a/HueUWP/DetailView.xaml.cs +++ b/HueUWP/DetailView.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; @@ -33,6 +34,22 @@ namespace HueUWP { l = e.Parameter as Light; this.DataContext = l; - } + } + + + private void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) + { + //l.UpdateColor(); + } + + private void Slider_DragLeave(object sender, DragEventArgs e) + { + l.UpdateColor(); + } + + private void Slider_PointerCaptureLost(object sender, PointerRoutedEventArgs e) + { + l.UpdateColor(); + } } } diff --git a/HueUWP/Light.cs b/HueUWP/Light.cs index bb1ec28..0a17e2e 100644 --- a/HueUWP/Light.cs +++ b/HueUWP/Light.cs @@ -41,16 +41,17 @@ namespace HueUWP } - public void UpdateColor(int r, int g, int b) + public void UpdateColor() { - NotifyPropertyChanged(nameof(UpdateColor)); - double h; double s; double v; - ColorUtil.RGBtoHSV(r,g,b, out h,out s,out v); - this.Hue = h; this.Saturation = s; this.Brightness = v; api.SetLightValues(this); - Debug.WriteLine(r + "-" + g + "-" + b); - Debug.WriteLine(h + "-" + s + "-" + v); - NotifyPropertyChanged(nameof(UpdateColor)); + } + + public void UpdateColor(int h, int s, int b) + { + //double h; double s; double v; + //ColorUtil.RGBtoHSV(r,g,b, out h,out s,out v); + this.Hue = h; this.Saturation = s; this.Brightness = b; + api.SetLightValues(this); } diff --git a/HueUWP/MainPage.xaml.cs b/HueUWP/MainPage.xaml.cs index 6f6a8b6..f06ae7c 100644 --- a/HueUWP/MainPage.xaml.cs +++ b/HueUWP/MainPage.xaml.cs @@ -54,8 +54,6 @@ namespace HueUWP { Button button = ((Button)sender); Light light = (Light)button.DataContext; - - light.UpdateColor(10, 10, 10); } public void ToggleSwitch_Tapped(object sender, TappedRoutedEventArgs e) @@ -72,7 +70,6 @@ namespace HueUWP ToggleSwitch button = ((ToggleSwitch)sender); Light light = (Light)button.DataContext; light.UpdateState(button.IsOn); - light.UpdateColor(0, 38, 255); } private void RegisterButton_Click(object sender, RoutedEventArgs e)