Skip to content
This repository has been archived by the owner on Nov 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #24 from ethanmsmith/master
Browse files Browse the repository at this point in the history
Redesigned UI and small code refactoring
  • Loading branch information
kprinssu authored Dec 17, 2017
2 parents 13f41da + 3076df1 commit e5f1207
Show file tree
Hide file tree
Showing 15 changed files with 1,963 additions and 1,029 deletions.
17 changes: 17 additions & 0 deletions AnneProKeyboard/AboutPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Page
x:Class="AnneProKeyboard.AboutPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AnneProKeyboard"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" MinWidth="960" MinHeight="480">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<WebView Name="aboutGitHub" Grid.Row="0" x:FieldModifier="public" Source="ms-appx-web:///Assets/README.html" />
</Grid>
</Page>
30 changes: 30 additions & 0 deletions AnneProKeyboard/AboutPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace AnneProKeyboard
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class AboutPage : Page
{
public AboutPage()
{
this.InitializeComponent();
}
}
}
27 changes: 25 additions & 2 deletions AnneProKeyboard/AnneProKeyboard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,24 @@
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="AboutPage.xaml.cs">
<DependentUpon>AboutPage.xaml</DependentUpon>
</Compile>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="LightingPage.xaml.cs">
<DependentUpon>LightingPage.xaml</DependentUpon>
</Compile>
<Compile Include="CRC16.cs" />
<Compile Include="KeyboardKey.cs" />
<Compile Include="KeyboardProfileItem.cs" />
<Compile Include="KeyboardWriter.cs" />
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
<Compile Include="LayoutPage.xaml.cs">
<DependentUpon>LayoutPage.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand All @@ -116,7 +125,9 @@
<None Include="AnneProKeyboard_TemporaryKey.pfx" />
</ItemGroup>
<ItemGroup>
<Content Include="Assets\README.html" />
<Content Include="Assets\Square150x150Logo.scale-100.png" />
<Content Include="Assets\controls.png" />
<Content Include="Properties\Default.rd.xml" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\SplashScreen.scale-200.png" />
Expand All @@ -131,7 +142,19 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="AboutPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="LightingPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="LayoutPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
Expand Down
87 changes: 46 additions & 41 deletions AnneProKeyboard/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
Expand All @@ -22,30 +25,19 @@ namespace AnneProKeyboard
/// </summary>
sealed partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>

public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = true;
}
#endif
Frame rootFrame = Window.Current.Content as Frame;
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
ApplicationView.PreferredLaunchViewSize = new Size(1074, 800);
ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(1024, 604));

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
Expand All @@ -55,55 +47,68 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
rootFrame = new Frame();

rootFrame.NavigationFailed += OnNavigationFailed;
rootFrame.Navigated += OnNavigated;

if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
// TODO: Load state from previously suspended application
}

// Place the frame in the current Window
Window.Current.Content = rootFrame;

// Register a handler for BackRequested events and set the
// visibility of the Back button
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;

SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
rootFrame.CanGoBack ?
AppViewBackButtonVisibility.Visible :
AppViewBackButtonVisibility.Collapsed;
}

if (e.PrelaunchActivated == false)
if (rootFrame.Content == null)
{
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
// Ensure the current window is active
Window.Current.Activate();
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}

this.DebugSettings.EnableFrameRateCounter = false;
this.DebugSettings.EnableRedrawRegions = false;
// Ensure the current window is active
Window.Current.Activate();
}

/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}

/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnNavigated(object sender, NavigationEventArgs e)
{
// Each time a navigation event occurs, update the Back button's visibility
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
((Frame)sender).CanGoBack ?
AppViewBackButtonVisibility.Visible :
AppViewBackButtonVisibility.Collapsed;
}

private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
// TODO: Save application state and stop any background activity
deferral.Complete();
}

private void OnBackRequested(object sender, BackRequestedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;

if (rootFrame.CanGoBack)
{
e.Handled = true;
rootFrame.GoBack();
}
}
}
}
25 changes: 25 additions & 0 deletions AnneProKeyboard/Assets/README.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

<body style="background:#36393e; color:whitesmoke;">
<h1 id="anne-keyboard-windows">Anne Keyboard Windows</h1>
<p>A Universal Windows App for controlling the an Anne Pro keyboard over Bluetooth Low Energy.</p>
<h2 id="requirements">Requirements</h2>
<p>This app has been tested against Windows 10. Other version of Windows is not supported due to Universal Windows App (UWP) platform only supporting Windows 10. The keyboard has to be in L0 mode by: pressing <code>Fn+B, Fn+0, ESC, Fn+B, +</code></p>
<h2 id="supported-features">Supported Features</h2>
<ul>
<li>Automatic keyboard pairing (launch the app, and it should start scanning for the keyboard)</li>
<li>Create and manage profiles</li>
<li>Set keyboard backlight colours</li>
</ul>
<h2 id="planned-features">Planned Features</h2>
<ul>
<li>Support for changing keyboard layouts</li>
<li>Implement keyboard macros</li>
<li>Improve changing multiple button keyboard light colours</li>
</ul>
<h2 id="known-bugs">Known Bugs</h2>
<ul>
<li>None so far. Please submit an issue to report any bugs.</li>
</ul>
<h2 id="license">License</h2>
<p>The codebase and the project are released under the permissive MIT License. The images and icons are generated using the Font Awesome font released under the <a href="http://scripts.sil.org/OFL">OFIL license</a>, and the font can be found on <a href="http://scripts.sil.org/OFL">Github</a>.</p>
</body>
Binary file added AnneProKeyboard/Assets/controls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 38 additions & 3 deletions AnneProKeyboard/KeyboardProfileItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public KeyboardProfileItem(int ID, string Label)
{
this.ID = ID;
this.Label = Label;

this.KeyboardColours = new List<int>();

// We only need 70 values to represent the 61 keys (70 is needed for some reason by the keyboard..)
Expand Down Expand Up @@ -176,7 +176,7 @@ public void SyncProfile(GattCharacteristic gatt)
{
this.SyncProfilePhase1(gatt);
}

// send the backlight first data, should cause a waterfall effect on syncing up the profile
private void SyncProfilePhase1(GattCharacteristic gatt)
{
Expand All @@ -190,7 +190,7 @@ private void SyncProfilePhase1(GattCharacteristic gatt)
KeyboardWriter keyboard_writer = new KeyboardWriter(gatt, lighting_meta_data, light_data);
keyboard_writer.WriteToKeyboard();

keyboard_writer.OnWriteFinished += (object_s, events) => { SyncProfilePhase2(gatt); NotifyStatus("Keyboard light has been synced"); }; // we need to do this because of async calls, threading is fun!
keyboard_writer.OnWriteFinished += (object_s, events) => { SyncProfilePhase2(gatt); NotifyStatus("Keyboard light has been synced"); }; // we need to do this because of async calls, threading is fun!
keyboard_writer.OnWriteFailed += (object_s, events) => { NotifyStatus("Failed to sync profile (light): exception handled"); };
}

Expand Down Expand Up @@ -224,5 +224,40 @@ private void NotifyStatus(string status)
handler(status, EventArgs.Empty);
}
}

public override Boolean Equals(object obj)
{
if (obj == null)
{
return false;
}

if (obj.GetType() == typeof(KeyboardProfileItem))
{
KeyboardProfileItem that = obj as KeyboardProfileItem;
return (this.ID == that.ID && this.Label == that.Label);
}

return false;
}

public static bool operator ==(KeyboardProfileItem a, KeyboardProfileItem b)
{
if (object.ReferenceEquals(a, null))
{
return object.ReferenceEquals(b, null);
}
return a.Equals(b);
}

public static bool operator !=(KeyboardProfileItem a, KeyboardProfileItem b)
{
return !(a == b);
}

public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
Loading

0 comments on commit e5f1207

Please sign in to comment.