BLE switch interface with 3 tact switches for micro:bit. It is intended for use with ios devices.

Dependencies:   microbit

Files at this revision

API Documentation at this revision

Comitter:
masakjm
Date:
Fri Feb 22 21:10:14 2019 +0000
Parent:
6:bd39b12d4ac8
Commit message:
1st release

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
microbit.lib Show annotated file Show diff for this revision Revisions of this file
microbit_switch_if_3sw.h Show diff for this revision Revisions of this file
microbit_switch_if_3sw.lib Show diff for this revision Revisions of this file
microbit_switch_if_joy.h Show annotated file Show diff for this revision Revisions of this file
readme.txt Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Jan 14 03:32:41 2019 +0000
+++ b/main.cpp	Fri Feb 22 21:10:14 2019 +0000
@@ -1,10 +1,10 @@
 //=================================
-// microbit_switch_if_3sw
+// microbit_switch_if_joy
 //=================================
-//    BLE switch interface with 3 tact switches or 3 touch sensors for micro:bit
+//    BLE switch interface with GROVE joystic for micro:bit
 //    It is intended for use with ios devices.
 //
-//    The MIT License (MIT)   Copyright (c) 2018 Masatomo Kojima
+//    The MIT License (MIT)   Copyright (c) 2019 Masatomo Kojima
 //
 //  LED message
 //    S  key code setting P1,P2
@@ -15,23 +15,31 @@
 //    E  Error at sending data by ble
 //    e  Error at writting data to flash memory
 //    I  Error by Incorrect cording
+//    G  GROVE sensor connect error
 //---------------------------------
 
-#define VERSION     "3SW-190114"
-//#define NO_DEBUG
+#define VERSION     "JOY-190218"
+#define NO_DEBUG
 
-#include "microbit_switch_if_3sw.h"
+#include "microbit_switch_if_joy.h"
 #include "KeyValueInt.h"
 
 //---------------------------------
 //  Display
 //---------------------------------
 MicroBitDisplay display;
-int state;                    // 状態遷移
-char dispChar = 0;            // LEDに表示する文字コード
-char dispCharLast = 0;        // 最後に表示した文字コード
-bool turnOffMode = false;     // LED非表示モードのフラグ
+int  State;                   // 状態遷移
+char DispChar  = 0;           // LEDに表示する文字コード
+char DispCharLast = 0;        // 最後に表示した文字コード
+bool TurnOffMode = false;     // LED非表示モードのフラグ
 
+//---------------------------------
+//  GROVE Joystick
+//---------------------------------
+
+AnalogIn AnalogP1(MICROBIT_PIN_P1);
+AnalogIn AnalogP2(MICROBIT_PIN_P2);
+    
 /** ----------
  * @brief 整数値をLEDに表示する
  * @param data 整数値
@@ -90,7 +98,6 @@
 bool setting_next;          // 次の設定値に移動
 
 KeyValueInt kviKeyCode1("keycode1",'S', 1, 1, NUM_GROUP1, true);
-KeyValueInt kviKeyCode2("keycode2",'T', 1, 1, NUM_GROUP2, true);
 
 /** ----------  
  * @brief   1つのパラメータの表示と変更
@@ -134,9 +141,7 @@
     MicroBitStorage storage;
 
     kviKeyCode1.set(FlashGet(storage, kviKeyCode1.key, 1));
-    kviKeyCode2.set(FlashGet(storage, kviKeyCode2.key, 1));
-    if(!paraSettingOne(storage, &kviKeyCode1, change)) return false;
-    return paraSettingOne(storage, &kviKeyCode2, change);
+    return paraSettingOne(storage, &kviKeyCode1, change);
 }
 //---------------------------------
 //  BLE & HID
@@ -286,14 +291,6 @@
 MicroBitButton buttonA(MICROBIT_PIN_BUTTON_A, MICROBIT_ID_BUTTON_A);
 MicroBitButton buttonB(MICROBIT_PIN_BUTTON_B, MICROBIT_ID_BUTTON_B);
 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);
-MicroBitPin P15(MICROBIT_ID_IO_P15, MICROBIT_PIN_P15, 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);
-MicroBitButton button15(MICROBIT_PIN_P15, MICROBIT_ID_IO_P15, MICROBIT_BUTTON_ALL_EVENTS, PullUp);
 
 /** ----------  
  * @brief  キーコードを送信する
@@ -305,13 +302,13 @@
         uint8_t modif = code >> 8;
 
         if (key > KEYMAP_SIZE ) {
-            dispChar ='I';      // キーコード設定間違い
+            DispChar  ='I';      // キーコード設定間違い
         } else {
             ble_error_t ret = kbdServicePtr->keyDownCode(key, modif);
-//                    DEBUG("  code=%d  modif=%d\r\n",key , modif);
+                    DEBUG("  code=%d  modif=%d\r\n",key , modif);
             if (ret) {
-                dispChar ='E';
-                dispCharLast =0;   // E が続く時に表示
+                DispChar  ='E';
+                DispCharLast =0;   // E が続く時に表示
                 DEBUG("(BLE)Error %d\r\n",ret);
             }
         }
@@ -325,7 +322,7 @@
 {
     if ((e.source == MICROBIT_ID_BUTTON_A && buttonB.isPressed()) ||
         (e.source == MICROBIT_ID_BUTTON_B && buttonA.isPressed()) ) {
-           dispChar = 'H';
+           DispChar  = 'H';
            sendKeyCode(keyCodeGroup0[2]);
      }
 }
@@ -336,9 +333,9 @@
  */
 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) {
+    switch (State) {
         case STATE_SETTING :
             switch(e.source) {
                 case MICROBIT_ID_BUTTON_A :
@@ -353,28 +350,19 @@
             int code = 0;
             switch(e.source) {
                 case MICROBIT_ID_BUTTON_A :
-                    dispChar = 'A';
+                    DispChar  = 'A';
                     code = keyCodeGroup0[0];
                     break;
                 case MICROBIT_ID_BUTTON_B :
-                    dispChar = 'B';
+                    DispChar  = 'B';
                     code = keyCodeGroup0[1];
                     break;
                 case MICROBIT_ID_IO_P0 :
-                    dispChar = '0';
-                    code = keyCodeGroup2[kviKeyCode2.value-1];
-                    break;
-                case MICROBIT_ID_IO_P1 :
-                    dispChar = '1';
-                    code = keyCodeGroup1[kviKeyCode1.value-1][0];
-                    break;
-                case MICROBIT_ID_IO_P2 :
-                case MICROBIT_ID_IO_P15 :
-                    dispChar = '2';
-                    code = keyCodeGroup1[kviKeyCode1.value-1][1];
+                    DispChar  = '0';
+                    code = keyCodeGroup1[kviKeyCode1.value-1][JOY_CENTER_PRESS];
                     break;
             }
-            sendKeyCode(code);
+            if (code != 0 )sendKeyCode(code);
     }
 }
 
@@ -385,38 +373,97 @@
 static void onButtonUp(MicroBitEvent e)
 {
 //    DEBUG("  Button up %d\r\n", e.source);
-    switch (state) {
+    switch (State) {
         case STATE_SETTING :
             if(setting_enter) setting_next = true;    // 決定ボタンを離したら次へ
             break;
         case STATE_OPERATING :
-            dispChar = 0;
+            DispChar  = 0;
             ble_error_t ret = kbdServicePtr->keyUpCode();
             if (ret) {
-                dispChar ='E';
-                dispCharLast =0;   // E が続く時に表示
+                DispChar  ='E';
+                DispCharLast =0;   // E が続く時に表示
             }
     }
 }
 
+
+/** ----------  
+ * @brief   ジョイスティックの接続をチェックする
+ * @return  false:接続エラー
+ */
+static bool checkJoy() 
+{
+    float joyX = AnalogP1.read();
+    float joyY = AnalogP2.read();
+
+    if (joyX < JOY_ERR_THRE) return false;       
+    if (joyY < JOY_ERR_THRE) return false;   
+
+    return true;
+}
+
+/** ----------  
+ * @brief   ジョイスティックの状態を返す
+ * @return  JOY_STATUS
+ */
+static JOY_STATUS readJoyStatus(JOY_STATUS last) 
+{
+    JOY_STATUS js = JOY_NEUTRAL;
+
+    float joyX = AnalogP1.read();
+    float joyY = AnalogP2.read();
+
+    if (joyX > JOY_CENTER_THRE) js = JOY_CENTER_PRESS;       
+    else {
+        if (joyX < JOY_LOW_THRE)  js = JOY_XLOW_PRESS;        
+        if (joyX > JOY_HIGH_THRE) js = JOY_XHIGH_PRESS;        
+        if (joyY < JOY_LOW_THRE)  js = JOY_YLOW_PRESS;        
+        if (joyY > JOY_HIGH_THRE) js = JOY_YHIGH_PRESS;        
+    }
+             
+//    DEBUG("%d, %f, %f\r\n", js, joyX, joyY);
+    return js;
+}
+
+static void joyAction(JOY_STATUS last, JOY_STATUS now) 
+{
+    int code = 0;
+//   DEBUG("%d, %d\r\n", now, last);
+            
+    if( now != last){              
+        if(now == JOY_NEUTRAL) {
+            DispChar  = 0;
+            ble_error_t ret = kbdServicePtr->keyUpCode();
+            if (ret) {
+                DispChar  ='E';
+                DispCharLast =0;   // E が続く時に表示
+            }
+        } else {
+            DispChar  = '0' + now;
+            code = keyCodeGroup1[kviKeyCode1.value-1][now];
+        }
+        if (code != 0 )sendKeyCode(code);
+    }
+}
 //---------------------------------
 //  Main
 //---------------------------------
 int main()
 {
-    state = STATE_DESABLE_INPUT;
+    State = STATE_DESABLE_INPUT;
 
     wait(0.1);           // ボタン状態の更新
     bool bA = buttonA.isPressed();
     bool bB = buttonB.isPressed();
 
     if (bA && bB) {     // ボタンABを押しながら起動
-        for(int i=0;i<3;i++) {
+        for(int i=0;i<2;i++) {
             display.scroll(VERSION);
             wait(0.5);
         }
     } else if(bA)       // ボタンAを押しながら起動
-        state = STATE_SETTING;
+        State = STATE_SETTING;
 
 //----- Display
     display.setDisplayMode(DISPLAY_MODE_BLACK_AND_WHITE);
@@ -429,43 +476,61 @@
     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.
+
+//----- 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);
+
+    // Put the P0 pins into touch sense mode.
     P0.isTouched();
-    P1.isTouched();
-    P2.isTouched();
 
+//----- Joystick
+    JOY_STATUS joyStatus;
+    JOY_STATUS joyStatusLast = JOY_NEUTRAL;
+    while (!checkJoy())  {
+        DispChar  ='G';
+        display.printChar(DispChar );
+        wait(1);
+    }   
+    
 //----- Setting
-    if (paraSetting(state == STATE_SETTING)) dispChar =0;
-    else                                     dispChar ='e';   
+    if (paraSetting(State == STATE_SETTING)) DispChar  =0;
+    else                                     DispChar  ='e';   
 
 //----- BLE & HID
-    state = STATE_DESABLE_INPUT;
+    State = STATE_DESABLE_INPUT;
     initialize_BLE_HID();
     display.clear();
 
 //----- Loop
-    state = STATE_OPERATING;
+    State = STATE_OPERATING;
     while (true) {
         ble.waitForEvent();        // BLEイベントを待つ
 
+        joyStatus = readJoyStatus(joyStatusLast);  // Joystick の状態を読む
+        joyAction(joyStatusLast, joyStatus);
+        joyStatusLast = joyStatus;      
+
         if(bleMessage != BLE_NO_MESSAGE) {    // BLEの状態を表示する
-            dispChar = bleDispChar[bleMessage];
+            DispChar  = bleDispChar[bleMessage];
             bleMessage = BLE_NO_MESSAGE;    
         }
 
-        if (dispChar != dispCharLast) {  // 表示文字が変更
-            turnOffMode = false;
+        if (DispChar  != DispCharLast) {  // 表示文字が変更
+            TurnOffMode = false;
             dispTime.reset();
             display.enable(); 
-            if (dispChar) display.printChar(dispChar);
+            if (DispChar ) display.printChar(DispChar );
             else          display.clear();
         }
-        if (!turnOffMode) {
+        if (!TurnOffMode) {
             if (dispTime.read() > TIME_TURN_OFF) {  // 長時間表示
-                turnOffMode = true;
+                TurnOffMode = true;
                 display.disable();
             }
         }
-        dispCharLast = dispChar;
+        
+        DispCharLast = DispChar ;
     }
 }
--- a/microbit.lib	Mon Jan 14 03:32:41 2019 +0000
+++ b/microbit.lib	Fri Feb 22 21:10:14 2019 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/teams/Lancaster-University/code/microbit/#4b89e7e3494f
+https://os.mbed.com/teams/Lancaster-University/code/microbit/#5a5ed1a7ec49
--- a/microbit_switch_if_3sw.h	Mon Jan 14 03:32:41 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,153 +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         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/microbit_switch_if_3sw.lib	Mon Jan 14 03:32:41 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/users/masakjm/code/microbit_switch_if_3sw/#80cb8f9db01e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/microbit_switch_if_joy.h	Fri Feb 22 21:10:14 2019 +0000
@@ -0,0 +1,172 @@
+//=================================
+// microbit_switch_if_joy
+//=================================
+//    BLE switch interface with GROVE joystic for micro:bit
+//    The MIT License (MIT)   Copyright (c) 2019 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"
+
+//----------------------
+//  GROVE JoyStick
+//----------------------
+#define JOY_ERR_THRE     0.4   // JoyStick 異常入力の閾値
+#define JOY_LOW_THRE     0.35  // JoyStick 入力値の低い側の閾値
+#define JOY_HIGH_THRE    0.65  // JoyStick 入力値の高い側の閾値
+#define JOY_CENTER_THRE  0.90  // JoyStick の押しスイッチの閾値
+enum JOY_STATUS {
+    JOY_NEUTRAL = -1,
+    JOY_CENTER_PRESS ,   // 中央
+    JOY_YHIGH_PRESS,    // 左
+    JOY_YLOW_PRESS,     // 右
+    JOY_XHIGH_PRESS,    // 上
+    JOY_XLOW_PRESS,     // 下
+};
+
+//----------------------
+//  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 */
+
+const int KEY_NUMPAD0 = 0x60; /* Numpad 0 */
+const int KEY_NUMPAD1 = 0x61; /* Numpad 1 */
+const int KEY_NUMPAD2 = 0x62; /* Numpad 2 */
+const int KEY_NUMPAD3 = 0x63; /* Numpad 3 */
+const int KEY_NUMPAD4 = 0x64; /* Numpad 4 */
+const int KEY_NUMPAD5 = 0x65; /* Numpad 5 */
+const int KEY_NUMPAD6 = 0x66; /* Numpad 6 */
+const int KEY_NUMPAD7 = 0x67; /* Numpad 7 */
+const int KEY_NUMPAD8 = 0x68; /* Numpad 8 */
+const int KEY_NUMPAD9 = 0x69; /* Numpad 9 */
+
+//----------------------
+//  Setting
+//----------------------
+#define NUM_GROUP1         4
+#define NUM_G1MEMBER       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][NUM_G1MEMBER] = { // 中央 左 右 上 下
+    {KEY_ENTER,   KEY_TAB,     KEY_SPACE,   0,           KEY_ENTER  },
+    {KEY_HOME,    RIGHT_ARROW, LEFT_ARROW,  DOWN_ARROW,  UP_ARROW   },
+    {KEY_NUMPAD1, KEY_NUMPAD2, KEY_NUMPAD3, KEY_NUMPAD4, KEY_NUMPAD5},
+    {KEY_ENTER,   MODIFY_OPTION+MODIFY_SHIFT+KEY_TAB, MODIFY_OPTION+KEY_TAB,
+                  MODIFY_OPTION+DOWN_ARROW, MODIFY_OPTION+UP_ARROW},
+//    {KEY_ENTER,   MODIFY_SHIFT+KEY_TAB, KEY_TAB, KEY_SPACE, MODIFY_SHIFT+KEY_SPACE},
+};
+
+//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	Mon Jan 14 03:32:41 2019 +0000
+++ b/readme.txt	Fri Feb 22 21:10:14 2019 +0000
@@ -1,25 +1,24 @@
 //=================================
-// microbit_switch_if_3sw
+// microbit_switch_if_joy
 //=================================
-//    BLE switch interface with 3 tact switches for micro:bit
+//    BLE switch interface with GROVE joystic for micro:bit
 //    It is intended for use with ios devices.
 //
 //    The MIT License (MIT)   Copyright (c) 2019 Masatomo Kojima
 //
 //  LED message
-//    S  key code setting P1, P2
-//    T  key code setting P0
+//    S  key code setting 
 //    C  Conected
 //    P  success Pearing
 //    F  Fail pearing
 //    E  Error at sending data by ble
 //    e  Error at writting data to flash memory
 //    I  Error by Incorrect cording
+//    G  GROVE sensor connect error
 //
 //  Please refer to the following site. (Japanese only)
-//     http://mahoro-ba.net/e2036.html
-//     http://mahoro-ba.net/e2039.html
-//     http://mahoro-ba.net/e2065.html
+//   http://mahoro-ba.net/files/workshop_text_switch_if_103.pdf
+//   http://mahoro-ba.net/files/workshop_text_switch_if_301.pdf
 //
 //  I refer to information written on the following sites.
 //    (1)https://os.mbed.com/teams/microbit/code/microbit_presenter/
@@ -31,10 +30,5 @@
 //
 
 Version
-3SW-180917  初版リリース
-3SW-180922  軽微な修正
-3SW-181125  "makey makey" style touch sensor に対応
-            ボタンA:RIGHT_ARROW ボタンB:LEFT_ARROW に変更
-3SW-190114  P1とP2のコード設定をSの値で、P0のコード設定をTの値でするように変更
-       P15は、P2と同じ動作
+JOY-190223  初版リリース(3SW-190215から派生)
             
\ No newline at end of file