Skip to content

Commit

Permalink
Merge pull request #2056 from Fluto/asus-fix-01
Browse files Browse the repository at this point in the history
ASUS Fixes 01
  • Loading branch information
diogotr7 authored Jun 1, 2020
2 parents 0de4418 + 475d960 commit 5045d20
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Drawing;
using AuraServiceLib;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
VerticalAlignment="Stretch"
Height="auto">
<StackPanel Orientation="Vertical">
<CheckBox Content="Enabled" Name="DeviceEnabledCheckBox" IsChecked="False"/>
<StackPanel Orientation="Horizontal" >
<CheckBox Content="Enabled" Name="DeviceEnabledCheckBox" IsChecked="False"/>
<Button Name="SetAllNone" Content="Set All None" DockPanel.Dock="Top" Click="SetAllNone_Click" ToolTip="Set all of the lights to NONE"/>
<Button Name="SetAllLogo" Content="Set All Logo" DockPanel.Dock="Top" Click="SetAllLogo_Click" ToolTip="Set all of the lights to PERIPHERAL_LOGO"/>
</StackPanel>
<StackPanel Orientation="Vertical" Name="AsusDeviceKeys">
<config:AsusKeyToDeviceKeyControl/>
</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public partial class AsusConfigWindow : Window
public AsusConfigWindow()
{
if (windowOpen)
{
Close();
return;
}

windowOpen = true;
InitializeComponent();
Expand Down Expand Up @@ -122,6 +125,12 @@ private void DeviceSelect(int index)
selectedDevice = index;
keys.Clear();

for (int i = 0; i < AsusDeviceList.Children.Count; i++)
{
if (AsusDeviceList.Children[i] is Button button)
button.IsEnabled = i != index;
}

// Rebuild the key area
AsusDeviceKeys.Children.Clear();
var device = devices[index];
Expand All @@ -140,6 +149,8 @@ private void DeviceSelect(int index)
keyControl.KeyIdValue.Text = i.ToString();
if (configDevice.HasValue && configDevice.Value.KeyMapper.TryGetValue(i, out var deviceKey))
keyControl.DeviceKey.SelectedValue = deviceKey;
else
keyControl.DeviceKey.SelectedValue = DeviceKeys.NONE;

keys.Add(keyControl);

Expand All @@ -160,26 +171,31 @@ public async void BlinkLight(IAuraSyncDevice device, int lightId)
tokenSource.Cancel();

tokenSource = new CancellationTokenSource();
for (int i = 0; i < BlinkCount; i++)
var token = tokenSource.Token;
try
{
if (tokenSource.IsCancellationRequested || device == null)
return;

// set everything to black
foreach (IAuraRgbLight light in device.Lights)
light.Color = 0;

// set this one key to white
if (i % 2 == 1)
for (int i = 0; i < BlinkCount; i++)
{
device.Lights[lightId].Red = 255;
device.Lights[lightId].Green = 255;
device.Lights[lightId].Blue = 255;
if (token.IsCancellationRequested || device == null)
return;

// set everything to black
foreach (IAuraRgbLight light in device.Lights)
light.Color = 0;

// set this one key to white
if (i % 2 == 1)
{
device.Lights[lightId].Red = 255;
device.Lights[lightId].Green = 255;
device.Lights[lightId].Blue = 255;
}

device.Apply();
await Task.Delay(200, token); // ms
}

device.Apply();
await Task.Delay(200); // ms
}
catch { }
}

private void SaveDevice()
Expand Down Expand Up @@ -245,6 +261,18 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
{
SaveToFile();
}

private void SetAllNone_Click(object sender, RoutedEventArgs e)
{
foreach (var key in keys)
key.DeviceKey.SelectedValue = DeviceKeys.NONE;
}

private void SetAllLogo_Click(object sender, RoutedEventArgs e)
{
foreach (var key in keys)
key.DeviceKey.SelectedValue = DeviceKeys.Peripheral_Logo;
}
#endregion
}
}

0 comments on commit 5045d20

Please sign in to comment.