Skip to content

Commit

Permalink
more tft primitives exposed (buffered)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunokjod committed Mar 5, 2024
1 parent 8934ddc commit a64bcce
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/app/LuaLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ for i=1,3 do\n\
delay(500);\n\
end\n\
Debug()\n\
log('Draw strings random')\n\
for i=1,100 do\n\
local color = random(0,0xffff)\n\
local x0 = random(0,240)\n\
local y0 = random(0,240)\n\
local tsize = random(1,8)\n\
SetTextColor(color)\n\
SetTextSize(tsize)\n\
DrawText(x0,y0,\"hello world!\")\n\
end\n\
Debug()\n\
log('Fill screen with color cycle')\n\
local color=0\n\
for x=0,240 do\n\
Expand Down Expand Up @@ -85,7 +96,7 @@ for i=1,50 do\n\
DrawRect(x0,y0,x1,y1,color,true)\n\
end\n\
log('Little delay...')\n\
delay(1000)\n\
-- delay(1000)\n\
Debug()\n\
log('See you!')\n\
LaunchWatchface()\n\
Expand Down
57 changes: 52 additions & 5 deletions src/system/lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ extern "C" {
static int lua_wrapper_tft_fillScreen(lua_State *lua_state) {
uint16_t color = luaL_checkinteger(lua_state, 1);
xSemaphoreTake( UISemaphore, LUNOKIOT_EVENT_MANDATORY_TIME_TICKS);
LunokIoTApplication * current = currentApplication;
//LunokIoTApplication * current = currentApplication;
if ( nullptr != currentApplication ) {
currentApplication->canvas->fillSprite(color);
currentApplication->dirty=true;
}
UINextTimeout = millis()+UITimeout; // disable screen timeout
xSemaphoreGive( UISemaphore );
return 0;
}
Expand All @@ -102,7 +103,7 @@ extern "C" {
bool fill = lua_toboolean(lua_state, 5);

xSemaphoreTake( UISemaphore, LUNOKIOT_EVENT_MANDATORY_TIME_TICKS);
LunokIoTApplication * current = currentApplication;
//LunokIoTApplication * current = currentApplication;
if ( nullptr != currentApplication ) {
if ( fill ) {
currentApplication->canvas->fillCircle(x0,y0,r,color);
Expand All @@ -111,6 +112,48 @@ extern "C" {
}
currentApplication->dirty=true;
}
UINextTimeout = millis()+UITimeout; // disable screen timeout
xSemaphoreGive( UISemaphore );
return 0;
}

static int lua_wrapper_tft_setTextColor(lua_State *lua_state) {
uint32_t color = luaL_checkinteger(lua_state, 1);
xSemaphoreTake( UISemaphore, LUNOKIOT_EVENT_MANDATORY_TIME_TICKS);
//LunokIoTApplication * current = currentApplication;
if ( nullptr != currentApplication ) {
currentApplication->canvas->setTextColor(color);
}
xSemaphoreGive( UISemaphore );
return 0;
}

static int lua_wrapper_tft_setTextSize(lua_State *lua_state) {
uint32_t tsize = luaL_checkinteger(lua_state, 1);
xSemaphoreTake( UISemaphore, LUNOKIOT_EVENT_MANDATORY_TIME_TICKS);
//LunokIoTApplication * current = currentApplication;
if ( nullptr != currentApplication ) {
currentApplication->canvas->setTextSize(tsize);
}
xSemaphoreGive( UISemaphore );
return 0;
}

static int lua_wrapper_tft_drawText(lua_State *lua_state) {
int32_t x0 = luaL_checkinteger(lua_state, 1);
int32_t y0 = luaL_checkinteger(lua_state, 2);
const char * what = luaL_checkstring(lua_state, 3);
xSemaphoreTake( UISemaphore, LUNOKIOT_EVENT_MANDATORY_TIME_TICKS);
//LunokIoTApplication * current = currentApplication;
if ( nullptr != currentApplication ) {
/* @TODO
currentApplication->canvas->setFreeFont(&FreeMonoBold9pt7b);
currentApplication->canvas->setTextDatum(BC_DATUM);
*/
currentApplication->canvas->drawString(what,x0,y0);
currentApplication->dirty=true;
}
UINextTimeout = millis()+UITimeout; // disable screen timeout
xSemaphoreGive( UISemaphore );
return 0;
}
Expand All @@ -125,7 +168,7 @@ extern "C" {
bool fill = lua_toboolean(lua_state, 6);

xSemaphoreTake( UISemaphore, LUNOKIOT_EVENT_MANDATORY_TIME_TICKS);
LunokIoTApplication * current = currentApplication;
//LunokIoTApplication * current = currentApplication;
if ( nullptr != currentApplication ) {
if ( fill ) {
currentApplication->canvas->fillRect(x0,y0,x1,y1,color);
Expand All @@ -134,6 +177,7 @@ extern "C" {
}
currentApplication->dirty=true;
}
UINextTimeout = millis()+UITimeout; // disable screen timeout
xSemaphoreGive( UISemaphore );
return 0;
}
Expand All @@ -146,11 +190,12 @@ extern "C" {
uint32_t color = luaL_checkinteger(lua_state, 5);

xSemaphoreTake( UISemaphore, LUNOKIOT_EVENT_MANDATORY_TIME_TICKS);
LunokIoTApplication * current = currentApplication;
//LunokIoTApplication * current = currentApplication;
if ( nullptr != currentApplication ) {
currentApplication->canvas->drawLine(x0,y0,x1,y1,color);
currentApplication->dirty=true;
}
UINextTimeout = millis()+UITimeout; // disable screen timeout
xSemaphoreGive( UISemaphore );
return 0;
}
Expand Down Expand Up @@ -221,6 +266,9 @@ void LuaInit() {
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("SetTextColor", &lua_wrapper_tft_setTextColor);
lua.Lua_register("SetTextSize", &lua_wrapper_tft_setTextSize);
lua.Lua_register("DrawText", &lua_wrapper_tft_drawText);
lua.Lua_register("RGBTft", &lua_wrapper_tft_rgbTFTColor);
// @TODO UI calls
// @TODO GUI calls
Expand Down Expand Up @@ -252,6 +300,5 @@ void LuaRun(const String LuaProgram, LuaCallback callback, void *payload) {
mypkg->payload=payload;
mypkg->id = RunningLuaScripts;
mypkg->program=new String(LuaProgram);

xTaskCreatePinnedToCore(LuaRunTask, "luaScr", LUNOKIOT_TASK_STACK_SIZE, mypkg, LUAPRIORITY, NULL,LUACORE);
}
2 changes: 1 addition & 1 deletion tool/.buildCount.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
26477
26479

0 comments on commit a64bcce

Please sign in to comment.