serialClient.cpp 1.2 KB

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