private void RequestKeyboardSync() { // expect firmware version and mac address byte[] device_id_meta_data = { 0x02, 0x01, 0x01 }; KeyboardWriter keyboard_writer = new KeyboardWriter(this.WriteGatt, device_id_meta_data, null); keyboard_writer.WriteToKeyboard(); keyboard_writer.OnWriteFinished += (object_s, events) => { FinishSync(); }; }
// send the backlight first data, should cause a waterfall effect on syncing up the profile private void SyncProfilePhase1(GattCharacteristic gatt) { // We need this to identify the type of data we are sending byte[] lighting_meta_data = { 0x09, 0xD7, 0x03 }; // Convert the list of keyboard colours byte[] light_data = this.GenerateKeyboardBacklightData(); // Send the data to the keyboard 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.OnWriteFailed += (object_s, events) => { NotifyStatus("Failed to sync profile (light): exception handled"); }; }
// send the layout data private void SyncProfilePhase2(GattCharacteristic gatt) { if (!this.ValidateKeyboardKeys()) { // raise an error? return; } // We need this to identify the type of data we are sending byte[] layout_meta_data = { 0x7, 0x91, 0x02 }; // Convert the list of keyboard keys byte[] layout_data = this.GenerateKeyboardLayoutData(); KeyboardWriter keyboard_writer = new KeyboardWriter(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"); }; }