Skip to content

Commit

Permalink
more draw primitives exposed
Browse files Browse the repository at this point in the history
  • Loading branch information
lunokjod committed Mar 5, 2024
1 parent 473df7d commit 8e1a0a2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 7 deletions.
37 changes: 35 additions & 2 deletions src/app/LuaLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ using namespace LuI;
const char * HelloworldLuaScript =
"\
log('Hello world from Lua script!')\n\
Debug()\n\
log('Fill screen with color')\n\
for i=1,3 do\n\
local RandomBGColor = random(0,0xffff)\n\
FillScreen(RandomBGColor)\n\
delay(500);\n\
end\n\
Debug()\n\
log('Fill screen with color cycle')\n\
local color=0\n\
for x=0,240 do\n\
DrawLine(x,0,x,240,RGBTft(color,color,color))\n\
color=color+1\n\
end\n\
Debug()\n\
log('Fill screen with lines random')\n\
for i=1,100 do\n\
local color = random(0,0xffff)\n\
Expand All @@ -47,15 +50,45 @@ for i=1,100 do\n\
local y1 = random(0,240)\n\
DrawLine(x0,y0,x1,y1,color)\n\
end\n\
Debug()\n\
log('Fill screen with circles random')\n\
for i=1,100 do\n\
for i=1,50 do\n\
local color = random(0,0xffff)\n\
local x0 = random(0,240)\n\
local y0 = random(0,240)\n\
local r = random(0,50)\n\
DrawCircle(x0,y0,r,color)\n\
DrawCircle(x0,y0,r,color,false)\n\
end\n\
for i=1,50 do\n\
local color = random(0,0xffff)\n\
local x0 = random(0,240)\n\
local y0 = random(0,240)\n\
local r = random(0,50)\n\
DrawCircle(x0,y0,r,color,true)\n\
end\n\
Debug()\n\
log('Fill screen with rects random')\n\
for i=1,50 do\n\
local color = random(0,0xffff)\n\
local x0 = random(0,240)\n\
local y0 = random(0,240)\n\
local x1 = random(0,240)\n\
local y1 = random(0,240)\n\
DrawRect(x0,y0,x1,y1,color,false)\n\
end\n\
for i=1,50 do\n\
local color = random(0,0xffff)\n\
local x0 = random(0,240)\n\
local y0 = random(0,240)\n\
local x1 = random(0,240)\n\
local y1 = random(0,240)\n\
DrawRect(x0,y0,x1,y1,color,true)\n\
end\n\
log('Little delay...')\n\
delay(1000)\n\
Debug()\n\
log('See you!')\n\
LaunchWatchface()\n\
";

LuaLauncher::LuaLauncher(const char * script) {
Expand Down
48 changes: 43 additions & 5 deletions src/system/lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ extern "C" {
*/


static int lua_wrapper_Debug(lua_State *lua_state) {
lRawLog("[LUA] Free System Heap: %d\n",esp_get_free_heap_size());
lRawLog("[LUA] Free Task Heap: %d\n",uxTaskGetStackHighWaterMark(NULL));
return 0;
}
static int lua_wrapper_Restart(lua_State *lua_state) {
LaunchApplication(new ShutdownApplication(true));
return 0;
Expand All @@ -69,7 +74,7 @@ extern "C" {
lua_pushnumber(lua_state, (lua_Number) millis());
return 1;
}
static int lua_wrapper_Random(lua_State *lua_state) {
static int lua_wrapper_random(lua_State *lua_state) {
long floorVal = luaL_optnumber(lua_state, 1,0.0);
long maxVal = luaL_optnumber(lua_state, 2,1.0);
lua_pushnumber(lua_state, (lua_Number) random(floorVal,maxVal));
Expand All @@ -93,11 +98,40 @@ extern "C" {
int32_t y0 = luaL_checkinteger(lua_state, 2);
int32_t r = luaL_checkinteger(lua_state, 3);
uint32_t color = luaL_checkinteger(lua_state, 4);
luaL_checktype(lua_state, 5, LUA_TBOOLEAN);
bool fill = lua_toboolean(lua_state, 5);

xSemaphoreTake( UISemaphore, LUNOKIOT_EVENT_MANDATORY_TIME_TICKS);
LunokIoTApplication * current = currentApplication;
if ( nullptr != currentApplication ) {
currentApplication->canvas->drawCircle(x0,y0,r,color);
if ( fill ) {
currentApplication->canvas->fillCircle(x0,y0,r,color);
} else {
currentApplication->canvas->drawCircle(x0,y0,r,color);
}
currentApplication->dirty=true;
}
xSemaphoreGive( UISemaphore );
return 0;
}

static int lua_wrapper_tft_drawRect(lua_State *lua_state) {
int32_t x0 = luaL_checkinteger(lua_state, 1);
int32_t y0 = luaL_checkinteger(lua_state, 2);
int32_t x1 = luaL_checkinteger(lua_state, 3);
int32_t y1 = luaL_checkinteger(lua_state, 4);
uint32_t color = luaL_checkinteger(lua_state, 5);
luaL_checktype(lua_state, 6, LUA_TBOOLEAN);
bool fill = lua_toboolean(lua_state, 6);

xSemaphoreTake( UISemaphore, LUNOKIOT_EVENT_MANDATORY_TIME_TICKS);
LunokIoTApplication * current = currentApplication;
if ( nullptr != currentApplication ) {
if ( fill ) {
currentApplication->canvas->fillRect(x0,y0,x1,y1,color);
} else {
currentApplication->canvas->drawRect(x0,y0,x1,y1,color);
}
currentApplication->dirty=true;
}
xSemaphoreGive( UISemaphore );
Expand Down Expand Up @@ -172,20 +206,24 @@ void LuaInit() {
// arduino general
lua.Lua_register("millis", &lua_wrapper_millis);
lua.Lua_register("delay", &lua_wrapper_delay);
lua.Lua_register("random", &lua_wrapper_Random);
lua.Lua_register("random", &lua_wrapper_random);

// lwatch calls
// system (lwatch) calls
lua.Lua_register("LaunchWatchface", &lua_wrapper_LaunchWatchface);
lua.Lua_register("ScreenSleep", &lua_wrapper_ScreenSleep);
lua.Lua_register("ScreenWake", &lua_wrapper_ScreenWake);
lua.Lua_register("DoSleep", &lua_wrapper_DoSleep);
lua.Lua_register("Shutdown", &lua_wrapper_Shutdown);
lua.Lua_register("Restart", &lua_wrapper_Restart);
// UI calls
lua.Lua_register("Debug", &lua_wrapper_Debug);
// draw primitives
lua.Lua_register("FillScreen", &lua_wrapper_tft_fillScreen);
lua.Lua_register("DrawLine", &lua_wrapper_tft_drawLine);
lua.Lua_register("DrawCircle", &lua_wrapper_tft_drawCircle);
lua.Lua_register("DrawRect", &lua_wrapper_tft_drawRect);
lua.Lua_register("RGBTft", &lua_wrapper_tft_rgbTFTColor);
// @TODO UI calls
// @TODO GUI calls

}
void LuaRunTask(void *data) {
Expand Down

0 comments on commit 8e1a0a2

Please sign in to comment.