/* Generated by re2c 2.2 */
|
|
#line 1 "espurna\\led_pattern.re"
|
|
/*
|
|
|
|
LED MODULE
|
|
|
|
Copyright (C) 2020-2021 by Maxim Prokhorov <prokhorov dot max at outlook dot com>
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
// Scans input string with format
|
|
// '<on1>,<off1>,<repeats1> <on2>,<off2>,<repeats2> ...'
|
|
// And returns a list of Delay objects for the pattern
|
|
|
|
Pattern::Pattern(const char* begin, const char* end) {
|
|
char buffer[16];
|
|
|
|
const char* on1;
|
|
const char* on2;
|
|
|
|
const char* off1;
|
|
const char* off2;
|
|
|
|
const char* repeat1;
|
|
const char* repeat2;
|
|
|
|
const char* YYCURSOR { begin };
|
|
const char* YYLIMIT { end };
|
|
const char* YYMARKER;
|
|
|
|
loop:
|
|
#line 35 "espurna\\led_pattern.re.ipp"
|
|
const char *yyt1;const char *yyt2;const char *yyt3;
|
|
#line 32 "espurna\\led_pattern.re"
|
|
|
|
|
|
#line 40 "espurna\\led_pattern.re.ipp"
|
|
{
|
|
char yych;
|
|
yych = (char)*YYCURSOR;
|
|
switch (yych) {
|
|
case '\t':
|
|
case ' ': goto yy4;
|
|
case '0' ... '9':
|
|
yyt1 = YYCURSOR;
|
|
goto yy7;
|
|
default:
|
|
if (YYLIMIT <= YYCURSOR) goto yy18;
|
|
goto yy2;
|
|
}
|
|
yy2:
|
|
++YYCURSOR;
|
|
yy3:
|
|
#line 46 "espurna\\led_pattern.re"
|
|
{ return; }
|
|
#line 59 "espurna\\led_pattern.re.ipp"
|
|
yy4:
|
|
yych = (char)*++YYCURSOR;
|
|
switch (yych) {
|
|
case '\t':
|
|
case ' ': goto yy4;
|
|
default: goto yy6;
|
|
}
|
|
yy6:
|
|
#line 48 "espurna\\led_pattern.re"
|
|
{ goto loop; }
|
|
#line 70 "espurna\\led_pattern.re.ipp"
|
|
yy7:
|
|
yych = (char)*(YYMARKER = ++YYCURSOR);
|
|
switch (yych) {
|
|
case ',': goto yy8;
|
|
case '0' ... '9': goto yy10;
|
|
default: goto yy3;
|
|
}
|
|
yy8:
|
|
yych = (char)*++YYCURSOR;
|
|
switch (yych) {
|
|
case '0' ... '9':
|
|
yyt2 = YYCURSOR;
|
|
goto yy12;
|
|
default: goto yy9;
|
|
}
|
|
yy9:
|
|
YYCURSOR = YYMARKER;
|
|
goto yy3;
|
|
yy10:
|
|
yych = (char)*++YYCURSOR;
|
|
switch (yych) {
|
|
case ',': goto yy8;
|
|
case '0' ... '9': goto yy10;
|
|
default: goto yy9;
|
|
}
|
|
yy12:
|
|
yych = (char)*++YYCURSOR;
|
|
switch (yych) {
|
|
case ',': goto yy14;
|
|
case '0' ... '9': goto yy12;
|
|
default: goto yy9;
|
|
}
|
|
yy14:
|
|
yych = (char)*++YYCURSOR;
|
|
switch (yych) {
|
|
case '0' ... '9':
|
|
yyt3 = YYCURSOR;
|
|
goto yy15;
|
|
default: goto yy9;
|
|
}
|
|
yy15:
|
|
yych = (char)*++YYCURSOR;
|
|
switch (yych) {
|
|
case '0' ... '9': goto yy15;
|
|
default: goto yy17;
|
|
}
|
|
yy17:
|
|
on1 = yyt1;
|
|
off1 = yyt2;
|
|
repeat1 = yyt3;
|
|
on2 = yyt2 - 1;
|
|
off2 = yyt3 - 1;
|
|
repeat2 = YYCURSOR;
|
|
#line 50 "espurna\\led_pattern.re"
|
|
{
|
|
memcpy(buffer, on1, on2 - on1);
|
|
buffer[on2 - on1] = '\0';
|
|
espurna::duration::Milliseconds::rep on { strtoul(buffer, nullptr, 10) };
|
|
|
|
memcpy(buffer, off1, off2 - off1);
|
|
buffer[off2 - off1] = '\0';
|
|
espurna::duration::Milliseconds::rep off { strtoul(buffer, nullptr, 10) };
|
|
|
|
memcpy(buffer, repeat1, repeat2 - repeat1);
|
|
buffer[repeat2 - repeat1] = '\0';
|
|
|
|
using Repeats = unsigned long;
|
|
Repeats repeats { strtoul(buffer, nullptr, 10) };
|
|
|
|
constexpr Repeats RepeatsMax { Delay::RepeatsMax };
|
|
_delays.emplace_back(
|
|
std::min(espurna::duration::Milliseconds(on), Delay::MillisecondsMax),
|
|
std::min(espurna::duration::Milliseconds(off), Delay::MillisecondsMax),
|
|
std::min(repeats, RepeatsMax));
|
|
|
|
if (repeats) {
|
|
goto loop;
|
|
}
|
|
}
|
|
#line 150 "espurna\\led_pattern.re.ipp"
|
|
yy18:
|
|
#line 45 "espurna\\led_pattern.re"
|
|
{ return; }
|
|
#line 154 "espurna\\led_pattern.re.ipp"
|
|
}
|
|
#line 75 "espurna\\led_pattern.re"
|
|
|
|
}
|