Merge remote-tracking branch 'origin/dev' into dev
Conflicts: HueUWP/MainPage.xaml.cs
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
</RelativePanel>
|
||||
|
||||
<StackPanel Grid.Row="1">
|
||||
<Slider Maximum="65535" Value="{Binding Hue}" />
|
||||
<Slider Maximum="254" Value="{Binding Saturation}" />
|
||||
<Slider Maximum="254" Value="{Binding Brightness}" />
|
||||
<Slider Maximum="65535" Value="{Binding Hue, Mode=TwoWay}" ValueChanged="Slider_ValueChanged" PointerCaptureLost="Slider_PointerCaptureLost"/>
|
||||
<Slider Maximum="254" Value="{Binding Saturation, Mode=TwoWay}" ValueChanged="Slider_ValueChanged" PointerCaptureLost="Slider_PointerCaptureLost" />
|
||||
<Slider Maximum="254" Value="{Binding Brightness, Mode=TwoWay}" ValueChanged="Slider_ValueChanged" PointerCaptureLost="Slider_PointerCaptureLost"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-8
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<String> 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)
|
||||
|
||||
Reference in New Issue
Block a user