diff --git a/examples/arduino/EspLinkSample/EspLinkSample.ino b/examples/arduino/EspLinkSample/EspLinkSample.ino index ab672b0..c776994 100644 --- a/examples/arduino/EspLinkSample/EspLinkSample.ino +++ b/examples/arduino/EspLinkSample/EspLinkSample.ino @@ -3,9 +3,11 @@ #define LED_PIN 13 -int8_t blinking = 0; -int8_t frequency = 10; +int8_t blinking = 0; +int8_t frequency = 10; +uint8_t pattern = 2; uint16_t elapse = 100; +uint16_t elapse_delta = 200; uint32_t next_ts = 0; void ledHtmlCallback(WebServerCommand command, char * data, int dataLen); @@ -38,6 +40,7 @@ void loop() { digitalWrite(LED_PIN, !digitalRead(LED_PIN)); next_ts += elapse; + elapse = elapse_delta - elapse; } } } @@ -66,12 +69,41 @@ void ledHtmlCallback(WebServerCommand command, char * data, int dataLen) if( strcmp_P(data, PSTR("frequency") ) == 0 ) { frequency = webServer.getArgInt(); - elapse = 1000 / frequency; + digitalWrite(LED_PIN, false); + elapse_delta = 2000 / frequency; + elapse = pattern * elapse_delta / 4; + } + else if( strcmp_P(data, PSTR("pattern") ) == 0 ) + { + char * arg = webServer.getArgString(); + + if( strcmp_P(arg, PSTR("25_75")) == 0 ) + pattern = 1; + else if( strcmp_P(arg, PSTR("50_50")) == 0 ) + pattern = 2; + else if( strcmp_P(arg, PSTR("75_25")) == 0 ) + pattern = 3; + + digitalWrite(LED_PIN, false); + elapse = pattern * elapse_delta / 4; } break; case LOAD: - webServer.setArgNum(2); + webServer.setArgNum(3); webServer.setArgInt("frequency", frequency); + + switch(pattern) + { + case 1: + webServer.setArgStringP("pattern", PSTR("25_75")); + break; + case 2: + webServer.setArgStringP("pattern", PSTR("50_50")); + break; + case 3: + webServer.setArgStringP("pattern", PSTR("75_25")); + break; + } case REFRESH: if( command == REFRESH ) webServer.setArgNum(1); diff --git a/examples/arduino/EspLinkSample/WebServer.cpp b/examples/arduino/EspLinkSample/WebServer.cpp index 5e100d5..7aab354 100644 --- a/examples/arduino/EspLinkSample/WebServer.cpp +++ b/examples/arduino/EspLinkSample/WebServer.cpp @@ -182,3 +182,8 @@ int32_t WebServer::getArgInt() return (int32_t)atol(value_ptr); } +char * WebServer::getArgString() +{ + return value_ptr; +} + diff --git a/examples/arduino/EspLinkSample/WebServer.h b/examples/arduino/EspLinkSample/WebServer.h index 6d70817..28365be 100644 --- a/examples/arduino/EspLinkSample/WebServer.h +++ b/examples/arduino/EspLinkSample/WebServer.h @@ -77,6 +77,7 @@ class WebServer void setArgStringP(const char * name, const char * value); int32_t getArgInt(); + char * getArgString(); }; #endif /* WEB_SERVER_H */