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.

70 lines
1.5 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. auto& pattern = led.pattern;
  19. pattern.delays.clear();
  20. loop:
  21. /*!stags:re2c format = 'const char *@@;'; */
  22. /*!re2c
  23. re2c:define:YYCTYPE = char;
  24. re2c:define:YYCURSOR = p;
  25. re2c:define:YYMARKER = marker;
  26. re2c:yyfill:enable = 0;
  27. re2c:yych:conversion = 1;
  28. re2c:indent:top = 1;
  29. end = "\x00";
  30. wsp = [ \t]+;
  31. num = [0-9]+;
  32. * { return; }
  33. wsp { goto loop; }
  34. @d1 num [,] @d2 num [,] @d3 num {
  35. unsigned long on;
  36. unsigned long off;
  37. unsigned char repeats;
  38. memcpy(buffer, d1, int(d2 - d1));
  39. buffer[int(d2 - d1 - 1)] = '\0';
  40. on = strtoul(buffer, nullptr, 10);
  41. memcpy(buffer, d2, int(d3 - d2));
  42. buffer[int(d3 - d2 - 1)] = '\0';
  43. off = strtoul(buffer, nullptr, 10);
  44. memcpy(buffer, d3, int(p - d3));
  45. buffer[int(p - d3)] = '\0';
  46. repeats = strtoul(buffer, nullptr, 10);
  47. pattern.delays.emplace_back(on, off, repeats);
  48. goto loop;
  49. }
  50. */
  51. }