2022-06-30 12:19:02 -07:00
|
|
|
/*
|
2022-06-30 11:16:29 -07:00
|
|
|
* Note2: If your flash is not formatted as FAT12 previously, you could format it using
|
|
|
|
* follow sketch https://github.com/adafruit/Adafruit_SPIFlash/tree/master/examples/SdFat_format
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include "src/keyboard/keyboard.h"
|
|
|
|
#include "src/led/led.h"
|
|
|
|
#include "src/duckparser/duckparser.h"
|
|
|
|
#include "src/msc/msc.h"
|
|
|
|
#include "src/selector/selector.h"
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
debug_init();
|
|
|
|
|
|
|
|
msc::init();
|
2022-06-30 12:19:02 -07:00
|
|
|
keyboard::init();
|
|
|
|
selector::init();
|
|
|
|
led::init();
|
2022-06-30 11:16:29 -07:00
|
|
|
|
|
|
|
Serial.begin(115200);
|
2022-06-30 12:19:02 -07:00
|
|
|
|
2022-06-30 11:16:29 -07:00
|
|
|
// while ( !Serial ) delay(10); // wait for native usb
|
|
|
|
|
2022-06-30 12:19:02 -07:00
|
|
|
/*
|
|
|
|
// Wait a bit
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
msc::prepare_read("payload.dd");
|
2022-06-30 11:16:29 -07:00
|
|
|
|
2022-06-30 12:19:02 -07:00
|
|
|
// Read script from SD Card
|
|
|
|
char last_buffer[READ_BUFFER];
|
|
|
|
size_t last_buffer_len { 0 };
|
2022-06-30 11:16:29 -07:00
|
|
|
|
2022-06-30 12:19:02 -07:00
|
|
|
char buffer[READ_BUFFER];
|
|
|
|
size_t buffer_len { 0 };
|
2022-06-30 11:16:29 -07:00
|
|
|
|
2022-06-30 12:19:02 -07:00
|
|
|
do {
|
|
|
|
buffer_len = msc::read_line(buffer, READ_BUFFER);
|
2022-06-30 11:16:29 -07:00
|
|
|
|
2022-06-30 12:19:02 -07:00
|
|
|
duckparser::parse(buffer, buffer_len);
|
2022-06-30 11:16:29 -07:00
|
|
|
|
2022-06-30 12:19:02 -07:00
|
|
|
int repeats = duckparser::getRepeats();
|
|
|
|
if (repeats > 0) {
|
|
|
|
debug("[repeat x");
|
|
|
|
debug(repeats);
|
|
|
|
debugln("]");
|
2022-06-30 11:16:29 -07:00
|
|
|
|
2022-06-30 12:19:02 -07:00
|
|
|
for (int i = 0; i<repeats; ++i) {
|
|
|
|
debugln("[repeating]");
|
|
|
|
duckparser::parse(last_buffer, last_buffer_len);
|
|
|
|
}
|
2022-06-30 11:16:29 -07:00
|
|
|
}
|
|
|
|
|
2022-06-30 12:19:02 -07:00
|
|
|
memcpy(last_buffer, buffer, buffer_len);
|
|
|
|
last_buffer_len = buffer_len;
|
|
|
|
#ifdef ENABLE_DEBUG
|
2022-06-30 11:16:29 -07:00
|
|
|
|
2022-06-30 12:19:02 -07:00
|
|
|
for (size_t i = 0; i<buffer_len; ++i) {
|
|
|
|
debug(buffer[i]);
|
|
|
|
}
|
|
|
|
#endif // ifdef ENABLE_DEBUG 3THIS ISA N3moal,lSCRUPT 1
|
|
|
|
} while(buffer_len > 0);
|
|
|
|
*/
|
2022-06-30 11:16:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2022-06-30 12:19:02 -07:00
|
|
|
if (selector::read()) {
|
|
|
|
led::setColor(255, 0, 0);
|
|
|
|
} else {
|
|
|
|
led::setColor(0, 255, 0);
|
|
|
|
}
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
/*
|
|
|
|
if(msc::changed()) {
|
2022-06-30 11:16:29 -07:00
|
|
|
FatFile file;
|
2022-06-30 12:19:02 -07:00
|
|
|
|
2022-06-30 11:16:29 -07:00
|
|
|
if(file.open("/payload.dd")) {
|
|
|
|
size_t fsize = file.fileSize();
|
|
|
|
|
|
|
|
char _buf[fsize + 1];
|
|
|
|
|
|
|
|
file.read(_buf, fsize);
|
|
|
|
_buf[fsize] = '\0';
|
|
|
|
|
|
|
|
Serial.println(_buf);
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
}
|
2022-06-30 12:19:02 -07:00
|
|
|
}*/
|
2022-06-30 11:16:29 -07:00
|
|
|
}
|