Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Commit

Permalink
Showing the FW and HW revision on the info page
Browse files Browse the repository at this point in the history
  • Loading branch information
COM8 committed Feb 10, 2019
1 parent a2f2d6d commit fe72ade
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
12 changes: 12 additions & 0 deletions Onewheel/Pages/InfoPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@
<TextBlock x:Name="deviceId_tbx"
TextWrapping="Wrap"/>

<TextBlock Margin="0,10,0,0"
FontSize="20"
Text="Firmware revision:"/>
<TextBlock x:Name="firmware_tbx"
TextWrapping="Wrap"/>

<TextBlock Margin="0,10,0,0"
FontSize="20"
Text="Hardware revision:"/>
<TextBlock x:Name="hardware_tbx"
TextWrapping="Wrap"/>

<TextBlock Margin="0,10,0,0"
FontSize="20"
Text="Battery:"/>
Expand Down
41 changes: 34 additions & 7 deletions Onewheel/Pages/InfoPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Onewheel_UI_Context.Classes;
using OnewheelBluetooth.Classes;
using System;
using Shared.Classes;
using System.Threading.Tasks;
using Windows.Devices.Bluetooth;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand Down Expand Up @@ -95,10 +96,22 @@ private void ShowBoard()
}
}

private void ShowCellVoltages()
private async Task ShowCellVoltagesAsync()
{
byte[] data = OnewheelConnectionHelper.INSTANCE.CACHE.GetBytes(OnewheelCharacteristicsCache.CHARACTERISTIC_BATTERY_CELL_VOLTAGES);
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => batteryCellVoltages_bcvc.SetVoltages(data)).AsTask();
await SharedUtils.CallDispatcherAsync(() => batteryCellVoltages_bcvc.SetVoltages(data));
}

private async Task ShowHardwareRevisionAsync()
{
uint hw = OnewheelConnectionHelper.INSTANCE.CACHE.GetUint(OnewheelCharacteristicsCache.CHARACTERISTIC_HARDWARE_REVISION);
await SharedUtils.CallDispatcherAsync(() => hardware_tbx.Text = hw.ToString());
}

private async Task ShowFirmwareRevisionAsync()
{
uint fw = OnewheelConnectionHelper.INSTANCE.CACHE.GetUint(OnewheelCharacteristicsCache.CHARACTERISTIC_FIRMWARE_REVISION);
await SharedUtils.CallDispatcherAsync(() => firmware_tbx.Text = fw.ToString());
}

#endregion
Expand All @@ -109,22 +122,36 @@ private void ShowCellVoltages()
#endregion
//--------------------------------------------------------Events:---------------------------------------------------------------------\\
#region --Events--
private void Page_Loaded(object sender, RoutedEventArgs e)
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
OnewheelConnectionHelper.INSTANCE.OnewheelChanged += INSTANCE_OnewheelChanged;
OnewheelConnectionHelper.INSTANCE.CACHE.CharacteristicChanged += CACHE_CharacteristicChanged;
SetBoard(OnewheelConnectionHelper.INSTANCE.GetOnewheel());

// Battery:
ShowCellVoltages();
await ShowCellVoltagesAsync();
// Firmware:
await ShowFirmwareRevisionAsync();
// Hardware:
await ShowHardwareRevisionAsync();
}

private void CACHE_CharacteristicChanged(OnewheelCharacteristicsCache sender, OnewheelBluetooth.Classes.Events.CharacteristicChangedEventArgs args)
private async void CACHE_CharacteristicChanged(OnewheelCharacteristicsCache sender, OnewheelBluetooth.Classes.Events.CharacteristicChangedEventArgs args)
{
// Battery:
if (args.UUID.Equals(OnewheelCharacteristicsCache.CHARACTERISTIC_BATTERY_CELL_VOLTAGES))
{
ShowCellVoltages();
await ShowCellVoltagesAsync();
}
// Firmware:
else if (args.UUID.Equals(OnewheelCharacteristicsCache.CHARACTERISTIC_FIRMWARE_REVISION))
{
await ShowFirmwareRevisionAsync();
}
// Hardware:
else if (args.UUID.Equals(OnewheelCharacteristicsCache.CHARACTERISTIC_HARDWARE_REVISION))
{
await ShowHardwareRevisionAsync();
}
}

Expand Down

0 comments on commit fe72ade

Please sign in to comment.