12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #include "serialClient.hpp"
- int8_t readSerial() {
- uint16_t len = Serial.available();
- uint8_t buf[6];
- if(len < N_ROWS*N_COLS+1) {
- return -1;
- }
- wdt_reset();
-
- Serial.readBytes(buf, 1);
- if(buf[0] != 'A') {
- if(buf[0] == 'C') {
- Serial.readBytes(buf, 6);
- if(memcmp(buf, "ONFIG:", 6) == 0) {
- len = Serial.readBytesUntil(',', config.ssid, sizeof(config.ssid)-1);
- config.ssid[len] = '\0';
- len = Serial.readBytesUntil(',', config.pass, sizeof(config.pass)-1);
- config.pass[len] = '\0';
- len = Serial.readBytesUntil(',', config.host, sizeof(config.host)-1);
- config.host[len] = '\0';
- config.port = Serial.parseInt();
- if(config.port > 0) {
- wdt_reset();
- memset(matrix.bytes, 0xF, sizeof(matrix_t));
- matrix.bytes[14] = 0x0F;
- config_save();
- printf("Config saved.\n");
- for(;;);
- return 0;
- } else {
- return 3;
- }
- } else {
- return 2;
- }
- } else {
- printf("A\n");
- return 1;
- }
- }
- len = Serial.readBytes(matrix.bytes, N_ROWS*N_COLS);
- sprintf((char*)buf, "%d\n", len);
- Serial.write(buf, 3);
- return 0;
- }
|