Introduction
The rockev library allows some simple event driven programming.
This library allows events to be subscribed / recieved within a lua script,
most events in Rockbox are synchronous so flags are set and later checked by a
secondary thread to make them (
semi)-asynchronous
Caveats
- The main lua state is halted till the lua callback(s) are finished Yielding will not return control to your script from within a callback
- Subsequent callbacks may be delayed by the code in your lua callback
- You must store the value returned from the event_register function, you might get away with it for a bit but, garbage collection will destroy your callback eventually if you do not store the event
- You only get one cb per event type ["action", "button", "custom", "playback", "timer"] (Re-registration of an event overwrites the previous one)
Usage
Events |
action |
button |
custom |
playback |
timer |
Functions |
Arguments |
Notes |
register |
("event", cb_function, [timeout / flags]) |
cb_function([id] [, data]) ... end |
suspend |
(["event"/nil][true/false]) |
passing nil affects all events |
trigger |
("event", [true/false], [id]) |
CUSTOM_EVENT must be unset manually |
unregister |
(evX) |
Unregistering is not necessary before script end |
register
local function act_function(id, data)
if id ~= 0 then rb.splash(rb.HZ, "Action Recieved")
end
local eva = rockev.register("action", act_function, rb.HZ / 10)
local function btn_function(id, data)
if id ~= 0 then rb.splash(rb.HZ, "Button Pressed")
end
local evb = rockev.register("button", btn_function, rb.HZ / 10)
local evc = rockev.register("custom", rb.lcd_update)
local function pb_function(id, data)
if id == (rb.PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE) then rb.splash(rb.HZ, "PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE") end
if id == (rb.PLAYBACK_EVENT_START_PLAYBACK) then rb.splash(rb.HZ, "PLAYBACK_EVENT_START_PLAYBACK") end
if id == (rb.PLAYBACK_EVENT_TRACK_BUFFER) then rb.splash(rb.HZ, "PLAYBACK_EVENT_TRACK_BUFFER") end
if id == (rb.PLAYBACK_EVENT_TRACK_CHANGE) then rb.splash(rb.HZ, "PLAYBACK_EVENT_TRACK_CHANGE") end
if id == (rb.PLAYBACK_EVENT_TRACK_FINISH) then rb.splash(rb.HZ, "PLAYBACK_EVENT_TRACK_FINISH") end
if id == (rb.PLAYBACK_EVENT_TRACK_SKIP) then rb.splash(rb.HZ, "PLAYBACK_EVENT_TRACK_SKIP") end
end
local evp = rockev.register("playback", pb_function, [flags]) -- see source for available flags
local function tmr_function(id, data)
rb.splash(rb.HZ, "Timer Fired")
end
local evt = rockev.register("timer", tmr_function, rb.HZ * 10)
Copyright © by the contributing authors.