From 4df8d9b7946e688468b9e7d54fa00f9e447e9286 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Wed, 23 Nov 2022 02:20:01 -0500 Subject: [PATCH] allow to control the modes --- flash.sh | 2 +- sources/_init.lua | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/flash.sh b/flash.sh index 9b7bd03..389bd92 100755 --- a/flash.sh +++ b/flash.sh @@ -12,7 +12,7 @@ function reset_flash() { esptool.py --port /dev/ttyUSB0 write_flash -fm dio 0x10000 firmware/0x10000.bin } -reset_flash +#reset_flash CONN_DELAY=1000 diff --git a/sources/_init.lua b/sources/_init.lua index 770294a..a808b4c 100644 --- a/sources/_init.lua +++ b/sources/_init.lua @@ -7,7 +7,6 @@ lights = {} lights[green] = false lights[red] = false - function display_table(t) print("table") for k, v in pairs(t) do @@ -30,7 +29,8 @@ function make_timer(pin, interval, initial_duty_cycle) local direction = 1 local delay = 0 print("timer created!") - return tmr.create():alarm(interval, tmr.ALARM_AUTO, function() + local timer = tmr.create() + timer:register(interval, tmr.ALARM_AUTO, function() if delay > 0 then delay = delay - 1 return @@ -54,6 +54,7 @@ function make_timer(pin, interval, initial_duty_cycle) lights[pin] = true pwm.setduty(pin, duty_cycle_t) end) + return timer end pwm.setup(green, 500, 0) @@ -61,8 +62,15 @@ pwm.setup(red, 500, 0) pwm.start(green) pwm.start(red) -green_timer = make_timer(green, 50, 1) -red_timer = make_timer(red, 50, 1023) +timers = {} +timers[green] = make_timer(green, 50, 1) +timers[red] = make_timer(red, 50, 1023) +timers[green]:start() +timers[red]:start() + +function fade_light(pin) + timers[pin]:start() +end function turn_light_on(pin, duty_cycle) if not lights[pin] then @@ -114,8 +122,6 @@ end function extract_formdata(s) local cgi = {} for name, value in string.gmatch(s, "([^&=]+)=([^&=]+)") do - name = name - value = value cgi[name] = value end return cgi @@ -131,6 +137,10 @@ function get_info(group) return result .. "" end +function compose(f, g) + return function(x) f(g(x)) end +end + function gen_select(name, id, options) local result = "