 /*
-Copyright (c) 2017 Seytonic, Spacehuhn (Licensed under MIT)
-For more information see: github.com/seytonic/malduino
+  ==============================================================
+    Copyright (c) 2017 Seytonic, Spacehuhn (Licensed under MIT)
+      For more information see: github.com/seytonic/malduino
+  ==============================================================
 */
 
 #include <SPI.h>
 #include <SD.h>
 #include "Keyboard.h"
 
-//#define debug true // <-- uncomment to turn serial output on
+#define debug true // <-- uncomment to turn serial output on
 #define CSpin 4 //Chip-Select of the SD-Card reader
 #define ledPin 3
 #define blinkInterval 50

  return -1;
}

bool equals(int start, int end, char* str, int strLen){
  if(end-start != strLen) return false;
  for(int i=0;i<strLen;i++){
    if(buf[start+i] != str[i]) return false;
  }
  return true;
}

int getInt(int pos){
  String amount = String(buf).substring(pos+1,pos+6);
  return amount.toInt();
}


  #endif
  
  if(e - s < 2) Keyboard.press(buf[s]);
  else if(equalsBuffer(s,e,"ENTER")) Keyboard.press(KEY_RETURN);
  else if(equalsBuffer(s,e,"GUI") || equalsBuffer(s,e,"WINDOWS")) Keyboard.press(KEY_LEFT_GUI);
  else if(equalsBuffer(s,e,"SHIFT")) Keyboard.press(KEY_LEFT_SHIFT);
  else if(equalsBuffer(s,e,"ALT")  ||equalsBuffer(s,e,"ALT_LEFT") ||equalsBuffer(s,e,"ALTLEFT")) Keyboard.press(KEY_LEFT_ALT);
  else if(equalsBuffer(s,e,"ALT_RIGHT") ||equalsBuffer(s,e,"ALTRIGHT")) Keyboard.press(KEY_RIGHT_ALT);
  else if(equalsBuffer(s,e,"CTRL") || equalsBuffer(s,e,"CONTROL")) Keyboard.press(KEY_LEFT_CTRL);
  else if(equalsBuffer(s,e,"CAPSLOCK")) Keyboard.press(KEY_CAPS_LOCK);
  else if(equalsBuffer(s,e,"DELETE")) Keyboard.press(KEY_DELETE);
  else if(equalsBuffer(s,e,"END")) Keyboard.press(KEY_END);
  else if(equalsBuffer(s,e,"ESC") || equalsBuffer(s,e,"ESCAPE")) Keyboard.press(KEY_ESC);
  else if(equalsBuffer(s,e,"HOME")) Keyboard.press(KEY_HOME);
  else if(equalsBuffer(s,e,"INSERT")) Keyboard.press(KEY_INSERT);
  else if(equalsBuffer(s,e,"PAGEUP")) Keyboard.press(KEY_PAGE_UP);
  else if(equalsBuffer(s,e,"PAGEDOWN")) Keyboard.press(KEY_PAGE_DOWN);
  else if(equalsBuffer(s,e,"SPACE")) Keyboard.press(' ');
  else if(equalsBuffer(s,e,"TAB")) Keyboard.press(KEY_TAB);
  else if(equalsBuffer(s,e,"BACKSPACE")) Keyboard.press(KEY_BACKSPACE);
  
  else if(equalsBuffer(s,e,"UP") || equalsBuffer(s,e,"UPARROW")) Keyboard.press(KEY_UP_ARROW);
  else if(equalsBuffer(s,e,"DOWN") || equalsBuffer(s,e,"DOWNARROW")) Keyboard.press(KEY_DOWN_ARROW);
  else if(equalsBuffer(s,e,"LEFT") || equalsBuffer(s,e,"LEFTARROW")) Keyboard.press(KEY_LEFT_ARROW);
  else if(equalsBuffer(s,e,"RIGHT") || equalsBuffer(s,e,"RIGHTARROW")) Keyboard.press(KEY_RIGHT_ARROW);
  
  else if(equalsBuffer(s,e,"PRINTSCREEN")) Keyboard.press(PRINTSCREEN);

  else if(equalsBuffer(s,e,"F1")) Keyboard.press(KEY_F1);
  else if(equalsBuffer(s,e,"F2")) Keyboard.press(KEY_F2);
  else if(equalsBuffer(s,e,"F3")) Keyboard.press(KEY_F3);
  else if(equalsBuffer(s,e,"F4")) Keyboard.press(KEY_F4);
  else if(equalsBuffer(s,e,"F5")) Keyboard.press(KEY_F5);
  else if(equalsBuffer(s,e,"F6")) Keyboard.press(KEY_F6);
  else if(equalsBuffer(s,e,"F7")) Keyboard.press(KEY_F7);
  else if(equalsBuffer(s,e,"F8")) Keyboard.press(KEY_F8);
  else if(equalsBuffer(s,e,"F9")) Keyboard.press(KEY_F9);
  else if(equalsBuffer(s,e,"F10")) Keyboard.press(KEY_F10);
  else if(equalsBuffer(s,e,"F11")) Keyboard.press(KEY_F11);
  else if(equalsBuffer(s,e,"F12")) Keyboard.press(KEY_F12);

  else if(equalsBuffer(s,e,"NUM_0")) KeyboardWrite(KEYPAD_0);
  else if(equalsBuffer(s,e,"NUM_1")) KeyboardWrite(KEYPAD_1);
  else if(equalsBuffer(s,e,"NUM_2")) KeyboardWrite(KEYPAD_2);
  else if(equalsBuffer(s,e,"NUM_3")) KeyboardWrite(KEYPAD_3);
  else if(equalsBuffer(s,e,"NUM_4")) KeyboardWrite(KEYPAD_4);
  else if(equalsBuffer(s,e,"NUM_5")) KeyboardWrite(KEYPAD_5);
  else if(equalsBuffer(s,e,"NUM_6")) KeyboardWrite(KEYPAD_6);
  else if(equalsBuffer(s,e,"NUM_7")) KeyboardWrite(KEYPAD_7);
  else if(equalsBuffer(s,e,"NUM_8")) KeyboardWrite(KEYPAD_8);
  else if(equalsBuffer(s,e,"NUM_9")) KeyboardWrite(KEYPAD_9);
  else if(equalsBuffer(s,e,"NUM_ASTERIX")) KeyboardWrite(KEYPAD_ASTERIX);
  else if(equalsBuffer(s,e,"NUM_ENTER")) KeyboardWrite(KEYPAD_ENTER);
  else if(equalsBuffer(s,e,"NUM_Minus")) KeyboardWrite(KEYPAD_MINUS);
  else if(equalsBuffer(s,e,"NUM_PERIOD")) KeyboardWrite(KEYPAD_PERIOD);
  else if(equalsBuffer(s,e,"NUM_PLUS")) KeyboardWrite(KEYPAD_PLUS);

#ifdef debug
  else Serial.println("failed to find command");
#endif
  /* not implemented
  else if(equalsBuffer(s,e,"APP")) Keyboard.press();
  else if(equalsBuffer(s,e,"MENU")) Keyboard.press();
  else if(equalsBuffer(s,e,"BREAK") || equalsBuffer(s,e,"PAUSE",5)) Keyboard.press();
  else if(equalsBuffer(s,e,"NUMLOCK")) Keyboard.press();
  else if(equalsBuffer(s,e,"SCROLLLOCK")) Keyboard.press();
  */
}

