-
-
Save tyleretters/ed521d7c8992a2cfe7fc268659e30d3c to your computer and use it in GitHub Desktop.
detecting an enc stop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
screen_dirty = true | |
function init() | |
message = {"e1 ready","e2 ready","e3 ready"} | |
counters = {} | |
waiting_indicator_max = 100 | |
wait_length_in_seconds = .5 | |
for e = 1,3 do | |
reset_counter(e) | |
end | |
indicator = metro.init() | |
indicator.time = wait_length_in_seconds / waiting_indicator_max | |
indicator.count = -1 | |
indicator.play = 1 | |
indicator.event = update_lengths | |
indicator:start() | |
clock.run(screen_redraw_clock) | |
redraw() | |
end | |
function reset_counter(e) | |
counters[e] = { | |
this_clock = nil, | |
length = 0, | |
waiting = false | |
} | |
end | |
function update_lengths() | |
for e = 1,3 do | |
if counters[e]["waiting"] then | |
counters[e]["length"] = counters[e]["length"] - 1 | |
screen_dirty = true | |
end | |
end | |
end | |
function enc(e,d) | |
if counters[e]["this_clock"] ~= nil then | |
clock.cancel(counters[e]["this_clock"]) | |
reset_counter(e) | |
end | |
message[e] = "turning: e" .. e | |
counters[e]["length"] = waiting_indicator_max | |
screen_dirty = true | |
if counters[e]["this_clock"] == nil then | |
counters[e]["this_clock"] = clock.run(wait, e) | |
end | |
end | |
function wait(e) | |
counters[e]["waiting"] = true | |
clock.sleep(wait_length_in_seconds) | |
counters[e]["waiting"] = false | |
counters[e]["this_clock"] = nil | |
message[e] = "stopped: e" .. e | |
screen_dirty = true | |
end | |
function redraw() | |
screen:clear() | |
screen.level(15) | |
for i = 1,3 do | |
local y = 22 + (12*i) | |
screen.move(0, y) | |
screen.text(message[i]) | |
screen.move(0, y + 4) | |
screen.line_rel(counters[i]["length"], 0) | |
screen.stroke() | |
end | |
screen:update() | |
end | |
function screen_redraw_clock() | |
while true do | |
if screen_dirty then | |
redraw() | |
screen_dirty = false | |
end | |
clock.sleep(1/30) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment