Browse Source

Update to IDE 1.8.5

And latest version of USB Host Shield Library 2.0
gdsports 7 months ago
parent
commit
cc7b243650
2 changed files with 1694 additions and 1693 deletions
  1. 253
    253
      keymapper.ino
  2. 1441
    1440
      keymapper_game.h

+ 253
- 253
keymapper.ino View File

@@ -1,69 +1,69 @@
1 1
 /*
2
-Usage: Convert standard QWERTY keyboard to any keyboard layout you want
3
-Default layout: QWERTY
4
-Reserved key combination to switch layout:
5
-Ctrl-Shift 0 => QWERTY (DEFAULT)
6
-Ctrl-Shift 1 => tarmak1
7
-Ctrl-Shift 2 => tarmak2
8
-Ctrl-Shift 3 => tarmak3
9
-Ctrl-Shift 4 => tarmak4
10
-Ctrl-Shift 5 => Colemak
11
-Ctrl-Shift 6 => Dvorak
12
-Ctrl-Shift 7 => Workman
2
+  Usage: Convert standard QWERTY keyboard to any keyboard layout you want
3
+  Default layout: QWERTY
4
+  Reserved key combination to switch layout:
5
+  Ctrl-Shift 0 => QWERTY (DEFAULT)
6
+  Ctrl-Shift 1 => tarmak1
7
+  Ctrl-Shift 2 => tarmak2
8
+  Ctrl-Shift 3 => tarmak3
9
+  Ctrl-Shift 4 => tarmak4
10
+  Ctrl-Shift 5 => Colemak
11
+  Ctrl-Shift 6 => Dvorak
12
+  Ctrl-Shift 7 => Workman
13 13
 */
14 14
 
15 15
 #include <avr/pgmspace.h>
16 16
 #include <Usb.h>
17 17
 #include <hidboot.h>
18
+#include <Keyboard.h>
18 19
 
19 20
 #include "keymapper_game.h"
20 21
 
21
-//#define DEBUG
22
-#define modeLED 13
23
-//#define TEENSY   //uncomment this line if you are usin Teensy
22
+#define DEBUG
23
+#define modeLED LED_BUILTIN
24 24
 
25 25
 
26 26
 // function definitions
27
-bool HandleReservedKeystrokes(HID *hid, uint8_t *buf);
27
+bool HandleReservedKeystrokes(USBHID *hid, uint8_t *buf);
28 28
 inline void SendKeysToHost (uint8_t *buf);
29 29
 void play_word_game(void);
30 30
 inline void LatchKey (uint8_t keyToLatch);
31 31
 
32 32
 
33 33
 // variable definitions
34
-typedef enum 
34
+typedef enum
35 35
 {
36
-    qwerty=0, 
37
-    tarmak1,
38
-    tarmak2,
39
-    tarmak3,
40
-    tarmak4,
41
-    colemak,
42
-    dvorak,
43
-    workman
36
+  qwerty = 0,
37
+  tarmak1,
38
+  tarmak2,
39
+  tarmak3,
40
+  tarmak4,
41
+  colemak,
42
+  dvorak,
43
+  workman
44 44
 } KeyboardLayout;
45 45
 
46 46
 // Keymap based on the scancodes from 4 to 57, refer to the HID usage table on the meaning of each element
47
-PROGMEM prog_uint8_t qwertyKeymap[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57};
48
-PROGMEM prog_uint8_t tarmak1Keymap[] = {4, 5, 6, 7, 13, 9, 10, 11, 12, 17, 8, 15, 16, 14, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 42};
49
-PROGMEM prog_uint8_t tarmak2Keymap[] = {4, 5, 6, 7, 9, 23, 13, 11, 12, 17, 8, 15, 16, 14, 18, 19, 20, 21, 22, 10, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 42};
50
-PROGMEM prog_uint8_t tarmak3Keymap[] = {4, 5, 6, 7, 9, 23, 51, 11, 12, 17, 8, 15, 16, 14, 28, 19, 20, 21, 22, 10, 24, 25, 26, 27, 13, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 18, 52, 53, 54, 55, 56, 42};
51
-PROGMEM prog_uint8_t tarmak4Keymap[] = {4, 5, 6, 7, 9, 23, 51, 11, 24, 17, 8, 12, 16, 14, 28, 19, 20, 21, 22, 10, 15, 25, 26, 27, 13, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 18, 52, 53, 54, 55, 56, 42};
52
-PROGMEM prog_uint8_t colemakKeymap[] = {4, 5, 6, 22, 9, 23, 7, 11, 24, 17, 8, 12, 16, 14, 28, 51, 20, 19, 21, 10, 15, 25, 26, 27, 13, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 18, 52, 53, 54, 55, 56, 42};
53
-PROGMEM prog_uint8_t dvorakKeymap[] = {4, 27, 13, 8, 55, 24, 12, 7, 6, 11, 23, 17, 16, 5, 21, 15, 52, 19, 18, 28, 10, 14, 54, 20, 9, 51, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 47, 48, 56, 46, 49, 50, 22, 45, 53, 26, 25, 29, 57};
54
-PROGMEM prog_uint8_t workmanKeymap[] = {4, 25, 16, 11, 21, 23, 10, 28, 24, 17, 8, 18, 15, 14, 19, 51, 20, 26, 22, 5, 9, 6, 7, 27, 13, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 12, 52, 53, 54, 55, 56, 42};
47
+PROGMEM const uint8_t qwertyKeymap[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57};
48
+PROGMEM const uint8_t tarmak1Keymap[] = {4, 5, 6, 7, 13, 9, 10, 11, 12, 17, 8, 15, 16, 14, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 42};
49
+PROGMEM const uint8_t tarmak2Keymap[] = {4, 5, 6, 7, 9, 23, 13, 11, 12, 17, 8, 15, 16, 14, 18, 19, 20, 21, 22, 10, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 42};
50
+PROGMEM const uint8_t tarmak3Keymap[] = {4, 5, 6, 7, 9, 23, 51, 11, 12, 17, 8, 15, 16, 14, 28, 19, 20, 21, 22, 10, 24, 25, 26, 27, 13, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 18, 52, 53, 54, 55, 56, 42};
51
+PROGMEM const uint8_t tarmak4Keymap[] = {4, 5, 6, 7, 9, 23, 51, 11, 24, 17, 8, 12, 16, 14, 28, 19, 20, 21, 22, 10, 15, 25, 26, 27, 13, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 18, 52, 53, 54, 55, 56, 42};
52
+PROGMEM const uint8_t colemakKeymap[] = {4, 5, 6, 22, 9, 23, 7, 11, 24, 17, 8, 12, 16, 14, 28, 51, 20, 19, 21, 10, 15, 25, 26, 27, 13, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 18, 52, 53, 54, 55, 56, 42};
53
+PROGMEM const uint8_t dvorakKeymap[] = {4, 27, 13, 8, 55, 24, 12, 7, 6, 11, 23, 17, 16, 5, 21, 15, 52, 19, 18, 28, 10, 14, 54, 20, 9, 51, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 47, 48, 56, 46, 49, 50, 22, 45, 53, 26, 25, 29, 57};
54
+PROGMEM const uint8_t workmanKeymap[] = {4, 25, 16, 11, 21, 23, 10, 28, 24, 17, 8, 18, 15, 14, 19, 51, 20, 26, 22, 5, 9, 6, 7, 27, 13, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 12, 52, 53, 54, 55, 56, 42};
55 55
 
56 56
 
57 57
 const uint8_t *Keymap[] =
58
-{   
59
-    qwertyKeymap,
60
-    tarmak1Keymap,
61
-    tarmak2Keymap,
62
-    tarmak3Keymap,
63
-    tarmak4Keymap,
64
-    colemakKeymap,
65
-    dvorakKeymap,
66
-    workmanKeymap
58
+{
59
+  qwertyKeymap,
60
+  tarmak1Keymap,
61
+  tarmak2Keymap,
62
+  tarmak3Keymap,
63
+  tarmak4Keymap,
64
+  colemakKeymap,
65
+  dvorakKeymap,
66
+  workmanKeymap
67 67
 };
68 68
 
69 69
 // global variables
@@ -71,15 +71,15 @@ const uint8_t *Keymap[] =
71 71
 //uint16_t ledBlinkDelay = 500;
72 72
 
73 73
 KeyboardLayout CurrentLayout = qwerty;
74
-uint8_t KeyBuffer[8] = {0,0,0,0,0,0,0,0};
75
-uint8_t specialKeyLatch=0;
74
+uint8_t KeyBuffer[8] = {0, 0, 0, 0, 0, 0, 0, 0};
75
+uint8_t specialKeyLatch = 0;
76 76
 bool specialKeyLatchReleased = false;
77 77
 
78 78
 
79 79
 class KbdRptParser : public KeyboardReportParser
80 80
 {
81
-protected:
82
-    virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
81
+  protected:
82
+    virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
83 83
 };
84 84
 
85 85
 
@@ -87,179 +87,179 @@ protected:
87 87
 // Parse
88 88
 // *******************************************************************************************
89 89
 
90
-void KbdRptParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
90
+void KbdRptParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
91 91
 {
92
-	uint8_t i;
93
-  
94
-	// On error - return
95
-	if (buf[2] == 1)
96
-		return;
92
+  uint8_t i;
97 93
 
98
-    // for (uint8_t i=0; i<8; i++)
99
-    // {
100
-        // PrintHex(buf[i]);
101
-        // Serial.print(" ");
102
-    // }
103
-    // Serial.println("");
94
+  // On error - return
95
+  if (buf[2] == 1)
96
+    return;
97
+
98
+  // for (uint8_t i=0; i<8; i++)
99
+  // {
100
+  //   PrintHex(buf[i]);
101
+  //   Serial.print(" ");
102
+  // }
103
+  // Serial.println("");
104 104
 
105
-    KeyBuffer[0] = buf[0];
106
-    
107
-    
108
-    if (!HandleReservedKeystrokes(hid, buf))
105
+  KeyBuffer[0] = buf[0];
106
+
107
+
108
+  if (!HandleReservedKeystrokes(hid, buf))
109
+  {
110
+    specialKeyLatchReleased = true;
111
+
112
+    // remap all keys according to the existing keymap
113
+    for (i = 2; i < 8; i++)
109 114
     {
110
-      specialKeyLatchReleased = true;
111
-      
112
-      // remap all keys according to the existing keymap
113
-      for (i=2; i<8; i++)
115
+
116
+      // handle special case of Shift-CAPSLOCK to be ignored by the remapper
117
+      if (buf[i] == KEY_CAPS_LOCK && buf[0] & 0x22)
114 118
       {
115
-        
116
-        // handle special case of Shift-CAPSLOCK to be ignored by the remapper
117
-        if (buf[i] == KEY_CAPS_LOCK && buf[0] & 0x22)
118
-        {
119
-          KeyBuffer[i] = KEY_CAPS_LOCK;
120
-          LatchKey(KEY_CAPS_LOCK);
121
-        }
122
-        else
119
+        KeyBuffer[i] = KEY_CAPS_LOCK;
120
+        LatchKey(KEY_CAPS_LOCK);
121
+      }
122
+      else
123
+      {
124
+        // print the key based on the current layout
125
+        if (buf[i] >= 4 && buf[i] <= 57)     	// transpose of 4 becoz our array starts from 0 but A is 4
126
+          // limit check to 57, which is the last mappable key (CAPSLOCK)
123 127
         {
124
-          // print the key based on the current layout
125
-          if (buf[i]>=4 && buf[i] <= 57)     	// transpose of 4 becoz our array starts from 0 but A is 4
126
-                                              // limit check to 57, which is the last mappable key (CAPSLOCK)
128
+          // if it was a special key of shift-CAPS, then only allow mapping if the key has been released at least once
129
+          if (buf[i] != specialKeyLatch)
130
+            KeyBuffer[i] = pgm_read_byte(Keymap[CurrentLayout] + buf[i] - 4);
131
+          else  // key is not released yet. do not allow mapping
127 132
           {
128
-            // if it was a special key of shift-CAPS, then only allow mapping if the key has been released at least once
129
-            if (buf[i] != specialKeyLatch)
130
-              KeyBuffer[i] = pgm_read_byte(Keymap[CurrentLayout]+buf[i]-4);
131
-            else  // key is not released yet. do not allow mapping
132
-            {
133
-              // Serial.println("key is not released");
134
-              KeyBuffer[i] = 0;
135
-              specialKeyLatchReleased = false;
136
-            }
133
+            // Serial.println("key is not released");
134
+            KeyBuffer[i] = 0;
135
+            specialKeyLatchReleased = false;
137 136
           }
138
-          else
139
-            KeyBuffer[i] = buf[i];
140 137
         }
141
-        
142
-
143
-        // check locking keys
144
-        HandleLockingKeys(hid, KeyBuffer[i]);
145
-      }
146
-      
147
-      // reset latch if key is released
148
-      if (specialKeyLatchReleased)
149
-      {
150
-        // Serial.println("latch is released");
151
-        specialKeyLatch = 0;
138
+        else
139
+          KeyBuffer[i] = buf[i];
152 140
       }
153
-      
154
-      // send out key press
155
-      SendKeysToHost (KeyBuffer); 
141
+
142
+
143
+      // check locking keys
144
+      HandleLockingKeys(hid, KeyBuffer[i]);
145
+    }
146
+
147
+    // reset latch if key is released
148
+    if (specialKeyLatchReleased)
149
+    {
150
+      // Serial.println("latch is released");
151
+      specialKeyLatch = 0;
152
+    }
153
+
154
+    // send out key press
155
+    SendKeysToHost (KeyBuffer);
156 156
 
157 157
     // for (uint8_t i=0; i<8; i++)
158 158
     // {
159
-        // PrintHex(KeyBuffer[i]);
160
-        // Serial.print(" ");
159
+    //   PrintHex(KeyBuffer[i]);
160
+    //   Serial.print(" ");
161 161
     // }
162 162
     // Serial.println("");
163 163
     // Serial.println("");
164
-        
165
-    }
164
+
165
+  }
166 166
 
167 167
 };
168 168
 
169 169
 
170
-bool HandleReservedKeystrokes(HID *hid, uint8_t *buf) // return true if it is a reserved keystroke
170
+bool HandleReservedKeystrokes(USBHID *hid, uint8_t *buf) // return true if it is a reserved keystroke
171 171
 {
172
-    uint8_t mod = buf[0];       // read the modifier byte
173
-    
174
-    uint8_t numKeysPressed = 0;
175
-    uint8_t keyPosition = 0;
176
-    
177
-    // check that there is only 1 single key that is pressed
178
-    for (uint8_t i=2; i<8; i++) if (buf[i] > 0) {
179
-        numKeysPressed++;
180
-        keyPosition = i;
172
+  uint8_t mod = buf[0];       // read the modifier byte
173
+
174
+  uint8_t numKeysPressed = 0;
175
+  uint8_t keyPosition = 0;
176
+
177
+  // check that there is only 1 single key that is pressed
178
+  for (uint8_t i = 2; i < 8; i++) if (buf[i] > 0) {
179
+      numKeysPressed++;
180
+      keyPosition = i;
181 181
     }
182
-	
183
-    if (numKeysPressed != 1) return false;	// only allow single keypress for reserved keystrokes (besides modifiers)
184
-    
185
-	
186
-	
187
-    // check if we are changing layouts
188
-    if ((mod & 0x22) && (mod & 0x11))  {        // Shift-Alt keystrokes
189
-        switch (buf[keyPosition]) {
190
-            case 0x27:    // 0
191
-                CurrentLayout = qwerty;
192
-                digitalWrite(modeLED, LOW);
193
-                LatchKey(buf[keyPosition]);
194
-                return true;
195
-
196
-            case 0x1e:    // 1
197
-                CurrentLayout = tarmak1;
198
-                digitalWrite(modeLED, HIGH);
199
-                LatchKey(buf[keyPosition]);
200
-                return true;
201
-
202
-            case 0x1f:    // 2
203
-                CurrentLayout = tarmak2;
204
-                digitalWrite(modeLED, HIGH);
205
-                LatchKey(buf[keyPosition]);
206
-                return true;
207
-
208
-            case 0x20:    // 3
209
-                CurrentLayout = tarmak3;
210
-                digitalWrite(modeLED, HIGH);
211
-                LatchKey(buf[keyPosition]);
212
-                return true;
213
-
214
-            case 0x21:    // 4
215
-                CurrentLayout = tarmak4;
216
-                digitalWrite(modeLED, HIGH);
217
-                LatchKey(buf[keyPosition]);
218
-                return true;
219
-
220
-            case 0x22:    // 5
221
-                CurrentLayout = colemak;
222
-                digitalWrite(modeLED, HIGH);
223
-                LatchKey(buf[keyPosition]);
224
-                return true;
225
-                
226
-            case 0x23:    // 6
227
-                CurrentLayout = dvorak;
228
-                digitalWrite(modeLED, HIGH);
229
-                LatchKey(buf[keyPosition]);
230
-                return true;
231
-                
232
-            case 0x24:    // 7
233
-                CurrentLayout = workman;
234
-                digitalWrite(modeLED, HIGH);
235
-                LatchKey(buf[keyPosition]);
236
-                return true;
237
-
238
-            case 0x2c:    // space bar
239
-                play_word_game();
240
-                LatchKey(buf[keyPosition]);
241
-                return true;
242
-        }
243 182
 
183
+  if (numKeysPressed != 1) return false;	// only allow single keypress for reserved keystrokes (besides modifiers)
184
+
185
+
186
+
187
+  // check if we are changing layouts
188
+  if ((mod & 0x22) && (mod & 0x11))  {        // Shift-Alt keystrokes
189
+    switch (buf[keyPosition]) {
190
+      case 0x27:    // 0
191
+        CurrentLayout = qwerty;
192
+        digitalWrite(modeLED, LOW);
193
+        LatchKey(buf[keyPosition]);
194
+        return true;
195
+
196
+      case 0x1e:    // 1
197
+        CurrentLayout = tarmak1;
198
+        digitalWrite(modeLED, HIGH);
199
+        LatchKey(buf[keyPosition]);
200
+        return true;
201
+
202
+      case 0x1f:    // 2
203
+        CurrentLayout = tarmak2;
204
+        digitalWrite(modeLED, HIGH);
205
+        LatchKey(buf[keyPosition]);
206
+        return true;
207
+
208
+      case 0x20:    // 3
209
+        CurrentLayout = tarmak3;
210
+        digitalWrite(modeLED, HIGH);
211
+        LatchKey(buf[keyPosition]);
212
+        return true;
213
+
214
+      case 0x21:    // 4
215
+        CurrentLayout = tarmak4;
216
+        digitalWrite(modeLED, HIGH);
217
+        LatchKey(buf[keyPosition]);
218
+        return true;
219
+
220
+      case 0x22:    // 5
221
+        CurrentLayout = colemak;
222
+        digitalWrite(modeLED, HIGH);
223
+        LatchKey(buf[keyPosition]);
224
+        return true;
225
+
226
+      case 0x23:    // 6
227
+        CurrentLayout = dvorak;
228
+        digitalWrite(modeLED, HIGH);
229
+        LatchKey(buf[keyPosition]);
230
+        return true;
231
+
232
+      case 0x24:    // 7
233
+        CurrentLayout = workman;
234
+        digitalWrite(modeLED, HIGH);
235
+        LatchKey(buf[keyPosition]);
236
+        return true;
237
+
238
+      case 0x2c:    // space bar
239
+        play_word_game();
240
+        LatchKey(buf[keyPosition]);
241
+        return true;
244 242
     }
245
-	
246
-    return false;
243
+
244
+  }
245
+
246
+  return false;
247 247
 
248 248
 }
249 249
 
250 250
 inline void SendKeysToHost (uint8_t *buf)
251 251
 {
252
-#ifdef TEENSY
252
+#ifdef TEENSYDUINO
253 253
   Keyboard.set_modifier(buf[0]);
254
-	Keyboard.set_key1(buf[2]);
255
-	Keyboard.set_key2(buf[3]);
256
-	Keyboard.set_key3(buf[4]);
257
-	Keyboard.set_key4(buf[5]);
258
-	Keyboard.set_key5(buf[6]);
259
-	Keyboard.set_key6(buf[7]);
260
-	Keyboard.send_now();
254
+  Keyboard.set_key1(buf[2]);
255
+  Keyboard.set_key2(buf[3]);
256
+  Keyboard.set_key3(buf[4]);
257
+  Keyboard.set_key4(buf[5]);
258
+  Keyboard.set_key5(buf[6]);
259
+  Keyboard.set_key6(buf[7]);
260
+  Keyboard.send_now();
261 261
 #else
262
-	HID_SendReport(2,buf,8);
262
+  HID().SendReport(2, buf, 8);
263 263
 #endif
264 264
 
265 265
 }
@@ -283,101 +283,101 @@ inline void LatchKey (uint8_t keyToLatch)
283 283
 
284 284
 void play_word_game(void)
285 285
 {
286
-    char buffer[GAME_MAXWORDLENGTH];
287
-    char priorityAlphabets[10];
288
-    char *instrPtr;
289
-
290
-    uint16_t randNum;
291
-
292
-    switch (CurrentLayout) {
293
-        case tarmak1:
294
-            strcpy (priorityAlphabets, "nek");
295
-            break;
296
-        case tarmak2:
297
-            strcpy (priorityAlphabets, "ftg");
298
-            break;
299
-        case tarmak3:
300
-            strcpy (priorityAlphabets, "jyo");
301
-            break;
302
-        case tarmak4:
303
-            strcpy (priorityAlphabets, "lui");
304
-            break;
305
-        case colemak:
306
-            strcpy (priorityAlphabets, "rspd");
307
-            break;
308
-        default:
309
-            strcpy (priorityAlphabets, "");
286
+  char buffer[GAME_MAXWORDLENGTH];
287
+  char priorityAlphabets[10];
288
+  char *instrPtr;
289
+
290
+  uint16_t randNum;
291
+
292
+  switch (CurrentLayout) {
293
+    case tarmak1:
294
+      strcpy (priorityAlphabets, "nek");
295
+      break;
296
+    case tarmak2:
297
+      strcpy (priorityAlphabets, "ftg");
298
+      break;
299
+    case tarmak3:
300
+      strcpy (priorityAlphabets, "jyo");
301
+      break;
302
+    case tarmak4:
303
+      strcpy (priorityAlphabets, "lui");
304
+      break;
305
+    case colemak:
306
+      strcpy (priorityAlphabets, "rspd");
307
+      break;
308
+    default:
309
+      strcpy (priorityAlphabets, "");
310
+  }
311
+
312
+  Keyboard.print( "Word game! Letters being prioritised: " );
313
+  Keyboard.println( priorityAlphabets );
314
+
315
+  for (int i = 0; i < 15; i++)  {
316
+    if (priorityAlphabets[0] != 0) {
317
+      instrPtr = NULL;
318
+      while (instrPtr == NULL) {
319
+        randNum = random(GAME_NUMWORDS);
320
+        strcpy_P(buffer, (char*)pgm_read_word(&(game_word_list[randNum])));
321
+        instrPtr = strpbrk (buffer, priorityAlphabets);
322
+      }
310 323
     }
311
-
312
-    Keyboard.print( "Word game! Letters being prioritised: " );
313
-    Keyboard.println( priorityAlphabets );
314
-
315
-    for (int i = 0; i < 15; i++)  {
316
-        if (priorityAlphabets[0] != 0) {
317
-            instrPtr = NULL;
318
-            while (instrPtr == NULL) {
319
-                randNum = random(GAME_NUMWORDS);
320
-                strcpy_P(buffer, (char*)pgm_read_word(&(game_word_list[randNum]))); 
321
-                instrPtr = strpbrk (buffer, priorityAlphabets);
322
-            }
323
-        } 
324
-        else {
325
-            randNum = random(GAME_NUMWORDS);
326
-            strcpy_P(buffer, (char*)pgm_read_word(&(game_word_list[randNum]))); 
327
-        }
328
-        
329
-        Keyboard.print( buffer );
330
-        Keyboard.print( " " );
324
+    else {
325
+      randNum = random(GAME_NUMWORDS);
326
+      strcpy_P(buffer, (char*)pgm_read_word(&(game_word_list[randNum])));
331 327
     }
332
-    Keyboard.println( "" );
328
+
329
+    Keyboard.print( buffer );
330
+    Keyboard.print( " " );
331
+  }
332
+  Keyboard.println( "" );
333 333
 }
334
-  
335 334
 
336
-  
337
-  
338
-  
339
-  
335
+
336
+
337
+
338
+
339
+
340 340
 USB     Usb;
341 341
 //USBHub     Hub(&Usb);
342
-HIDBoot<HID_PROTOCOL_KEYBOARD>    ExtKeyboard(&Usb);
342
+HIDBoot<USB_HID_PROTOCOL_KEYBOARD>    ExtKeyboard(&Usb);
343 343
 
344 344
 uint32_t next_time;
345 345
 
346 346
 KbdRptParser Prs;
347 347
 
348
-  
349
-  
348
+
349
+
350 350
 void setup()
351 351
 {
352
-    randomSeed(analogRead(0));
352
+  randomSeed(analogRead(0));
353 353
 
354
-    // initialize the digital pin as an output.
355
-    pinMode(modeLED, OUTPUT);  
354
+  // initialize the digital pin as an output.
355
+  pinMode(modeLED, OUTPUT);
356 356
 
357
-    Keyboard.begin();
357
+  Keyboard.begin();
358 358
 
359 359
 #ifdef DEBUG
360
-    Serial.begin( 115200 );
361
-    Serial.println("Start");
360
+  Serial.begin( 115200 );
361
+  while (!Serial) delay(1);
362
+  Serial.println("Start");
362 363
 #endif
363 364
 
364
-    if (Usb.Init() == -1)
365
+  if (Usb.Init() == -1)
365 366
 
366 367
 #ifdef DEBUG
367
-    Serial.println("OSC did not start.");
368
+    Serial.println("USB host did not start.");
368 369
 #else
369 370
     delay( 1 );
370 371
 #endif
371 372
 
372
-    delay( 200 );
373
+  delay( 200 );
373 374
 
374
-    next_time = millis() + 5000;
375
+  next_time = millis() + 5000;
375 376
 
376
-    ExtKeyboard.SetReportParser(0, (HIDReportParser*)&Prs);
377
+  ExtKeyboard.SetReportParser(0, (HIDReportParser*)&Prs);
377 378
 }
378 379
 
379 380
 void loop()
380 381
 {
381
-    Usb.Task();
382
-    
382
+  Usb.Task();
383 383
 }

+ 1441
- 1440
keymapper_game.h
File diff suppressed because it is too large
View File


Loading…
Cancel
Save