#include "eic.h"
#include "usb.h"
#include "uart.h"
+#include "filesystem.h"
#ifdef HAS_IR_SENSOR
HAL_GPIO_IR_ENABLE_clr();
HAL_GPIO_IRSENSE_in();
HAL_GPIO_IRSENSE_pmuxen(HAL_GPIO_PMUX_SERCOM_ALT);
- uart_init_instance(0, UART_TXPO_NONE, UART_RXPO_0, 600);
+ uart_init_instance(0, UART_TXPO_NONE, UART_RXPO_0, 900);
uart_set_irda_mode_instance(0, true);
uart_enable_instance(0);
}
case EVENT_TICK:
{
char data[32];
+ char filename[9];
+ char content[30];
size_t bytes_read = uart_read_instance(0, data, 32);
if (bytes_read) {
+ // data is in the format: ">FILENAME>CONTENT" followed by a one-byte checksum
+ uint8_t checksum = 0;
+ for (size_t i = 0; i < bytes_read - 1; i++) {
+ checksum += data[i];
+ }
+ if (checksum != data[bytes_read - 1]) {
+ // failed
+ movement_force_led_on(48, 0, 0);
+ } else {
+ // parse the data
+ if (data[0] != '>') {
+ // failed
+ movement_force_led_on(48, 30, 0);
+ } else {
+ size_t i = 1;
+ while (data[i] != '>' && i < 9) {
+ filename[i - 1] = data[i];
+ i++;
+ }
+ if (i == 9) {
+ // failed
+ movement_force_led_on(48, 0, 30);
+ } else {
+ filename[i - 1] = 0;
+ i++;
+ size_t j = 0;
+ while (i < bytes_read - 1) {
+ content[j] = data[i];
+ i++;
+ j++;
+ }
+ content[j] = 0;
+ }
+ }
+ // write the data to the file
+ filesystem_write_file(filename, content, strlen(content));
+ movement_force_led_on(0, 48, 0);
+ }
char buf[14];
- movement_force_led_on(0, 48, 0);
snprintf(buf, 11, "IR%2d%c%c%c%c%c%c", bytes_read, data[0], data[1], data[2], data[3], data[4], data[5]);
watch_clear_display();
watch_display_text(WATCH_POSITION_FULL, buf);