diff --git a/src/main.cpp b/src/main.cpp index 800a07b..b654f46 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,24 +1,247 @@ #include #include "Keyboard.h" +#include "EEPROM.h" -#define PIN_BUTTON 12 +#define SERIAL_PORT Serial -String password="echo \"czimage:CC37*#dfk7,A6b3cqKS\" >cred && chmod 600 cred && s3fs clonezilla /home/partimag -o passwd_file=cred,use_path_request_style,url=https://ccsnstorage.catholiccharities.com:9000"; +// configuration + +const int slotcount=1; // number of keys to support +String passwords[slotcount]; // password storage +int pins[slotcount]={12}; // pins to which keys are attached + +// other globals + +String command=""; // serial-port command buffer +const String version="0.1"; // firmware version +const String hw_version="0.2"; // hardware version + +// prototypes + +void setup(); +void loop(); +void SendPassword(int slot); +void LoadPasswords(); +void SavePasswords(); +void Help(); +void ShowPassword(int key); +void ShowAll(); +void ShowVersion(); +String ReadHWVersion(); + +// initialization void setup() { - pinMode(PIN_BUTTON, INPUT_PULLUP); + SERIAL_PORT.begin(9600); + SERIAL_PORT.write(']'); + + // set up input pins + + for (int slot=0; slot0) { - for (int i=0; i=32 && inchr<127) // printable? { - Keyboard.press(password[i]); - Keyboard.releaseAll(); + command+=inchr; + SERIAL_PORT.write(inchr); // echo it back } - delay(500); + if (inchr==8 || inchr==127) // delete or backspace? + if (command.length()>0) + { + command=command.substring(0,command.length()-1); + SERIAL_PORT.write(8); // erase last character + SERIAL_PORT.write(32); + SERIAL_PORT.write(8); + } + if (inchr==13) // return? + { + cmdComplete=true; // end of line + SERIAL_PORT.write("\r\n"); + } + } + if (cmdComplete) // EOL? + { + if (command=="") + Help(); + else if (command.substring(0,5)=="show ") + { + command=command.substring(5); + if (command=="all") + ShowAll(); + else + ShowPassword(command.toInt()); + } + else if (command.substring(0,4)=="set ") + { + command=command.substring(4); + int slot=0; + while (command[0]!=' ') + { + slot=10*slot+String(command[0]).toInt(); + command=command.substring(1); + } + command=command.substring(1); + if (slot>=0 && slot=0 && key