diff --git a/HueUWP/APIHandler.cs b/HueUWP/APIHandler.cs
index a6935a5..d973a9c 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);
}
@@ -57,11 +58,11 @@ namespace HueUWP
var json = await nwh.AllLights();
JObject o = JObject.Parse(json);
- for (int i = 1; i <= o.Count; i++)
+ foreach(var i in o)
{
- var light = o["" + i];
+ var light = o["" + i.Key];
var state = light["state"];
- alllights.Add(new Light() { api = this,ID = i, Brightness = (int)state["bri"], IsOn = ((string)state["on"]).ToLower() == "true" ? true : false, Hue = (int)state["hue"], Saturation = (int)state["sat"], Name = (string)light["name"], Type = (string)light["type"] });
+ alllights.Add(new Light() { api = this,ID = Int32.Parse( i.Key), Brightness = (int)state["bri"], IsOn = ((string)state["on"]).ToLower() == "true" ? true : false, Hue = (int)state["hue"], Saturation = (int)state["sat"], Name = (string)light["name"], Type = (string)light["type"] });
Debug.WriteLine("Added light number " + i + " " + state["on"]);
} }
catch(Exception e)
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 5636988..46b7285 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 SettingsButton_Click(object sender, RoutedEventArgs e)
diff --git a/HueUWP/NetworkHandler.cs b/HueUWP/NetworkHandler.cs
index c0a45bf..ed0daeb 100755
--- a/HueUWP/NetworkHandler.cs
+++ b/HueUWP/NetworkHandler.cs
@@ -11,12 +11,12 @@ namespace HueUWP
{
public class NetworkHandler
{
- string ip;
- int port;
+ //string (string) MainPage.LOCAL_SETTINGS.Values["ip"];
+ //int (int)MainPage.LOCAL_SETTINGS.Values["port"];
public NetworkHandler()
{
- this.ip = (string) MainPage.LOCAL_SETTINGS.Values["ip"];
- this.port = (int)MainPage.LOCAL_SETTINGS.Values["port"];
+ //this.(string) MainPage.LOCAL_SETTINGS.Values["ip"] = (string) MainPage.LOCAL_SETTINGS.Values["(string) MainPage.LOCAL_SETTINGS.Values["ip"]"];
+ //this.(int)MainPage.LOCAL_SETTINGS.Values["port"] = (int)MainPage.LOCAL_SETTINGS.Values["(int)MainPage.LOCAL_SETTINGS.Values["port"]"];
}
private async Task Put(string path, string json)
@@ -31,7 +31,7 @@ namespace HueUWP
HttpClient client = new HttpClient();
HttpStringContent content = new HttpStringContent(json, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application /json");
- Uri uriLampState = new Uri($"http://{ip}:{port}/api/" + path);
+ Uri uriLampState = new Uri($"http://{(string) MainPage.LOCAL_SETTINGS.Values["ip"]}:{(int)MainPage.LOCAL_SETTINGS.Values["port"]}/api/" + path);
var response = await client.PutAsync(uriLampState, content).AsTask(cts.Token);
if (!response.IsSuccessStatusCode)
@@ -63,7 +63,7 @@ namespace HueUWP
HttpClient client = new HttpClient();
HttpStringContent content = new HttpStringContent(json, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application /json");
- Uri uriLampState = new Uri($"http://{ip}:{port}/api/" + path);
+ Uri uriLampState = new Uri($"http://{(string) MainPage.LOCAL_SETTINGS.Values["ip"]}:{(int)MainPage.LOCAL_SETTINGS.Values["port"]}/api/" + path);
var response = await client.PostAsync(uriLampState, content).AsTask(cts.Token);
if (!response.IsSuccessStatusCode)
@@ -94,7 +94,7 @@ namespace HueUWP
HttpClient client = new HttpClient();
//HttpStringContent content = new HttpStringContent($"{{\"devicetype\":\"Test#Test\"}}", Windows.Storage.Streams.UnicodeEncoding.Utf8, "application /json");
- Uri uriLampState = new Uri($"http://{ip}:{port}/api/" + path);
+ Uri uriLampState = new Uri($"http://{(string) MainPage.LOCAL_SETTINGS.Values["ip"]}:{(int)MainPage.LOCAL_SETTINGS.Values["port"]}/api/" + path);
var response = await client.GetAsync(uriLampState).AsTask(cts.Token);
if (!response.IsSuccessStatusCode)