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.
Revision 4:4fe5674bf409, committed 2018-11-25
- Comitter:
- masakjm
- Date:
- Sun Nov 25 04:41:15 2018 +0000
- Parent:
- 3:b6e9850d3e76
- Child:
- 5:80cb8f9db01e
- Commit message:
- 3SW-181125 "makey makey" style touch sensor ???; ???A?RIGHT_ARROW ???B?LEFT_ARROW ???
Changed in this revision
--- a/main.cpp Sat Sep 22 00:31:39 2018 +0000
+++ b/main.cpp Sun Nov 25 04:41:15 2018 +0000
@@ -1,7 +1,7 @@
//=================================
// microbit_switch_if_3sw
//=================================
-// BLE switch interface with 3 tact switches for micro:bit
+// BLE switch interface with 3 tact switches or 3 touch sensors for micro:bit
// It is intended for use with ios devices.
//
// The MIT License (MIT) Copyright (c) 2018 Masatomo Kojima
@@ -15,25 +15,12 @@
// E Error at sending data by ble
// e Error at writting data to flash memory
// I Error by Incorrect cording
-//
-// Please refer to the following site. (Japanese only)
-// http://mahoro-ba.net/e2036.html
-// http://mahoro-ba.net/e2038.html
-//
-// I refer to information written on the following sites.
-// (1)https://os.mbed.com/teams/microbit/code/microbit_presenter/
-// Licensed under the Apache License, Version 2.0
-//
-// (2)https://lancaster-university.github.io/microbit-docs/
-// The MIT License (MIT)
-// Copyright (c) 2016 British Broadcasting Corporation.
-//
//---------------------------------
-#define VERSION "3SW-180922"
+#define VERSION "3SW-181125"
//#define NO_DEBUG
-#include "microbit_switch_if.h"
+#include "microbit_switch_if_3sw.h"
#include "KeyValueInt.h"
//---------------------------------
@@ -298,9 +285,13 @@
MicroBitMessageBus bus;
MicroBitButton buttonA(MICROBIT_PIN_BUTTON_A, MICROBIT_ID_BUTTON_A);
MicroBitButton buttonB(MICROBIT_PIN_BUTTON_B, MICROBIT_ID_BUTTON_B);
-MicroBitButton button0(MICROBIT_PIN_P0, MICROBIT_ID_IO_P0, MICROBIT_BUTTON_ALL_EVENTS, PullUp);
-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);
+MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_ALL);
+MicroBitPin P1(MICROBIT_ID_IO_P1, MICROBIT_PIN_P1, PIN_CAPABILITY_ALL);
+MicroBitPin P2(MICROBIT_ID_IO_P2, MICROBIT_PIN_P2, PIN_CAPABILITY_ALL);
+
+//MicroBitButton button0(MICROBIT_PIN_P0, MICROBIT_ID_IO_P0, MICROBIT_BUTTON_ALL_EVENTS, PullUp);
+//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);
/** ----------
* @brief キーコードを送信する
@@ -343,7 +334,7 @@
*/
static void onButtonDown(MicroBitEvent e)
{
-// DEBUG(" Button Down %d state=%d\r\n", e.source, state);
+// DEBUG(" Button Down %d state=%d\r\n", e.source, state);
switch (state) {
case STATE_SETTING :
@@ -435,6 +426,11 @@
bus.listen(MICROBIT_ID_ANY, MICROBIT_BUTTON_EVT_UP, onButtonUp);
bus.listen(MICROBIT_ID_ANY, MICROBIT_BUTTON_EVT_HOLD, onButtonHold);
+ // Put the P0, P1 and P2 pins into touch sense mode.
+ P0.isTouched();
+ P1.isTouched();
+ P2.isTouched();
+
//----- Setting
if (paraSetting(state == STATE_SETTING)) dispChar =0;
else dispChar ='e';
--- a/microbit_switch_if.h Sat Sep 22 00:31:39 2018 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +0,0 @@
-//=================================
-// 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 int KEY_BS = 8; /* Keyboard Backspace */
-const int KEY_TAB = 9; /* Keyboard Tab */
-const int KEY_ENTER = 10; /* Keyboard Return (Enter) */
-//const int KEY_ESC = 27; /* Keyboard Escape */
-const int KEY_SPACE = 32; /* Keyboard Space */
-
-//----------------------
-// Setting
-//----------------------
-#define NUM_GROUP1 6
-#define NUM_GROUP2 5
-
-#define MODIFY_CTRL 0x100
-#define MODIFY_SHIFT 0x200
-#define MODIFY_OPTION 0x400 /* option or alt */
-#define MODIFY_COMMAND 0x800 /* command or Windows */
-
-const int keyCodeGroup0[3] = { // Button A, Button B, Button A&B
- 'A',
- 'B',
- MODIFY_COMMAND + 'h' // アプリ終了
-};
-const int keyCodeGroup1[NUM_GROUP1][2] = { // Switch 1 2
- {KEY_SPACE, KEY_ENTER},
- {RIGHT_ARROW, LEFT_ARROW},
- {DOWN_ARROW, UP_ARROW},
- {MODIFY_OPTION + DOWN_ARROW, MODIFY_OPTION + UP_ARROW},
- {'1', '3'},
- {'h', 'j'}
-};
-const int keyCodeGroup2[NUM_GROUP2]= { // Switch 3
- KEY_TAB,
- RIGHT_ARROW,
- LEFT_ARROW,
- MODIFY_COMMAND + 'r', // 再読み込み
- MODIFY_OPTION + DOWN_ARROW
-};
-
-//in "BLE_HID\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
-//----------------------
-enum STATE {
- STATE_DESABLE_INPUT, // 入力無効時
- STATE_SETTING, // パラメータ設定時
- STATE_OPERATING, // 操作時
-};
-//----------------------
-// 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);
-
-enum BLE_MESSAGE {
- BLE_NO_MESSAGE, // メッセージ無し
- BLE_CONNECTED, // BLE接続完了
- BLE_PAIRING_SUCCESS, // ペアリング成功
- BLE_PAIRING_FAILED, // ペアリング失敗
-};
-
-const char bleDispChar[]={0, 'C', 'P', 'F'};
-
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/microbit_switch_if_3sw.h Sun Nov 25 04:41:15 2018 +0000
@@ -0,0 +1,153 @@
+//=================================
+// 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 int KEY_BS = 8; /* Keyboard Backspace */
+const int KEY_TAB = 9; /* Keyboard Tab */
+const int KEY_ENTER = 10; /* Keyboard Return (Enter) */
+//const int KEY_ESC = 27; /* Keyboard Escape */
+const int KEY_SPACE = 32; /* Keyboard Space */
+
+//----------------------
+// Setting
+//----------------------
+#define NUM_GROUP1 6
+#define NUM_GROUP2 6
+
+#define MODIFY_CTRL 0x100
+#define MODIFY_SHIFT 0x200
+#define MODIFY_OPTION 0x400 /* option or alt */
+#define MODIFY_COMMAND 0x800 /* command or Windows */
+
+const int keyCodeGroup0[3] = { // Button A, Button B, Button A&B
+ RIGHT_ARROW,
+ LEFT_ARROW,
+ MODIFY_COMMAND + 'h' // アプリ終了
+};
+const int keyCodeGroup1[NUM_GROUP1][2] = { // Switch 1 2
+ {KEY_SPACE, KEY_ENTER},
+ {RIGHT_ARROW, LEFT_ARROW},
+ {DOWN_ARROW, UP_ARROW},
+ {MODIFY_OPTION + DOWN_ARROW, MODIFY_OPTION + UP_ARROW},
+ {'1', '3'},
+ {'h', 'j'}
+};
+const int keyCodeGroup2[NUM_GROUP2]= { // Switch 3
+ KEY_TAB,
+ 0,
+ 0,
+ MODIFY_COMMAND + 'r', // 再読み込み
+ 0,
+ 0
+};
+
+//in "BLE_HID\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
+//----------------------
+enum STATE {
+ STATE_DESABLE_INPUT, // 入力無効時
+ STATE_SETTING, // パラメータ設定時
+ STATE_OPERATING, // 操作時
+};
+//----------------------
+// 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);
+
+enum BLE_MESSAGE {
+ BLE_NO_MESSAGE, // メッセージ無し
+ BLE_CONNECTED, // BLE接続完了
+ BLE_PAIRING_SUCCESS, // ペアリング成功
+ BLE_PAIRING_FAILED, // ペアリング失敗
+};
+
+const char bleDispChar[]={0, 'C', 'P', 'F'};
+
\ No newline at end of file
--- a/readme.txt Sat Sep 22 00:31:39 2018 +0000 +++ b/readme.txt Sun Nov 25 04:41:15 2018 +0000 @@ -30,5 +30,8 @@ // Version -3SW-180917 初期リリース - +3SW-180917 初版リリース +3SW-180922 軽微な修正 +3SW-181125 "makey makey" style touch sensor に対応 + ボタンA:RIGHT_ARROW ボタンB:LEFT_ARROW に変更 + \ No newline at end of file