disco added
This commit is contained in:
+32
-2
@@ -6,6 +6,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace HueUWP
|
||||
@@ -49,6 +50,23 @@ namespace HueUWP
|
||||
lights.ForEach(l => SetLightState(l));
|
||||
}
|
||||
|
||||
public async void DiscoMode(ObservableCollection<Light> lights)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
for(int i = 0; i < 100; i++)
|
||||
{
|
||||
lights.ToList().ForEach(l =>
|
||||
{
|
||||
l.Hue = rnd.Next(0, 65535);
|
||||
l.Brightness = rnd.Next(128, 254);
|
||||
l.UpdateColorDisco();
|
||||
});
|
||||
//"transitiontime": 0
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(100));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task<String> SetLightValues(Light l)
|
||||
{
|
||||
if(l.IsOn)
|
||||
@@ -61,6 +79,18 @@ namespace HueUWP
|
||||
|
||||
return "error";
|
||||
}
|
||||
public async Task<String> SetInstantLightValues(Light l)
|
||||
{
|
||||
if (l.IsOn)
|
||||
{
|
||||
Debug.WriteLine(l.Hue);
|
||||
var json = await nwh.SetLightInfo(l.ID, $"{{\"bri\": {l.Brightness},\"hue\": {(l.Hue)},\"sat\": {l.Saturation}, \"transitiontime\" : 0}}");
|
||||
Debug.WriteLine(json);
|
||||
return "success";
|
||||
}
|
||||
|
||||
return "error";
|
||||
}
|
||||
|
||||
public async void SetLightValues(List<Light> lights)
|
||||
{
|
||||
@@ -84,8 +114,8 @@ namespace HueUWP
|
||||
}
|
||||
else
|
||||
{
|
||||
alllights.Add(new Light() { api = this, ID = Int32.Parse(i.Key), Brightness = (int)state["bri"], SaturationEnabled = false,HueEnabled = false,IsOn = ((string)state["on"]).ToLower() == "true" ? true : false, Hue =-1, Saturation = 254, Name = (string)light["name"], Type = (string)light["type"] });
|
||||
}//Debug.WriteLine("Added light number " + i + " " + state["on"]);
|
||||
alllights.Add(new Light() { api = this, ID = Int32.Parse(i.Key), Brightness = (int)state["bri"], SaturationEnabled = false, HueEnabled = false, IsOn = ((string)state["on"]).ToLower() == "true" ? true : false, Hue = -1, Saturation = 254, Name = (string)light["name"], Type = (string)light["type"] });
|
||||
}
|
||||
}
|
||||
return "success";
|
||||
}
|
||||
|
||||
@@ -76,6 +76,11 @@ namespace HueUWP
|
||||
api.SetLightValues(this);
|
||||
}
|
||||
|
||||
public void UpdateColorDisco()
|
||||
{
|
||||
api.SetInstantLightValues(this);
|
||||
}
|
||||
|
||||
public void UpdateColor(int h, int s, int b)
|
||||
{
|
||||
//double h; double s; double v;
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
|
||||
<Page.BottomAppBar>
|
||||
<CommandBar>
|
||||
<AppBarButton Icon="Audio" Label="Disco" Click="AppBarButton_Click"/>
|
||||
<AppBarButton Icon="Setting" Label="Settings" Click="SettingsButton_Click"/>
|
||||
<AppBarButton Icon="Refresh" Label="Refresh" Click="RefreshButton_Click"/>
|
||||
<AppBarSeparator/>
|
||||
|
||||
@@ -118,5 +118,10 @@ namespace HueUWP
|
||||
Frame rootframe = Window.Current.Content as Frame;
|
||||
rootframe.Navigate(typeof(AboutView));
|
||||
}
|
||||
|
||||
private void AppBarButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
api.DiscoMode(_lightsViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user