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

Commit

Permalink
Clean up UI; added full support for layout syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
kprinssu committed Aug 12, 2016
1 parent 15d00d1 commit 6a23fa0
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 112 deletions.
4 changes: 2 additions & 2 deletions AnneProKeyboard/KeyboardKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class KeyboardKey
static KeyboardKey()
{
// "Empty" key, also the unassigned value key
StringKeyboardKeys[""] = new KeyboardKey("", "None", 0);
IntKeyboardKeys[0] = StringKeyboardKeys[""];
StringKeyboardKeys["None"] = new KeyboardKey("None", "None", 0);
IntKeyboardKeys[0] = StringKeyboardKeys["None"];

// "Anne" key
StringKeyboardKeys["Anne"] = new KeyboardKey("Anne", "Anne", 250);
Expand Down
18 changes: 17 additions & 1 deletion AnneProKeyboard/KeyboardProfileItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace AnneProKeyboard
[DataContract]
public class KeyboardProfileItem : INotifyPropertyChanged
{
public EventHandler SyncStatusNotify;

private int _ID;
[DataMember]
public int ID
Expand Down Expand Up @@ -89,6 +91,7 @@ private bool SpecialKeyExists(List<KeyboardKey> keys)
if (key.KeyValue == 250)
{
anne_key = true;
int index = keys.IndexOf(key);
}
else if (key.KeyValue == 254)
{
Expand Down Expand Up @@ -187,7 +190,8 @@ private void SyncProfilePhase1(CoreDispatcher dispatcher, GattCharacteristic gat
KeyboardWriter keyboard_writer = new KeyboardWriter(dispatcher, gatt, lighting_meta_data, light_data);
keyboard_writer.WriteToKeyboard();

keyboard_writer.OnWriteFinished += (object_s, events) => { SyncProfilePhase2(dispatcher, gatt); }; // we need to do this because of async calls, threading is fun!
keyboard_writer.OnWriteFinished += (object_s, events) => { SyncProfilePhase2(dispatcher, 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"); };
}

// send the layout data
Expand All @@ -207,6 +211,18 @@ private void SyncProfilePhase2(CoreDispatcher dispatcher, GattCharacteristic gat

KeyboardWriter keyboard_writer = new KeyboardWriter(dispatcher, gatt, layout_meta_data, layout_data);
keyboard_writer.WriteToKeyboard();

keyboard_writer.OnWriteFinished += (object_s, events) => { NotifyStatus("Layout data 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 (layout): exception handled"); };
}

private void NotifyStatus(string status)
{
EventHandler handler = this.SyncStatusNotify;
if (handler != null)
{
handler(status, EventArgs.Empty);
}
}
}
}
Loading

0 comments on commit 6a23fa0

Please sign in to comment.