/***************************************************************************** */
+/* USB Uart */
+
+volatile uint8_t usb_logs = 0;
+volatile uint8_t usb_send_config = 0;
+
+enum comm_states {
+ Idle = 0, /* Waiting for next command */
+ Command, /* Received command, waiting for command param */
+ Config, /* Received config command, receiving configuration */
+};
+
/* Rx interrupt handler for system configuration over USB */
void config_rx(uint8_t c)
{
- /* FAN control */
- if (c == 'f') {
- gpio_set(fan_ctrl);
- } else {
- gpio_clear(fan_ctrl);
+ static uint8_t comm_state = 0;
+
+ if (comm_state == Command) {
+ /* Handle command value */
+ comm_state = Idle;
+ return;
+ }
+
+ if (comm_state == Config) {
+ /* Receive new config */
+ /* Check received config checksum */
+ /* If config received, burn to flash and reset */
+ comm_state = Idle;
+ return;
+ }
+
+ /* Idle case */
+ switch (c) {
+ /* FAN control */
+ case 'F':
+ gpio_set(fan_ctrl);
+ break;
+ case 'f':
+ gpio_clear(fan_ctrl);
+ break;
+ /* Activate USB Logs */
+ case 'L':
+ usb_logs = 1;
+ break;
+ case 'l':
+ usb_logs = 0;
+ break;
+ /* Enter command mode */
+ case 'a':
+ comm_state = Command;
+ break;
+ /* Enter config mode */
+ case 'C':
+ comm_state = Config;
+ break;
+ /* Get config */
+ case 'g':
+ usb_send_config = 1;
+ break;
+ default:
}
}
#include "data.h"
/***************************************************************************** */
+extern volatile uint8_t usb_logs;
+extern volatile uint8_t usb_send_config;
+
/* Rx interrupt handler for system configuration over USB */
void config_rx(uint8_t c);
slave_send_data();
/* Data Log */
- if (1) {
+ if (usb_logs == 1) {
external_disable |= linky_test;
uprintf(UART0, "#%c:%d:%d:%d:%d:%d:%d:",
mode, loop++, solar_prod_value, home_conso_value,
msg = NULL;
}
}
+ if (usb_send_config == 1) {
+ char* conf = (char*)&sc_conf;
+ serial_write(UART0, "C", 1);
+ serial_write(UART0, conf, sizeof(struct scialys_config));
+ usb_send_config = 0;
+ }
}
return 0;
}