first test of macros

This commit is contained in:
Charles Mangin 2013-09-18 15:03:58 -04:00
parent 275a3b7b5d
commit 8c174cab18
1 changed files with 194 additions and 10 deletions

View File

@ -6,7 +6,10 @@ https://github.com/felis/USB_Host_Shield_2.0/archive/master.zip
TO DO:
caps lock key
- custom mapping for Apple /// and ///+
- macro functions
*/
@ -358,6 +361,143 @@ int KEYS_ARRAY[ROWS][COLUMNS] = {
*/
// ASCII to USB HID:
//USB byte, shift key status
const int KEYMAP_SIZE (128);
int KEYMAP[KEYMAP_SIZE][2] = {
{0, 0}, /* NUL */
{0, 0}, /* SOH */
{0, 0}, /* STX */
{0, 0}, /* ETX */
{0, 0}, /* EOT */
{0, 0}, /* ENQ */
{0, 0}, /* ACK */
{0, 0}, /* BEL */
{0x2a, 0}, /* BS */ /* Keyboard Delete (Backspace) */
{0x2b, 0}, /* TAB */ /* Keyboard Tab */
{0x28, 0}, /* LF */ /* Keyboard Return (Enter) */
{0, 0}, /* VT */
{0, 0}, /* FF */
{0, 0}, /* CR */
{0, 0}, /* SO */
{0, 0}, /* SI */
{0, 0}, /* DEL */
{0, 0}, /* DC1 */
{0, 0}, /* DC2 */
{0, 0}, /* DC3 */
{0, 0}, /* DC4 */
{0, 0}, /* NAK */
{0, 0}, /* SYN */
{0, 0}, /* ETB */
{0, 0}, /* CAN */
{0, 0}, /* EM */
{0, 0}, /* SUB */
{0, 0}, /* ESC */
{0, 0}, /* FS */
{0, 0}, /* GS */
{0, 0}, /* RS */
{0, 0}, /* US */
{0x2c, 0}, /* */
{0x1e, 1}, /* ! */
{0x34, 1}, /* " */
{0x20, 1}, /* # */
{0x21, 1}, /* $ */
{0x22, 1}, /* % */
{0x24, 1}, /* & */
{0x34, 0}, /* ' */
{0x26, 1}, /* ( */
{0x27, 1}, /* ) */
{0x25, 1}, /* * */
{0x2e, 1}, /* + */
{0x36, 0}, /* , */
{0x2d, 0}, /* - */
{0x37, 0}, /* . */
{0x38, 0}, /* / */
{0x27, 0}, /* 0 */
{0x1e, 0}, /* 1 */
{0x1f, 0}, /* 2 */
{0x20, 0}, /* 3 */
{0x21, 0}, /* 4 */
{0x22, 0}, /* 5 */
{0x23, 0}, /* 6 */
{0x24, 0}, /* 7 */
{0x25, 0}, /* 8 */
{0x26, 0}, /* 9 */
{0x33, 1}, /* : */
{0x33, 0}, /* ; */
{0x36, 1}, /* < */
{0x2e, 0}, /* = */
{0x37, 1}, /* > */
{0x38, 1}, /* ? */
{0x1f, 1}, /* @ */
{0x04, 1}, /* A */
{0x05, 1}, /* B */
{0x06, 1}, /* C */
{0x07, 1}, /* D */
{0x08, 1}, /* E */
{0x09, 1}, /* F */
{0x0a, 1}, /* G */
{0x0b, 1}, /* H */
{0x0c, 1}, /* I */
{0x0d, 1}, /* J */
{0x0e, 1}, /* K */
{0x0f, 1}, /* L */
{0x10, 1}, /* M */
{0x11, 1}, /* N */
{0x12, 1}, /* O */
{0x13, 1}, /* P */
{0x14, 1}, /* Q */
{0x15, 1}, /* R */
{0x16, 1}, /* S */
{0x17, 1}, /* T */
{0x18, 1}, /* U */
{0x19, 1}, /* V */
{0x1a, 1}, /* W */
{0x1b, 1}, /* X */
{0x1c, 1}, /* Y */
{0x1d, 1}, /* Z */
{0x2f, 0}, /* [ */
{0x31, 0}, /* \ */
{0x30, 0}, /* ] */
{0x23, 1}, /* ^ */
{0x2d, 1}, /* _ */
{0x35, 0}, /* ` */
{0x04, 0}, /* a */
{0x05, 0}, /* b */
{0x06, 0}, /* c */
{0x07, 0}, /* d */
{0x08, 0}, /* e */
{0x09, 0}, /* f */
{0x0a, 0}, /* g */
{0x0b, 0}, /* h */
{0x0c, 0}, /* i */
{0x0d, 0}, /* j */
{0x0e, 0}, /* k */
{0x0f, 0}, /* l */
{0x10, 0}, /* m */
{0x11, 0}, /* n */
{0x12, 0}, /* o */
{0x13, 0}, /* p */
{0x14, 0}, /* q */
{0x15, 0}, /* r */
{0x16, 0}, /* s */
{0x17, 0}, /* t */
{0x18, 0}, /* u */
{0x19, 0}, /* v */
{0x1a, 0}, /* w */
{0x1b, 0}, /* x */
{0x1c, 0}, /* y */
{0x1d, 0}, /* z */
{0x2f, 1}, /* { */
{0x31, 1}, /* | */
{0x30, 1}, /* } */
{0x35, 1}, /* ~ */
{0,0} /* DEL */
};
#include <avr/pgmspace.h>
@ -381,12 +521,51 @@ class KbdRptParser : public KeyboardReportParser
{
void PrintKey(uint8_t mod, uint8_t key);
void PrintLine();
protected:
virtual void OnKeyDown (uint8_t mod, uint8_t key);
virtual void OnKeyUp (uint8_t mod, uint8_t key);
virtual void OnKeyPressed(uint8_t key);
};
void KbdRptParser::PrintLine()
{
int CharDelay = 50;
String TestWord = "Hello, World!"; //{97,98,67,68}; //abCD
char SHIFTDOWN = 0;
// break up word into array of characters
// for each character in array
// translate character into USB byte
// send keydown, wait X miliseconds, send keyup
for(int letters=0; letters < TestWord.length(); letters++ ) {
Serial.print(KEYMAP[TestWord[letters]][0]); // look up the USB byte from the KEYMAP array.
if(KEYMAP[TestWord[letters]][1] == 1) {
Serial.print("!"); // hold shift
SHIFTDOWN = 2;
} else {
SHIFTDOWN = 0;
}
OnKeyDown(SHIFTDOWN,KEYMAP[TestWord[letters]][0]);
delay(CharDelay);
OnKeyUp(SHIFTDOWN,KEYMAP[TestWord[letters]][0]);
}
}
void KbdRptParser::PrintKey(uint8_t m, uint8_t key)
{
MODIFIERKEYS mod;
@ -442,13 +621,16 @@ void KbdRptParser::PrintKey(uint8_t m, uint8_t key)
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
Serial.println("DN ");
digitalWrite(S0_4051, LOW);
digitalWrite(S1_4051, LOW);
digitalWrite(S2_4051, LOW);
Serial.println(mod);
Serial.println(key);
// Serial.print("DN ");
PrintKey(mod, key);
uint8_t c = OemToAscii(mod, key);
@ -471,14 +653,13 @@ for (int row=0; row<ROWS; row++) {
}
}
/*
Serial.print( "SEARCH_ROW = " );
Serial.println( SEARCH_ROW );
Serial.print( "SEARCH_COLUMN = " );
Serial.println( SEARCH_COLUMN );
*/
//select the column bits
c0 = bitRead(SEARCH_COLUMN,0);
@ -528,8 +709,11 @@ Serial.print( "SEARCH_ROW = " );
}
// trying a sample macro:
if(key == 68) { // 0x44 == 68 == key_F11
PrintLine();
}
}
@ -607,12 +791,12 @@ digitalWrite(CONTROL_PIN, HIGH);
digitalWrite(S2_4051, LOW);
// Serial.begin( 115200 );
// Serial.println("Start");
// *** DEBUG
// Serial.begin( 115200 );
Serial.println("Start");
if (Usb.Init() == -1)
// Serial.println("OSC did not start.");
Serial.println("OSC did not start.");
delay( 200 );