Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions grid_common/grid_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ void grid_lua_start_vm(struct grid_lua_model* lua) {
grid_lua_dostring(lua, GRID_LUA_FNC_G_ELEMENTNAME_source);
grid_lua_dostring(lua, GRID_LUA_FNC_G_MAPSAT_source);
grid_lua_dostring(lua, GRID_LUA_FNC_G_SIGN_source);
grid_lua_dostring(lua, GRID_LUA_FNC_G_TIMER_source);
grid_lua_dostring(lua, GRID_LUA_FNC_G_SEGCALC_source);
// grid_lua_dostring(lua, GRID_LUA_FNC_G_TOML_source);
grid_lua_dostring(lua, "midi_fifo = {}");
Expand Down
25 changes: 25 additions & 0 deletions grid_common/grid_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1525,3 +1525,28 @@ void grid_port_process_ui_UNSAFE(struct grid_ui_model* ui) {

grid_ui_busy_semaphore_release(ui);
}

void grid_port_process_timer_UNSAFE(struct grid_ui_model* ui) {
grid_ui_busy_semaphore_lock(ui);

grid_lua_clear_stdo(&grid_lua_state);

grid_lua_dostring(&grid_lua_state, "check_timers()");

char* stdo = grid_lua_get_output_string(&grid_lua_state);

if (strlen(stdo) > 0) {

struct grid_msg_packet response;
grid_msg_packet_init(&grid_msg_state, &response, GRID_PARAMETER_GLOBAL_POSITION, GRID_PARAMETER_GLOBAL_POSITION);

response.body_length += sprintf(response.body, "%s", stdo);

grid_msg_packet_close(&grid_msg_state, &response);
grid_transport_send_msg_packet_to_all(&grid_transport_state, &response);

grid_lua_clear_stdo(&grid_lua_state);
}

grid_ui_busy_semaphore_release(ui);
}
2 changes: 2 additions & 0 deletions grid_common/grid_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,6 @@ void grid_port_process_ui_local_UNSAFE(struct grid_ui_model* ui);

void grid_port_process_ui_UNSAFE(struct grid_ui_model* ui);

void grid_port_process_timer_UNSAFE(struct grid_ui_model* ui);

#endif /* GRID_UI_H */
3 changes: 3 additions & 0 deletions grid_common/lua_src/lua_source_collection.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef LUA_SOURCE_COLLECTION_H_INCLUDED
#define LUA_SOURCE_COLLECTION_H_INCLUDED

#include "timer.h"
#define GRID_LUA_FNC_G_TIMER_source grid_lua_src_timer_lua

#include "lookup.h"
#define GRID_LUA_FNC_G_LOOKUP_source grid_lua_src_lookup_lua
#define GRID_LUA_FNC_G_LOOKUP_short "glut"
Expand Down
34 changes: 34 additions & 0 deletions grid_common/lua_src/timer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- Updated infinite loop for the `setTimeout` example
local timers = {}
local timersNextId = 0

function set_timeout(callback, delay)
local timerId = timersNextId
timersNextId = timersNextId + 1
local targetTime = os.clock() + delay
timers[timerId] = {id = timerId, time = targetTime, interval = delay, callback = callback}
return timerId
end

function clear_timeout(timerId)
if timers[timerId] then
timers[timerId] = nil
end
end

function check_timers()
local now = os.clock()
for timerId, timer in pairs(timers) do
if now >= timer.time then
--print("Servicing timer"..timerId.." now")
local retrigger = timer.callback(timer)
if retrigger == true then
--print("Retriggering timer"..timerId.." now")
timers[timerId].time = timers[timerId].time + timers[timerId].interval
else
--print("Deleting timer"..timerId.." now")
timers[timerId] = nil
end
end
end
end
3 changes: 2 additions & 1 deletion grid_esp/components/grid_esp32_port/grid_esp32_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ void grid_utask_process_ui(struct grid_utask_timer* timer) {
}

if (grid_ui_event_count_istriggered(&grid_ui_state) > 0) {

grid_port_process_ui_UNSAFE(&grid_ui_state);
} else {
grid_port_process_timer_UNSAFE(&grid_ui_state);
}
}

Expand Down
8 changes: 8 additions & 0 deletions grid_esp/sdkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,14 @@ CONFIG_WIFI_PROV_STA_ALL_CHANNEL_SCAN=y
# TinyUSB Stack
#
CONFIG_TINYUSB_DEBUG_LEVEL=1
CONFIG_TINYUSB_RHPORT_FS=y

#
# TinyUSB DCD
#
# CONFIG_TINYUSB_MODE_SLAVE is not set
CONFIG_TINYUSB_MODE_DMA=y
# end of TinyUSB DCD

#
# TinyUSB task configuration
Expand Down
3 changes: 2 additions & 1 deletion grid_make/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ void grid_utask_process_ui(struct grid_utask_timer* timer) {
}

if (grid_ui_event_count_istriggered(&grid_ui_state) > 0) {

grid_port_process_ui_UNSAFE(&grid_ui_state);
} else {
grid_port_process_timer_UNSAFE(&grid_ui_state);
}
}

Expand Down