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: main.cpp
- Revision:
- 1:3b9ae1dbcdcf
- Parent:
- 0:28fb3e9ef81a
- Child:
- 3:b6e9850d3e76
diff -r 28fb3e9ef81a -r 3b9ae1dbcdcf main.cpp
--- a/main.cpp Mon Sep 17 02:48:51 2018 +0000
+++ b/main.cpp Mon Sep 17 06:27:25 2018 +0000
@@ -284,11 +284,38 @@
MicroBitButton button1(MICROBIT_PIN_P1, MICROBIT_ID_IO_P1, MICROBIT_BUTTON_ALL_EVENTS, PullUp);
MicroBitButton button2(MICROBIT_PIN_P2, MICROBIT_ID_IO_P2, MICROBIT_BUTTON_ALL_EVENTS, PullUp);
+static void sendKeyCode(int code) {
+ if (code) {
+ uint8_t key = code & 0xff;
+ uint8_t modif = code >> 8;
+
+ if (key > KEYMAP_SIZE ) {
+ dispChar ='I'; // キーコード設定間違い
+ } else {
+ ble_error_t ret = kbdServicePtr->keyDownCode(key, modif);
+// DEBUG(" code=%d modif=%d\r\n",key , modif);
+ if (ret) {
+ dispChar ='E';
+ dispCharLast =0; // E が続く時に表示
+ DEBUG("(BLE)Error %d\r\n",ret);
+ }
+ }
+ }
+}
+//----- ボタン保持時イベント
+static void onButtonHold(MicroBitEvent e)
+{
+ if ((e.source == MICROBIT_ID_BUTTON_A && buttonB.isPressed()) ||
+ (e.source == MICROBIT_ID_BUTTON_B && buttonA.isPressed()) ) {
+ dispChar = 'H';
+ sendKeyCode(keyCodeGroup0[2]);
+ }
+}
+
//----- ボタン押下げ時イベント
static void onButtonDown(MicroBitEvent e)
{
// DEBUG(" Button Down %d state=%d\r\n", e.source, state);
- int code = 0;
switch (state) {
case STATE_SETTING :
@@ -302,6 +329,7 @@
}
break;
case STATE_OPERATING :
+ int code = 0;
switch(e.source) {
case MICROBIT_ID_BUTTON_A :
dispChar = 'A';
@@ -324,23 +352,7 @@
code = keyCodeGroup2[kviKeyCode2.value-1];
break;
}
-
- if (code) {
- uint8_t key = code & 0xff;
- uint8_t modif = code >> 8;
-
- if (key > KEYMAP_SIZE ) {
- dispChar ='I'; // キーコード設定間違い
- } else {
- ble_error_t ret = kbdServicePtr->keyDownCode(key, modif);
-// DEBUG(" code=%d modif=%d\r\n",key , modif);
- if (ret) {
- dispChar ='E';
- dispCharLast =0; // E が続く時に表示
- DEBUG("(BLE)Error %d\r\n",ret);
- }
- }
- }
+ sendKeyCode(code);
}
}
@@ -390,6 +402,7 @@
//----- Button
bus.listen(MICROBIT_ID_ANY, MICROBIT_BUTTON_EVT_DOWN, onButtonDown);
bus.listen(MICROBIT_ID_ANY, MICROBIT_BUTTON_EVT_UP, onButtonUp);
+ bus.listen(MICROBIT_ID_ANY, MICROBIT_BUTTON_EVT_HOLD, onButtonHold);
//----- Setting
paraSetting(state == STATE_SETTING);