123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include "serialClient.hpp"
- uint16_t len;
- uint8_t buf[6];
- int8_t readSerial() {
- len = Serial.available();
- 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, 0xa, sizeof(matrix_t));
- matrix.bytes[14] = 0x00;
- 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;
- }
|