Last active
May 18, 2024 14:55
-
-
Save marron-akanishi/ca5b955c99aff978c98246317ea85af3 to your computer and use it in GitHub Desktop.
KING BLADE X10 V BLE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Web Bluetooth APIでの接続例(Mac Chromeでのみ動作確認) */ | |
// 接続開始 | |
const device = await navigator.bluetooth.requestDevice({ | |
filters: [{ | |
name: 'KBX5' | |
}], | |
optionalServices:['00000000-0000-1000-8000-00805f9b34fb'] | |
}); | |
const server = await device.gatt.connect(); | |
const service = await server.getPrimaryService('00000000-0000-1000-8000-00805f9b34fb'); | |
const chara = await service.getCharacteristic('00000000-0000-1000-8000-00805f9b34fb'); | |
// 初期化? | |
await chara.writeValue(new Uint8Array([0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
// 色確認 | |
// Red | |
await chara.writeValue(new Uint8Array([0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
// Green | |
await chara.writeValue(new Uint8Array([0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
// Blue | |
await chara.writeValue(new Uint8Array([0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
// White | |
await chara.writeValue(new Uint8Array([0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
// メモリーAへの保存 | |
// 赤→緑→青→黄 で登録 | |
// 0x1e までに色を順番に送る、1バイト目は連番 | |
await chara.writeValue(new Uint8Array([0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
await chara.writeValue(new Uint8Array([0x01, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
await chara.writeValue(new Uint8Array([0x02, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
await chara.writeValue(new Uint8Array([0x03, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); // RGBは合計値が255になるように調整する | |
// 終了通知? 2バイト目にいくつ色を登録するかの個数を指定 | |
// 1バイト目が0x1eのため、仕様通り30色しか登録できない | |
await chara.writeValue(new Uint8Array([0x1e, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
// 保存? | |
await chara.writeValue(new Uint8Array([0x1f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
// メモリーBへの保存 | |
// 青→赤→白 で登録 | |
// 0x3e までに色を順番に送る、1バイト目は連番 | |
await chara.writeValue(new Uint8Array([0x20, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
await chara.writeValue(new Uint8Array([0x21, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
await chara.writeValue(new Uint8Array([0x22, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
// 終了通知? 2バイト目にいくつ色を登録するかの個数を指定 | |
// 1バイト目が0x3eのため、仕様通り30色しか登録できない | |
await chara.writeValue(new Uint8Array([0x3e, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
// 保存? | |
await chara.writeValue(new Uint8Array([0x3f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); | |
// 切断(自動的に電源が切れる) | |
await device.gatt.disconnect(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Copyright RUIFAN:KBX5 | |
蓮ノ空104期メンカラオンリー | |
FF79000000 | |
2DFF2D0000 | |
0000FF0000 | |
FF00000000 | |
8C00230000 | |
C8C2C60000 | |
0070640000 | |
BEBA000000 | |
DC00D20000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment