Browse Source

First public release

weigee 6 years ago
commit
e063ca1adb
6 changed files with 1920 additions and 0 deletions
  1. 22
    0
      .gitattributes
  2. 163
    0
      .gitignore
  3. BIN
      Hut1_11.pdf
  4. 284
    0
      keymapper.ino
  5. 1451
    0
      keymapper_game.h
  6. BIN
      word game list manager.xlsm

+ 22
- 0
.gitattributes View File

@@ -0,0 +1,22 @@
1
+# Auto detect text files and perform LF normalization
2
+* text=auto
3
+
4
+# Custom for Visual Studio
5
+*.cs     diff=csharp
6
+*.sln    merge=union
7
+*.csproj merge=union
8
+*.vbproj merge=union
9
+*.fsproj merge=union
10
+*.dbproj merge=union
11
+
12
+# Standard to msysgit
13
+*.doc	 diff=astextplain
14
+*.DOC	 diff=astextplain
15
+*.docx diff=astextplain
16
+*.DOCX diff=astextplain
17
+*.dot  diff=astextplain
18
+*.DOT  diff=astextplain
19
+*.pdf  diff=astextplain
20
+*.PDF	 diff=astextplain
21
+*.rtf	 diff=astextplain
22
+*.RTF	 diff=astextplain

+ 163
- 0
.gitignore View File

@@ -0,0 +1,163 @@
1
+#################
2
+## Eclipse
3
+#################
4
+
5
+*.pydevproject
6
+.project
7
+.metadata
8
+bin/
9
+tmp/
10
+*.tmp
11
+*.bak
12
+*.swp
13
+*~.nib
14
+local.properties
15
+.classpath
16
+.settings/
17
+.loadpath
18
+
19
+# External tool builders
20
+.externalToolBuilders/
21
+
22
+# Locally stored "Eclipse launch configurations"
23
+*.launch
24
+
25
+# CDT-specific
26
+.cproject
27
+
28
+# PDT-specific
29
+.buildpath
30
+
31
+
32
+#################
33
+## Visual Studio
34
+#################
35
+
36
+## Ignore Visual Studio temporary files, build results, and
37
+## files generated by popular Visual Studio add-ons.
38
+
39
+# User-specific files
40
+*.suo
41
+*.user
42
+*.sln.docstates
43
+
44
+# Build results
45
+[Dd]ebug/
46
+[Rr]elease/
47
+*_i.c
48
+*_p.c
49
+*.ilk
50
+*.meta
51
+*.obj
52
+*.pch
53
+*.pdb
54
+*.pgc
55
+*.pgd
56
+*.rsp
57
+*.sbr
58
+*.tlb
59
+*.tli
60
+*.tlh
61
+*.tmp
62
+*.vspscc
63
+.builds
64
+*.dotCover
65
+
66
+## TODO: If you have NuGet Package Restore enabled, uncomment this
67
+#packages/
68
+
69
+# Visual C++ cache files
70
+ipch/
71
+*.aps
72
+*.ncb
73
+*.opensdf
74
+*.sdf
75
+
76
+# Visual Studio profiler
77
+*.psess
78
+*.vsp
79
+
80
+# ReSharper is a .NET coding add-in
81
+_ReSharper*
82
+
83
+# Installshield output folder
84
+[Ee]xpress
85
+
86
+# DocProject is a documentation generator add-in
87
+DocProject/buildhelp/
88
+DocProject/Help/*.HxT
89
+DocProject/Help/*.HxC
90
+DocProject/Help/*.hhc
91
+DocProject/Help/*.hhk
92
+DocProject/Help/*.hhp
93
+DocProject/Help/Html2
94
+DocProject/Help/html
95
+
96
+# Click-Once directory
97
+publish
98
+
99
+# Others
100
+[Bb]in
101
+[Oo]bj
102
+sql
103
+TestResults
104
+*.Cache
105
+ClientBin
106
+stylecop.*
107
+~$*
108
+*.dbmdl
109
+Generated_Code #added for RIA/Silverlight projects
110
+
111
+# Backup & report files from converting an old project file to a newer
112
+# Visual Studio version. Backup files are not needed, because we have git ;-)
113
+_UpgradeReport_Files/
114
+Backup*/
115
+UpgradeLog*.XML
116
+
117
+
118
+
119
+############
120
+## Windows
121
+############
122
+
123
+# Windows image file caches
124
+Thumbs.db
125
+
126
+# Folder config file
127
+Desktop.ini
128
+
129
+
130
+#############
131
+## Python
132
+#############
133
+
134
+*.py[co]
135
+
136
+# Packages
137
+*.egg
138
+*.egg-info
139
+dist
140
+build
141
+eggs
142
+parts
143
+bin
144
+var
145
+sdist
146
+develop-eggs
147
+.installed.cfg
148
+
149
+# Installer logs
150
+pip-log.txt
151
+
152
+# Unit test / coverage reports
153
+.coverage
154
+.tox
155
+
156
+#Translations
157
+*.mo
158
+
159
+#Mr Developer
160
+.mr.developer.cfg
161
+
162
+# Mac crap
163
+.DS_Store

BIN
Hut1_11.pdf View File


+ 284
- 0
keymapper.ino View File

@@ -0,0 +1,284 @@
1
+#include <avr/pgmspace.h>
2
+
3
+#include <avrpins.h>
4
+#include <max3421e.h>
5
+#include <usbhost.h>
6
+#include <usb_ch9.h>
7
+#include <Usb.h>
8
+#include <usbhub.h>
9
+#include <avr/pgmspace.h>
10
+#include <address.h>
11
+#include <hidboot.h>
12
+
13
+#include <printhex.h>
14
+#include <message.h>
15
+#include <hexdump.h>
16
+#include <parsetools.h>
17
+
18
+#include "keymapper_game.h"
19
+
20
+//#define DEBUG
21
+
22
+
23
+#define modeLED 13
24
+
25
+typedef enum 
26
+{
27
+	qwerty=0, 
28
+	tarmak1,
29
+	tarmak2,
30
+	tarmak3,
31
+	tarmak4,
32
+	colemak,
33
+	dvorak
34
+} KeyboardLayout;
35
+
36
+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};
37
+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, 57};
38
+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, 57};
39
+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, 57};
40
+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, 57};
41
+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, 57};
42
+
43
+const uint8_t *keymap[] =
44
+{   
45
+  qwertyKeymap,
46
+  tarmak1Keymap,
47
+  tarmak2Keymap,
48
+  tarmak3Keymap,
49
+  tarmak4Keymap,
50
+  colemakKeymap
51
+};
52
+
53
+
54
+uint8_t keyBuffer[8] = {0,0,0,0,0,0,0,0};
55
+//uint32_t ledBlinkTime = millis();
56
+//uint16_t ledBlinkDelay = 500;
57
+//bool ledStatus = false;
58
+KeyboardLayout currentLayout = qwerty;
59
+
60
+
61
+class KbdRptParser : public KeyboardReportParser
62
+{
63
+        void PrintKey(uint8_t mod, uint8_t key);
64
+        
65
+protected:
66
+	virtual void OnKeyDown	(uint8_t mod, uint8_t key);
67
+	virtual void OnKeyUp	(uint8_t mod, uint8_t key);
68
+};
69
+
70
+void KbdRptParser::PrintKey(uint8_t m, uint8_t key)	
71
+{
72
+    
73
+    MODIFIERKEYS mod;
74
+    *((uint8_t*)&mod) = m;
75
+    
76
+    Serial.print((mod.bmLeftCtrl   == 1) ? "C" : " ");
77
+    Serial.print((mod.bmLeftShift  == 1) ? "S" : " ");
78
+    Serial.print((mod.bmLeftAlt    == 1) ? "A" : " ");
79
+    Serial.print((mod.bmLeftGUI    == 1) ? "G" : " ");
80
+    
81
+    Serial.print(" >");
82
+    Serial.print (key);
83
+    Serial.print (" : ");
84
+    PrintHex<uint8_t>(key);
85
+    Serial.print("< ");
86
+
87
+    Serial.print((mod.bmRightCtrl   == 1) ? "C" : " ");
88
+    Serial.print((mod.bmRightShift  == 1) ? "S" : " ");
89
+    Serial.print((mod.bmRightAlt    == 1) ? "A" : " ");
90
+    Serial.println((mod.bmRightGUI    == 1) ? "G" : " ");
91
+
92
+};
93
+
94
+void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)	
95
+{
96
+
97
+#ifdef DEBUG
98
+    Serial.print("DN ");
99
+    PrintKey(mod, key);
100
+
101
+#endif
102
+	
103
+	// check if we are changing layouts
104
+    if ((mod & 0x22) && (mod & 0x11))  {
105
+        switch (key) {
106
+            case 0x27:    // 0
107
+                currentLayout = qwerty;
108
+                digitalWrite(modeLED, LOW);
109
+
110
+#ifdef DEBUG				
111
+                Serial.print("Current layout: ");
112
+                Serial.println(currentLayout);
113
+                
114
+				for (uint8_t i=0; i<54; i++)
115
+					Serial.println(pgm_read_byte(keymap[currentLayout]+i));
116
+#endif
117
+					break;
118
+
119
+			case 0x1e:    // 1
120
+                currentLayout = tarmak1;
121
+                digitalWrite(modeLED, HIGH);
122
+                break;
123
+
124
+			case 0x1f:    // 2
125
+                currentLayout = tarmak2;
126
+                digitalWrite(modeLED, HIGH);
127
+                break;
128
+
129
+			case 0x20:    // 3
130
+                currentLayout = tarmak3;
131
+                digitalWrite(modeLED, HIGH);
132
+                break;
133
+
134
+			case 0x21:    // 4
135
+                currentLayout = tarmak4;
136
+                digitalWrite(modeLED, HIGH);
137
+                break;
138
+
139
+			case 0x22:    // 5
140
+                currentLayout = colemak;
141
+                digitalWrite(modeLED, HIGH);
142
+                break;
143
+
144
+
145
+			case 0x2c:    // space bar
146
+                play_word_game();
147
+                break;
148
+        }
149
+    } 
150
+	else
151
+	{
152
+		// print the key based on the current layout
153
+		if (key-4 < 54)		// transpose of 4 becoz our array starts from 0 but A is 4
154
+							// limit check to 57, which is the last mappable key (CAPSLOCK)
155
+			key = pgm_read_byte(keymap[currentLayout]+key-4);
156
+	
157
+		keyBuffer[0] = mod;
158
+		keyBuffer[2] = key;
159
+		
160
+		HID_SendReport(2,keyBuffer,sizeof(keyBuffer));    
161
+	}
162
+}
163
+
164
+void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key)	
165
+{
166
+#ifdef DEBUG
167
+    Serial.print("UP ");
168
+    PrintKey(mod, key);
169
+#endif
170
+    
171
+    keyBuffer[0] = 0;
172
+    keyBuffer[2] = 0;
173
+       
174
+    HID_SendReport(2,keyBuffer,sizeof(keyBuffer));
175
+
176
+}
177
+
178
+
179
+USB     Usb;
180
+//USBHub     Hub(&Usb);
181
+HIDBoot<HID_PROTOCOL_KEYBOARD>    Keyboard2(&Usb);
182
+
183
+uint32_t next_time;
184
+
185
+KbdRptParser Prs;
186
+
187
+
188
+// *******************************
189
+// **** 	WORD GAME!!!       ***
190
+// *******************************
191
+
192
+void play_word_game()
193
+{
194
+  char buffer[GAME_MAXWORDLENGTH];
195
+  char priorityAlphabets[10];
196
+  char *instrPtr;
197
+  
198
+  uint16_t randNum;
199
+
200
+  switch (currentLayout) {
201
+	case tarmak1:
202
+		strcpy (priorityAlphabets, "nek");
203
+		break;
204
+	case tarmak2:
205
+		strcpy (priorityAlphabets, "ftg");
206
+		break;
207
+	case tarmak3:
208
+		strcpy (priorityAlphabets, "jyo");
209
+		break;
210
+	case tarmak4:
211
+		strcpy (priorityAlphabets, "lui");
212
+		break;
213
+	case colemak:
214
+		strcpy (priorityAlphabets, "rspd");
215
+		break;
216
+	default:
217
+		strcpy (priorityAlphabets, "");
218
+  }
219
+
220
+  Keyboard.print( "Word game! Letters being prioritised: " );
221
+  Keyboard.println( priorityAlphabets );
222
+  
223
+  for (int i = 0; i < 15; i++)  {
224
+	if (priorityAlphabets[0] != 0) {
225
+		instrPtr = NULL;
226
+		while (instrPtr == NULL) {
227
+			randNum = random(GAME_NUMWORDS);
228
+			strcpy_P(buffer, (char*)pgm_read_word(&(game_word_list[randNum]))); 
229
+			instrPtr = strpbrk (buffer, priorityAlphabets);
230
+		}
231
+	} 
232
+	else {
233
+		randNum = random(GAME_NUMWORDS);
234
+		strcpy_P(buffer, (char*)pgm_read_word(&(game_word_list[randNum]))); 
235
+	}
236
+		
237
+	Keyboard.print( buffer );
238
+    Keyboard.print( " " );
239
+  }
240
+  Keyboard.println( "" );
241
+}
242
+  
243
+
244
+  
245
+  
246
+  
247
+  
248
+void setup()
249
+{
250
+  randomSeed(analogRead(0));
251
+
252
+  // initialize the digital pin as an output.
253
+  pinMode(modeLED, OUTPUT);  
254
+  
255
+  
256
+  
257
+  Keyboard.begin();
258
+
259
+#ifdef DEBUG
260
+  Serial.begin( 115200 );
261
+  Serial.println("Start");
262
+#endif
263
+
264
+  if (Usb.Init() == -1)
265
+
266
+#ifdef DEBUG
267
+    Serial.println("OSC did not start.");
268
+#else
269
+    delay( 1 );
270
+#endif
271
+
272
+  delay( 200 );
273
+  
274
+  next_time = millis() + 5000;
275
+  
276
+  Keyboard2.SetReportParser(0, (HIDReportParser*)&Prs);
277
+}
278
+
279
+void loop()
280
+{
281
+  Usb.Task();
282
+    
283
+}
284
+

+ 1451
- 0
keymapper_game.h
File diff suppressed because it is too large
View File


BIN
word game list manager.xlsm View File


Loading…
Cancel
Save