Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: microbit_switch_if.h
- Revision:
- 0:28fb3e9ef81a
- Child:
- 1:3b9ae1dbcdcf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/microbit_switch_if.h Mon Sep 17 02:48:51 2018 +0000
@@ -0,0 +1,140 @@
+//=================================
+// microbit_switch_if_3sw
+//=================================
+// BLE switch interface with 3 tact switches for micro:bit
+// The MIT License (MIT) Copyright (c) 2018 Masatomo Kojima
+
+#include "mbed.h"
+#include "MicroBit.h"
+#include "ble/services/BatteryService.h"
+#include "KeyboardService.h"
+#include "Keyboard_types.h"
+#include "HIDServiceBase.h"
+#include "HIDDeviceInformationService.h"
+
+//----------------------
+// Keybord
+//----------------------
+const char KEY_BS = 8; /* Keyboard Backspace */
+const char KEY_TAB = 9; /* Keyboard Tab */
+const char KEY_ENTER = 10; /* Keyboard Return (Enter) */
+//const char KEY_ESC = 27; /* Keyboard Escape */
+const char KEY_SPACE = 32; /* Keyboard Space */
+
+//----------------------
+// Setting
+//----------------------
+#define NUM_GROUP1 6
+#define NUM_GROUP2 5
+
+#define MODIF_CTRL 0x100
+#define MODIF_SHIFT 0x200
+#define MODIF_ALT 0x400 /* alt or option */
+#define MODIF_COMMAND 0x800 /* command or Windows */
+
+const int keyCodeGroup0[2] = { // Button A B
+ 'A', 'B'
+};
+const int keyCodeGroup1[NUM_GROUP1][2] = { // Switch 1 2
+ {KEY_SPACE, KEY_ENTER},
+ {MODIF_ALT + DOWN_ARROW, MODIF_ALT + UP_ARROW},
+ {RIGHT_ARROW, LEFT_ARROW},
+ {DOWN_ARROW, UP_ARROW},
+ {'1', '3'},
+ {'h', 'j'}
+};
+const int keyCodeGroup2[NUM_GROUP2]= { // Switch 2
+ KEY_TAB,
+ MODIF_COMMAND + 'r', // 再読み込み
+ RIGHT_ARROW,
+ LEFT_ARROW,
+ MODIF_ALT + DOWN_ARROW
+};
+
+//in "BLE_API\Keyboad_types.h"
+//enum FUNCTION_KEY {
+// KEY_F1 = 128, /* F1 key */
+// KEY_F2, /* F2 key */
+// KEY_F3, /* F3 key */
+// KEY_F4, /* F4 key */
+// KEY_F5, /* F5 key */
+// KEY_F6, /* F6 key */
+// KEY_F7, /* F7 key */
+// KEY_F8, /* F8 key */
+// KEY_F9, /* F9 key */
+// KEY_F10, /* F10 key */
+// KEY_F11, /* F11 key */
+// KEY_F12, /* F12 key */
+//
+// KEY_PRINT_SCREEN, /* Print Screen key */
+// KEY_SCROLL_LOCK, /* Scroll lock */
+// KEY_CAPS_LOCK, /* caps lock */
+// KEY_NUM_LOCK, /* num lock */
+// KEY_INSERT, /* Insert key */
+// KEY_HOME, /* Home key */
+// KEY_PAGE_UP, /* Page Up key */
+// KEY_PAGE_DOWN, /* Page Down key */
+//
+// RIGHT_ARROW, /* Right arrow */
+// LEFT_ARROW, /* Left arrow */
+// DOWN_ARROW, /* Down arrow */
+// UP_ARROW, /* Up arrow */
+//};
+
+//----------------------
+// Display
+//----------------------
+#define TIME_TURN_OFF 7.0 // 非表示モードに入るまでの時間 (s)
+#define SETTING_DISPLAY_WAIT 1.0 // 設定モード表示時間 (s)
+
+//----------------------
+// State
+//----------------------
+#define STATE_NORMAL 0 // 通常起動時
+#define STATE_SETTING 1 // パラメータ設定時
+#define STATE_OPERATING 2 // 操作時
+
+//----------------------
+// Disable debug messages by setting NO_DEBUG
+//----------------------
+#ifndef NO_DEBUG
+#define DEBUG(...) printf(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
+
+//----------------------
+// BLE & HID
+//----------------------
+/**
+ * IO capabilities of the device. During development, you most likely want "JustWorks", which means
+ * no IO capabilities.
+ * It is also possible to use IO_CAPS_DISPLAY_ONLY to generate and show a pincode on the serial
+ * output.
+ */
+#ifndef HID_SECURITY_IOCAPS
+#define HID_SECURITY_IOCAPS (SecurityManager::IO_CAPS_NONE)
+#endif
+
+/**
+ * Security level. MITM disabled forces "Just Works". If you require MITM, HID_SECURITY_IOCAPS must
+ * be at least IO_CAPS_DISPLAY_ONLY.
+ */
+#ifndef HID_SECURITY_REQUIRE_MITM
+#define HID_SECURITY_REQUIRE_MITM false
+#endif
+
+/**
+ * Initialize security manager: set callback functions and required security level
+ */
+void initializeSecurity(BLE &ble);
+
+/**
+ * - Initialize auxiliary services required by the HID-over-GATT Profile.
+ * - Initialize common Gap advertisement.
+ *
+ * Demos only have to set a custom device name and appearance, and their HID
+ * service.
+ */
+void initializeHOGP(BLE &ble);
+
\ No newline at end of file