Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.6 KiB

  1. /*
  2. LED MODULE
  3. Copyright (C) 2020 by Maxim Prokhorov <prokhorov dot max at outlook dot com>
  4. */
  5. #pragma once
  6. #include "led.h"
  7. #include <cstring>
  8. // Scans input string with format
  9. // '<on1>,<off1>,<repeats1> <on2>,<off2>,<repeats2> ...'
  10. // Directly changing `led.pattern.delays` contents
  11. void _ledLoadPattern(led_t& led, const char* input) {
  12. char buffer[16];
  13. const char* d1;
  14. const char* d2;
  15. const char* d3;
  16. const char* p = input;
  17. const char* marker;
  18. led.pattern.delays.clear();
  19. loop:
  20. /*!stags:re2c format = 'const char *@@;'; */
  21. /*!re2c
  22. re2c:define:YYCTYPE = char;
  23. re2c:define:YYCURSOR = p;
  24. re2c:define:YYMARKER = marker;
  25. re2c:yyfill:enable = 0;
  26. re2c:yych:conversion = 1;
  27. re2c:indent:top = 1;
  28. end = "\x00";
  29. wsp = [ \t]+;
  30. num = [0-9]+;
  31. * { return; }
  32. wsp { goto loop; }
  33. @d1 num [,] @d2 num [,] @d3 num {
  34. unsigned long on;
  35. unsigned long off;
  36. unsigned char repeats;
  37. memcpy(buffer, d1, int(d2 - d1));
  38. buffer[int(d2 - d1 - 1)] = '\0';
  39. on = strtoul(buffer, nullptr, 10);
  40. memcpy(buffer, d2, int(d3 - d2));
  41. buffer[int(d3 - d2 - 1)] = '\0';
  42. off = strtoul(buffer, nullptr, 10);
  43. memcpy(buffer, d3, int(p - d3));
  44. buffer[int(p - d3)] = '\0';
  45. repeats = strtoul(buffer, nullptr, 10);
  46. led.pattern.delays.emplace_back(
  47. on, off, repeats
  48. );
  49. goto loop;
  50. }
  51. */
  52. }