added slider for testing
This commit is contained in:
+13
-4
@@ -34,13 +34,22 @@ namespace HueUWP
|
||||
}
|
||||
}
|
||||
|
||||
public async void SetLightData(Light l)
|
||||
public async void SetLightState(Light l)
|
||||
{
|
||||
|
||||
var json = await nwh.ToggleLight(l.ID, $"{{\"on\": {((l.On) ? "true" : "false")},\"bri\": {l.Brightness},\"hue\": { l.Hue},\"sat\": {l.Saturation}}}");
|
||||
var json = await nwh.SetLightInfo(l.ID, $"{{\"on\": {((l.IsOn) ? "true" : "false")}}}");
|
||||
Debug.WriteLine(json);
|
||||
}
|
||||
|
||||
public async void SetLightValues(Light l)
|
||||
{
|
||||
if(l.IsOn)
|
||||
{
|
||||
var json = await nwh.SetLightInfo(l.ID, $"{{\"bri\": {l.Brightness},\"hue\": {l.Hue},\"sat\": {l.Saturation}}}");
|
||||
Debug.WriteLine(json);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async void GetAllLights(ObservableCollection<Light> alllights)
|
||||
{
|
||||
List<Light> lightlist = new List<Light>();
|
||||
@@ -54,7 +63,7 @@ namespace HueUWP
|
||||
{
|
||||
var light = o["" + i];
|
||||
var state = light["state"];
|
||||
alllights.Add(new Light() { api = this,ID = i, Brightness = (int)state["bri"], On = (bool)state["on"], Hue = (int)state["hue"], Saturation = (int)state["sat"], Name = (string)light["name"], Type = (string)light["type"] });
|
||||
alllights.Add(new Light() { api = this,ID = i, Brightness = (int)state["bri"], IsOn = (string)state["on"] == "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);
|
||||
} }
|
||||
catch(Exception e)
|
||||
|
||||
+11
-15
@@ -16,36 +16,32 @@ namespace HueUWP
|
||||
public string Name { get; set; }
|
||||
public string Type { get; set; }
|
||||
|
||||
public bool On { get; set; }
|
||||
public int Brightness{ get; set; }
|
||||
public int Hue { get; set; }
|
||||
public int Saturation { get; set; }
|
||||
public bool IsOn { get; set; }
|
||||
public double Brightness{ get; set; }
|
||||
public double Hue { get; set; }
|
||||
public double Saturation { get; set; }
|
||||
|
||||
public APIHandler api { get; set; }
|
||||
|
||||
public Light()
|
||||
{
|
||||
//temp
|
||||
ID = 1;
|
||||
Name = "Lamp 1";
|
||||
Type = "Extended color light";
|
||||
On = true;
|
||||
Brightness = 10;
|
||||
Hue = 14215;
|
||||
Saturation = 425;
|
||||
{
|
||||
}
|
||||
|
||||
public void UpdateState(bool on)
|
||||
{
|
||||
NotifyPropertyChanged(nameof(UpdateState));
|
||||
this.On = on;
|
||||
api.SetLightData(this);
|
||||
this.IsOn = on;
|
||||
api.SetLightState(this);
|
||||
|
||||
}
|
||||
|
||||
public void UpdateColor(int r, int g, int b)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,17 +22,19 @@
|
||||
<TextBlock Text="{Binding Type}" FontSize="14" />
|
||||
</StackPanel>
|
||||
|
||||
<ToggleSwitch Toggled="ToggleSwitch_Toggled">
|
||||
<ToggleSwitch Toggled="ToggleSwitch_Toggled" >
|
||||
<ToggleSwitch.OffContent>Off</ToggleSwitch.OffContent>
|
||||
<ToggleSwitch.OnContent>On</ToggleSwitch.OnContent>
|
||||
</ToggleSwitch>
|
||||
<Slider x:Name="slider" Maximum="255" Minimum="0" Width="100" ValueChanged="slider_ValueChanged" />
|
||||
|
||||
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
|
||||
</ListView>
|
||||
</ListView>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
|
||||
@@ -70,11 +70,16 @@ namespace HueUWP
|
||||
|
||||
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Debug.WriteLine("Hello again");
|
||||
ToggleSwitch button = ((ToggleSwitch)sender);
|
||||
Light light = (Light)button.DataContext;
|
||||
Debug.WriteLine("Hello");
|
||||
light.UpdateState(button.IsOn);
|
||||
}
|
||||
|
||||
private void slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
|
||||
{
|
||||
Slider slider = ((Slider)sender);
|
||||
Light l = (Light)slider.DataContext;
|
||||
l.UpdateColor((int)slider.Value, 255, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace HueUWP
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<String> ToggleLight(int lightid, string json)
|
||||
public async Task<String> SetLightInfo(int lightid, string json)
|
||||
{
|
||||
var response = await Put($"{(String)MainPage.LOCAL_SETTINGS.Values["id"]}/lights/{lightid}/state", json);
|
||||
return response;
|
||||
|
||||
Reference in New Issue
Block a user