Advertisement
michalmonday

Arduino HID custom char encoding Print() function

Mar 23rd, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.86 KB | None | 0 0
  1.  
  2. #define ENCODING_BYTE_DESIRED 0
  3. #define ENCODING_BYTE_USED 1
  4. #define ENCODING_BYTE_MODIFIER 2
  5. byte Encoding[3][100] = { //this is US encoding
  6.   {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x4D, 0x51, 0x57, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x69, 0x6D, 0x71, 0x77, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E},
  7.   {0x31, 0x22, 0x33, 0x34, 0x35, 0x37, 0x22, 0x39, 0x30, 0x38, 0x3D, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3B, 0x3B, 0x2C, 0x3D, 0x2E, 0x2F, 0x32, 0x61, 0x6D, 0x71, 0x77, 0x79, 0x7A, 0x5B, 0x5C, 0x5D, 0x36, 0x2D, 0x7E, 0x61, 0x69, 0x6D, 0x71, 0x77, 0x79, 0x7A, 0x5B, 0x5C, 0x5D, 0x7E},
  8.   {0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x00, 0x81, 0x81, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x81, 0x00, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x00, 0x00, 0x00, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x81, 0x81, 0x81}
  9. };
  10.  
  11. void Print(char *inStr)
  12. {
  13.   int enc_index;
  14.   for(byte i=0; i<strlen(inStr); i++)
  15.   {
  16.     enc_index = GetKeyIndex(inStr[i], Encoding[ENCODING_BYTE_DESIRED]);
  17.     if(enc_index < 256)
  18.     {    
  19.       if(Encoding[ENCODING_BYTE_MODIFIER][enc_index] > 0)
  20.       {
  21.         Keyboard.press(Encoding[ENCODING_BYTE_MODIFIER][enc_index]);
  22.         delay(5);
  23.       }
  24.       Keyboard.press(Encoding[ENCODING_BYTE_USED][enc_index]);
  25.       delay(5);    
  26.     }
  27.     else
  28.     {
  29.       Keyboard.press(inStr[i]);
  30.       delay(5);    
  31.     }
  32.     Keyboard.releaseAll();
  33.   }
  34. }
  35.  
  36. int GetKeyIndex(byte c, byte* char_array)
  37. {
  38.   for(byte i=0;i<strlen(char_array);i++)
  39.   {
  40.     if(c == char_array[i])
  41.     {
  42.       return i;
  43.     }
  44.   }
  45.   return 256;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement