serialClient.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "serialClient.hpp"
  2. int8_t readSerial() {
  3. uint16_t len = Serial.available();
  4. uint8_t buf[6];
  5. if(len < N_ROWS*N_COLS+1) {
  6. return -1;
  7. }
  8. wdt_reset();
  9. Serial.readBytes(buf, 1);
  10. if(buf[0] != 'A') {
  11. if(buf[0] == 'C') {
  12. Serial.readBytes(buf, 6);
  13. if(memcmp(buf, "ONFIG:", 6) == 0) {
  14. len = Serial.readBytesUntil(',', config.ssid, sizeof(config.ssid)-1);
  15. config.ssid[len] = '\0';
  16. len = Serial.readBytesUntil(',', config.pass, sizeof(config.pass)-1);
  17. config.pass[len] = '\0';
  18. len = Serial.readBytesUntil(',', config.host, sizeof(config.host)-1);
  19. config.host[len] = '\0';
  20. config.port = Serial.parseInt();
  21. if(config.port > 0) {
  22. wdt_reset();
  23. memset(matrix.bytes, 0xF, sizeof(matrix_t));
  24. matrix.bytes[14] = 0x0F;
  25. config_save();
  26. printf("Config saved.\n");
  27. for(;;);
  28. return 0;
  29. } else {
  30. return 3;
  31. }
  32. } else {
  33. return 2;
  34. }
  35. } else {
  36. printf("A\n");
  37. return 1;
  38. }
  39. }
  40. len = Serial.readBytes(matrix.bytes, N_ROWS*N_COLS);
  41. sprintf((char*)buf, "%d\n", len);
  42. Serial.write(buf, 3);
  43. return 0;
  44. }