From 5d6dd99b97481c22da1c71ff2b0226d49eed8c69 Mon Sep 17 00:00:00 2001 From: Yorick Rommers Date: Tue, 1 Dec 2015 12:44:25 +0100 Subject: [PATCH 1/2] color working --- HueUWP/APIHandler.cs | 2 +- HueUWP/Light.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/HueUWP/APIHandler.cs b/HueUWP/APIHandler.cs index 9ece594..de1e021 100755 --- a/HueUWP/APIHandler.cs +++ b/HueUWP/APIHandler.cs @@ -44,7 +44,7 @@ namespace HueUWP { if(l.IsOn) { - var json = await nwh.SetLightInfo(l.ID, $"{{\"bri\": {l.Brightness},\"hue\": {l.Hue},\"sat\": {l.Saturation}}}"); + var json = await nwh.SetLightInfo(l.ID, $"{{\"bri\": {l.Brightness},\"hue\": {l.Hue*255},\"sat\": {l.Saturation}}}"); Debug.WriteLine(json); } diff --git a/HueUWP/Light.cs b/HueUWP/Light.cs index 1000795..eaf5a41 100644 --- a/HueUWP/Light.cs +++ b/HueUWP/Light.cs @@ -43,6 +43,7 @@ namespace HueUWP this.Hue = h; this.Saturation = s; this.Brightness = v; api.SetLightValues(this); Debug.WriteLine(r + "-" + g + "-" + b); + Debug.WriteLine(h + "-" + s + "-" + v); } From 597309ca722ac1275da821360cc1ed0dc8d1e4ae Mon Sep 17 00:00:00 2001 From: Yorick Rommers Date: Tue, 1 Dec 2015 13:08:40 +0100 Subject: [PATCH 2/2] color fix --- HueUWP/APIHandler.cs | 4 +--- HueUWP/MainPage.xaml.cs | 17 +++++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/HueUWP/APIHandler.cs b/HueUWP/APIHandler.cs index de1e021..89020e3 100755 --- a/HueUWP/APIHandler.cs +++ b/HueUWP/APIHandler.cs @@ -44,7 +44,7 @@ namespace HueUWP { if(l.IsOn) { - var json = await nwh.SetLightInfo(l.ID, $"{{\"bri\": {l.Brightness},\"hue\": {l.Hue*255},\"sat\": {l.Saturation}}}"); + var json = await nwh.SetLightInfo(l.ID, $"{{\"bri\": {l.Brightness-1},\"hue\": {(l.Hue/360)*65535},\"sat\": {l.Saturation*254}}}"); Debug.WriteLine(json); } @@ -55,9 +55,7 @@ namespace HueUWP List lightlist = new List(); try { var json = await nwh.AllLights(); - Debug.WriteLine(json); JObject o = JObject.Parse(json); - Debug.WriteLine(o.ToString()); for (int i = 1; i <= o.Count; i++) { diff --git a/HueUWP/MainPage.xaml.cs b/HueUWP/MainPage.xaml.cs index 1cab349..d474057 100644 --- a/HueUWP/MainPage.xaml.cs +++ b/HueUWP/MainPage.xaml.cs @@ -32,6 +32,8 @@ namespace HueUWP private ObservableCollection _lightsViewModel = LightDataSource.GetLights(); + private APIHandler api; + public ObservableCollection LightsViewModel { get { return this._lightsViewModel; } @@ -43,11 +45,11 @@ namespace HueUWP LOCAL_SETTINGS.Values["ip"] = "localhost"; LOCAL_SETTINGS.Values["port"] = 8000; NetworkHandler nwh = new NetworkHandler(); - APIHandler api = new APIHandler(nwh); - //api.Register(); + api = new APIHandler(nwh); api.GetAllLights(_lightsViewModel); - - Debug.WriteLine(LOCAL_SETTINGS.Values["id"]); + + + } @@ -73,6 +75,7 @@ namespace HueUWP ToggleSwitch button = ((ToggleSwitch)sender); Light light = (Light)button.DataContext; light.UpdateState(button.IsOn); + light.UpdateColor(0, 38, 255); } private void slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) @@ -84,12 +87,14 @@ namespace HueUWP private void RegisterButton_Click(object sender, RoutedEventArgs e) { - + api.Register(); + Debug.WriteLine(LOCAL_SETTINGS.Values["id"]); } private void RefreshButton_Click(object sender, RoutedEventArgs e) { - + _lightsViewModel.Clear(); + api.GetAllLights(_lightsViewModel); } } }