add programs

Dependencies:   mbed USBDevice

Committer:
yabutakefu
Date:
Wed May 01 05:37:42 2019 +0000
Revision:
1:05875edbf215
Parent:
0:965ed9ce2a09
test commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yabutakefu 0:965ed9ce2a09 1 #include "keyboardJP53.h"
yabutakefu 0:965ed9ce2a09 2
yabutakefu 0:965ed9ce2a09 3 /*
yabutakefu 0:965ed9ce2a09 4 試作版キーボード 日本語53キー版 クラス
yabutakefu 0:965ed9ce2a09 5 */
yabutakefu 0:965ed9ce2a09 6
yabutakefu 0:965ed9ce2a09 7 keyboardJP53::keyboardJP53()
yabutakefu 0:965ed9ce2a09 8 {
yabutakefu 0:965ed9ce2a09 9 //行*列毎にキーコードを指定してkeyboardButtonを定義する
yabutakefu 0:965ed9ce2a09 10 //[参考URL] http://www2d.biglobe.ne.jp/~msyk/keyboard/layout/usbkeycode.html
yabutakefu 0:965ed9ce2a09 11 _map[0][0] = new keyboardButton( 1, false); //半角/全角
yabutakefu 0:965ed9ce2a09 12 _map[0][1] = new keyboardButton(110, false); //ESC
yabutakefu 0:965ed9ce2a09 13 _map[0][2] = new keyboardButton( 17, false); //Q
yabutakefu 0:965ed9ce2a09 14 _map[0][3] = new keyboardButton( 18, false); //W
yabutakefu 0:965ed9ce2a09 15 _map[0][4] = new keyboardButton( 19, false); //E
yabutakefu 0:965ed9ce2a09 16 _map[0][5] = new keyboardButton( 20, false); //R
yabutakefu 0:965ed9ce2a09 17 _map[0][6] = new keyboardButton( 21, false); //T
yabutakefu 0:965ed9ce2a09 18 _map[0][7] = NULL;
yabutakefu 0:965ed9ce2a09 19
yabutakefu 0:965ed9ce2a09 20 _map[1][0] = new keyboardButton(22, false); //Y
yabutakefu 0:965ed9ce2a09 21 _map[1][1] = new keyboardButton(23, false); //U
yabutakefu 0:965ed9ce2a09 22 _map[1][2] = new keyboardButton(24, false); //I
yabutakefu 0:965ed9ce2a09 23 _map[1][3] = new keyboardButton(25, false); //O
yabutakefu 0:965ed9ce2a09 24 _map[1][4] = new keyboardButton(26, false); //P
yabutakefu 0:965ed9ce2a09 25 _map[1][5] = new keyboardButton(12, false); //-
yabutakefu 0:965ed9ce2a09 26 _map[1][6] = new keyboardButton(15, false); //BackSpace
yabutakefu 0:965ed9ce2a09 27 _map[1][7] = NULL;
yabutakefu 0:965ed9ce2a09 28
yabutakefu 0:965ed9ce2a09 29 _map[2][0] = new keyboardButton(16, false); //TAB
yabutakefu 0:965ed9ce2a09 30 _map[2][1] = new keyboardButton(31, false); //A
yabutakefu 0:965ed9ce2a09 31 _map[2][2] = new keyboardButton(32, false); //S
yabutakefu 0:965ed9ce2a09 32 _map[2][3] = new keyboardButton(33, false); //D
yabutakefu 0:965ed9ce2a09 33 _map[2][4] = new keyboardButton(34, false); //F
yabutakefu 0:965ed9ce2a09 34 _map[2][5] = new keyboardButton(35, false); //G
yabutakefu 0:965ed9ce2a09 35 _map[2][6] = new keyboardButton(36, false); //H
yabutakefu 0:965ed9ce2a09 36 _map[2][7] = NULL;
yabutakefu 0:965ed9ce2a09 37
yabutakefu 0:965ed9ce2a09 38 _map[3][0] = new keyboardButton(37, false); //J
yabutakefu 0:965ed9ce2a09 39 _map[3][1] = new keyboardButton(38, false); //K
yabutakefu 0:965ed9ce2a09 40 _map[3][2] = new keyboardButton(39, false); //L
yabutakefu 0:965ed9ce2a09 41 _map[3][3] = new keyboardButton(27, false); //@
yabutakefu 0:965ed9ce2a09 42 _map[3][4] = new keyboardButton(28, false); //[
yabutakefu 0:965ed9ce2a09 43 _map[3][5] = new keyboardButton(13, false); //^
yabutakefu 0:965ed9ce2a09 44 _map[3][6] = new keyboardButton(14, false); //¥
yabutakefu 0:965ed9ce2a09 45 _map[3][7] = NULL;
yabutakefu 0:965ed9ce2a09 46
yabutakefu 0:965ed9ce2a09 47 _map[4][0] = new keyboardButton(0xFF, false); //Func(キーボード内で利用するだけでそのままキーコードを送信しない)
yabutakefu 0:965ed9ce2a09 48 _map[4][1] = new keyboardButton(46, false); //Z
yabutakefu 0:965ed9ce2a09 49 _map[4][2] = new keyboardButton(47, false); //X
yabutakefu 0:965ed9ce2a09 50 _map[4][3] = new keyboardButton(48, false); //C
yabutakefu 0:965ed9ce2a09 51 _map[4][4] = new keyboardButton(49, false); //V
yabutakefu 0:965ed9ce2a09 52 _map[4][5] = new keyboardButton(50, false); //B
yabutakefu 0:965ed9ce2a09 53 _map[4][6] = new keyboardButton(51, false); //N
yabutakefu 0:965ed9ce2a09 54 _map[4][7] = NULL;
yabutakefu 0:965ed9ce2a09 55
yabutakefu 0:965ed9ce2a09 56 _map[5][0] = new keyboardButton(52, false); //M
yabutakefu 0:965ed9ce2a09 57 _map[5][1] = new keyboardButton(40, false); //;
yabutakefu 0:965ed9ce2a09 58 _map[5][2] = new keyboardButton(41, false); //:
yabutakefu 0:965ed9ce2a09 59 _map[5][3] = new keyboardButton(83, false); //↑
yabutakefu 0:965ed9ce2a09 60 _map[5][4] = new keyboardButton(42, false); //]
yabutakefu 0:965ed9ce2a09 61 _map[5][5] = new keyboardButton(55, false); ///
yabutakefu 0:965ed9ce2a09 62 _map[5][6] = new keyboardButton(43, false); //Enter
yabutakefu 0:965ed9ce2a09 63 _map[5][7] = NULL;
yabutakefu 0:965ed9ce2a09 64
yabutakefu 0:965ed9ce2a09 65 _map[6][0] = NULL;
yabutakefu 0:965ed9ce2a09 66 _map[6][1] = new keyboardButton(44, false); //L-SHIFT
yabutakefu 0:965ed9ce2a09 67 _map[6][2] = new keyboardButton(58, false); //Ctlr
yabutakefu 0:965ed9ce2a09 68 _map[6][3] = new keyboardButton(60, false); //L-Alt
yabutakefu 0:965ed9ce2a09 69 _map[6][4] = new keyboardButton(131, false); //無変換
yabutakefu 0:965ed9ce2a09 70 _map[6][5] = new keyboardButton(61, false); //スペース
yabutakefu 0:965ed9ce2a09 71 _map[6][6] = NULL;
yabutakefu 0:965ed9ce2a09 72 _map[6][7] = NULL;
yabutakefu 0:965ed9ce2a09 73
yabutakefu 0:965ed9ce2a09 74 _map[7][0] = new keyboardButton(53, false); //,
yabutakefu 0:965ed9ce2a09 75 _map[7][1] = new keyboardButton(54, false); //.
yabutakefu 0:965ed9ce2a09 76 _map[7][2] = new keyboardButton(79, false); //←
yabutakefu 0:965ed9ce2a09 77 _map[7][3] = new keyboardButton(84, false); //↓
yabutakefu 0:965ed9ce2a09 78 _map[7][4] = new keyboardButton(89, false); //→
yabutakefu 0:965ed9ce2a09 79 _map[7][5] = new keyboardButton(57, false); //R-SHIFT
yabutakefu 0:965ed9ce2a09 80 _map[7][6] = NULL;
yabutakefu 0:965ed9ce2a09 81 _map[7][7] = NULL;
yabutakefu 0:965ed9ce2a09 82
yabutakefu 0:965ed9ce2a09 83 //全てのキーボタンを未押下状態&スキャン回数を初期化する
yabutakefu 0:965ed9ce2a09 84 reset();
yabutakefu 0:965ed9ce2a09 85 }
yabutakefu 0:965ed9ce2a09 86
yabutakefu 0:965ed9ce2a09 87
yabutakefu 0:965ed9ce2a09 88 keyboardJP53::~keyboardJP53()
yabutakefu 0:965ed9ce2a09 89 {
yabutakefu 0:965ed9ce2a09 90 //newしたkeyboardButtonをdeleteする
yabutakefu 0:965ed9ce2a09 91 for (int _row = 0; _row < KEYBORAD_JP53_ROW; _row++) {
yabutakefu 0:965ed9ce2a09 92 for (int _col = 0; _col < KEYBORAD_JP53_ROW; _col++) {
yabutakefu 0:965ed9ce2a09 93 if (NULL != _map[_row][_col]) {
yabutakefu 0:965ed9ce2a09 94 delete _map[_row][_col];
yabutakefu 0:965ed9ce2a09 95 }
yabutakefu 0:965ed9ce2a09 96 }
yabutakefu 0:965ed9ce2a09 97 }
yabutakefu 0:965ed9ce2a09 98 }
yabutakefu 0:965ed9ce2a09 99
yabutakefu 0:965ed9ce2a09 100
yabutakefu 0:965ed9ce2a09 101
yabutakefu 0:965ed9ce2a09 102 //全てのキーボタンを未押下状態&スキャン回数を初期化する
yabutakefu 0:965ed9ce2a09 103 void keyboardJP53::reset()
yabutakefu 0:965ed9ce2a09 104 {
yabutakefu 0:965ed9ce2a09 105 _scan = 0;
yabutakefu 0:965ed9ce2a09 106
yabutakefu 0:965ed9ce2a09 107 for (int temp = 0; temp < KEYBORAD_JP53_MAX_SCAN; temp++) {
yabutakefu 0:965ed9ce2a09 108 for (int _row = 0; _row < KEYBORAD_JP53_ROW; _row++) {
yabutakefu 0:965ed9ce2a09 109 for (int _col = 0; _col < KEYBORAD_JP53_ROW; _col++) {
yabutakefu 0:965ed9ce2a09 110 _status[temp][_row][_col] = false;
yabutakefu 0:965ed9ce2a09 111 }
yabutakefu 0:965ed9ce2a09 112 }
yabutakefu 0:965ed9ce2a09 113 }
yabutakefu 0:965ed9ce2a09 114 }
yabutakefu 0:965ed9ce2a09 115
yabutakefu 0:965ed9ce2a09 116 //現在のスキャン回数を取得する
yabutakefu 0:965ed9ce2a09 117 int keyboardJP53::scan() {
yabutakefu 0:965ed9ce2a09 118 return _scan;
yabutakefu 0:965ed9ce2a09 119 }
yabutakefu 0:965ed9ce2a09 120
yabutakefu 0:965ed9ce2a09 121 //最大スキャン回数を取得する
yabutakefu 0:965ed9ce2a09 122 int keyboardJP53::max() {
yabutakefu 0:965ed9ce2a09 123 return KEYBORAD_JP53_MAX_SCAN;
yabutakefu 0:965ed9ce2a09 124 }
yabutakefu 0:965ed9ce2a09 125
yabutakefu 0:965ed9ce2a09 126
yabutakefu 0:965ed9ce2a09 127 //指定RowへのCol値をスキャンする
yabutakefu 0:965ed9ce2a09 128 //--row : 更新対象row値
yabutakefu 0:965ed9ce2a09 129 //--value: col7,col6,col5,col4,col3,col2,col1,col0
yabutakefu 0:965ed9ce2a09 130 void keyboardJP53::scanRow(int row, unsigned char value) {
yabutakefu 0:965ed9ce2a09 131
yabutakefu 0:965ed9ce2a09 132 //valueをstd:bitsetへ変換
yabutakefu 0:965ed9ce2a09 133 std::bitset<8> bsValue(value);
yabutakefu 0:965ed9ce2a09 134
yabutakefu 0:965ed9ce2a09 135 for ( int i=0;i<=7;i++){
yabutakefu 0:965ed9ce2a09 136 _status[_scan][row][i] = bsValue[i];
yabutakefu 0:965ed9ce2a09 137 }
yabutakefu 0:965ed9ce2a09 138 }
yabutakefu 0:965ed9ce2a09 139
yabutakefu 0:965ed9ce2a09 140
yabutakefu 0:965ed9ce2a09 141 //スキャン回数をインクリメントする
yabutakefu 0:965ed9ce2a09 142 void keyboardJP53::nextScan() {
yabutakefu 0:965ed9ce2a09 143 _scan++;
yabutakefu 0:965ed9ce2a09 144 if (_scan >= KEYBORAD_JP53_MAX_SCAN) {
yabutakefu 0:965ed9ce2a09 145 _scan = 1;
yabutakefu 0:965ed9ce2a09 146 }
yabutakefu 0:965ed9ce2a09 147 }
yabutakefu 0:965ed9ce2a09 148
yabutakefu 0:965ed9ce2a09 149 //スキャン結果を元にキーボード押下/未押下状態を更新する
yabutakefu 0:965ed9ce2a09 150 void keyboardJP53::update(std::vector<keyboardButton>& newPressedButton, std::vector<keyboardButton>& newReleasedButton) {
yabutakefu 0:965ed9ce2a09 151 bool pressed;
yabutakefu 0:965ed9ce2a09 152 keyboardButton *button;
yabutakefu 0:965ed9ce2a09 153
yabutakefu 0:965ed9ce2a09 154 //_newPressedButton,_newReleasedButtonを初期化する
yabutakefu 0:965ed9ce2a09 155 newPressedButton.clear();
yabutakefu 0:965ed9ce2a09 156 newReleasedButton.clear();
yabutakefu 0:965ed9ce2a09 157
yabutakefu 0:965ed9ce2a09 158 for (int _row = 0; _row < KEYBORAD_JP53_ROW; _row++) {
yabutakefu 0:965ed9ce2a09 159 for (int _col = 0; _col < KEYBORAD_JP53_ROW; _col++) {
yabutakefu 0:965ed9ce2a09 160
yabutakefu 0:965ed9ce2a09 161 //スキャン回数が全てTrueなら押下状態 1つでもfalseなら未押下状態とする
yabutakefu 0:965ed9ce2a09 162 pressed = true;
yabutakefu 0:965ed9ce2a09 163 for (int temp = 0; temp < KEYBORAD_JP53_MAX_SCAN; temp++) {
yabutakefu 0:965ed9ce2a09 164 pressed = pressed && _status[temp][_row][_col];
yabutakefu 0:965ed9ce2a09 165 }
yabutakefu 0:965ed9ce2a09 166
yabutakefu 0:965ed9ce2a09 167 button = _map[_row][_col];
yabutakefu 0:965ed9ce2a09 168 //未定義であればコピー処理をスルー
yabutakefu 0:965ed9ce2a09 169 if (button == NULL) {
yabutakefu 0:965ed9ce2a09 170 continue;
yabutakefu 0:965ed9ce2a09 171 }
yabutakefu 0:965ed9ce2a09 172
yabutakefu 0:965ed9ce2a09 173 //新規に押下されたキーボードボタンに当該ボタンをコピー
yabutakefu 0:965ed9ce2a09 174 if ((pressed) && (not button->press())) {
yabutakefu 0:965ed9ce2a09 175 newPressedButton.push_back(*button);
yabutakefu 0:965ed9ce2a09 176 button->set(true);
yabutakefu 0:965ed9ce2a09 177 }
yabutakefu 0:965ed9ce2a09 178
yabutakefu 0:965ed9ce2a09 179 //新規に未押下されたキーボードボタンに当該ボタンをコピー
yabutakefu 0:965ed9ce2a09 180 if ((not pressed) && (button->press())) {
yabutakefu 0:965ed9ce2a09 181 newReleasedButton.push_back(*button);
yabutakefu 0:965ed9ce2a09 182 button->set(false);
yabutakefu 0:965ed9ce2a09 183 }
yabutakefu 0:965ed9ce2a09 184
yabutakefu 0:965ed9ce2a09 185 }
yabutakefu 0:965ed9ce2a09 186 }
yabutakefu 0:965ed9ce2a09 187 }
yabutakefu 0:965ed9ce2a09 188
yabutakefu 0:965ed9ce2a09 189 //押下中のキーボードボタンを取得する
yabutakefu 0:965ed9ce2a09 190 bool keyboardJP53::pressedButton(std::vector<keyboardButton>& result) {
yabutakefu 0:965ed9ce2a09 191
yabutakefu 0:965ed9ce2a09 192 bool returnValue = false;
yabutakefu 0:965ed9ce2a09 193 keyboardButton *button;
yabutakefu 0:965ed9ce2a09 194
yabutakefu 0:965ed9ce2a09 195 //resultに_newPressedButtonの要素を挿入する
yabutakefu 0:965ed9ce2a09 196 result.clear();
yabutakefu 0:965ed9ce2a09 197
yabutakefu 0:965ed9ce2a09 198 for (int _row = 0; _row < KEYBORAD_JP53_ROW; _row++) {
yabutakefu 0:965ed9ce2a09 199 for (int _col = 0; _col < KEYBORAD_JP53_ROW; _col++) {
yabutakefu 0:965ed9ce2a09 200 button = _map[_row][_col];
yabutakefu 0:965ed9ce2a09 201
yabutakefu 0:965ed9ce2a09 202 //未定義であればコピー処理をスルー
yabutakefu 0:965ed9ce2a09 203 if (button == NULL) {
yabutakefu 0:965ed9ce2a09 204 continue;
yabutakefu 0:965ed9ce2a09 205 }
yabutakefu 0:965ed9ce2a09 206
yabutakefu 0:965ed9ce2a09 207 //押下されたキーボードボタンに当該ボタンをコピー
yabutakefu 0:965ed9ce2a09 208 if (button->press()) {
yabutakefu 0:965ed9ce2a09 209 returnValue = true;
yabutakefu 0:965ed9ce2a09 210 result.push_back(*button);
yabutakefu 0:965ed9ce2a09 211 }
yabutakefu 0:965ed9ce2a09 212 }
yabutakefu 0:965ed9ce2a09 213 }
yabutakefu 0:965ed9ce2a09 214 return returnValue;
yabutakefu 0:965ed9ce2a09 215 }
yabutakefu 0:965ed9ce2a09 216
yabutakefu 0:965ed9ce2a09 217 //未押下のキーボードボタンを取得する
yabutakefu 0:965ed9ce2a09 218 bool keyboardJP53::releasedButton(std::vector<keyboardButton>& result) {
yabutakefu 0:965ed9ce2a09 219
yabutakefu 0:965ed9ce2a09 220 bool returnValue = false;
yabutakefu 0:965ed9ce2a09 221 keyboardButton *button;
yabutakefu 0:965ed9ce2a09 222
yabutakefu 0:965ed9ce2a09 223 //resultに_newPressedButtonの要素を挿入する
yabutakefu 0:965ed9ce2a09 224 result.clear();
yabutakefu 0:965ed9ce2a09 225
yabutakefu 0:965ed9ce2a09 226 for (int _row = 0; _row < KEYBORAD_JP53_ROW; _row++) {
yabutakefu 0:965ed9ce2a09 227 for (int _col = 0; _col < KEYBORAD_JP53_ROW; _col++) {
yabutakefu 0:965ed9ce2a09 228 button = _map[_row][_col];
yabutakefu 0:965ed9ce2a09 229
yabutakefu 0:965ed9ce2a09 230 //未定義であればコピー処理をスルー
yabutakefu 0:965ed9ce2a09 231 if (button == NULL) {
yabutakefu 0:965ed9ce2a09 232 continue;
yabutakefu 0:965ed9ce2a09 233 }
yabutakefu 0:965ed9ce2a09 234
yabutakefu 0:965ed9ce2a09 235 //押下されたキーボードボタンに当該ボタンをコピー
yabutakefu 0:965ed9ce2a09 236 if (not button->press()) {
yabutakefu 0:965ed9ce2a09 237 returnValue = true;
yabutakefu 0:965ed9ce2a09 238 result.push_back(*button);
yabutakefu 0:965ed9ce2a09 239 }
yabutakefu 0:965ed9ce2a09 240 }
yabutakefu 0:965ed9ce2a09 241 }
yabutakefu 0:965ed9ce2a09 242 return returnValue;
yabutakefu 0:965ed9ce2a09 243 }