Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SUKU self:draw_pixel implemented #147

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions grid_common/grid_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@
#define GRID_LUA_FNC_G_GUI_DRAW_PIXEL_fnptr l_grid_gui_draw_pixel
#define GRID_LUA_FNC_G_GUI_DRAW_PIXEL_usage "grid_gui_draw_pixel(x, y, {r, g, b}) Draws a pixel at (x, y) with the specified 8-bit color channels."

#define GRID_LUA_FNC_G_GUI_DRAW_PIXEL2_short "ggdp2"
#define GRID_LUA_FNC_G_GUI_DRAW_PIXEL2_human "gui_draw_pixel2"
#define GRID_LUA_FNC_G_GUI_DRAW_PIXEL2_fnptr l_grid_gui_draw_pixel2
#define GRID_LUA_FNC_G_GUI_DRAW_PIXEL2_usage "grid_gui_draw_pixel(screen_index, x, y, {r, g, b}) Draws a pixel at (x, y) with the specified 8-bit color channels."

#define GRID_LUA_FNC_G_GUI_DRAW_LINE_short "ggdl"
#define GRID_LUA_FNC_G_GUI_DRAW_LINE_human "gui_draw_line"
#define GRID_LUA_FNC_G_GUI_DRAW_LINE_fnptr l_grid_gui_draw_line
Expand Down
3 changes: 3 additions & 0 deletions grid_common/grid_ui_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ void grid_ui_element_lcd_template_parameter_init(struct grid_ui_template_buffer*
int32_t* template_parameter_list = buf->template_parameter_list;

template_parameter_list[GRID_LUA_FNC_L_ELEMENT_INDEX_index] = element_index;
template_parameter_list[GRID_LUA_FNC_L_SCREEN_INDEX_index] = element_index % 2; // TODO:implement proper logic here
template_parameter_list[GRID_LUA_FNC_L_SCREEN_WIDTH_index] = 320;
template_parameter_list[GRID_LUA_FNC_L_SCREEN_HEIGHT_index] = 240;
}
35 changes: 34 additions & 1 deletion grid_common/grid_ui_lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,50 @@ void grid_ui_element_lcd_template_parameter_init(struct grid_ui_template_buffer*
#define GRID_LUA_FNC_L_ELEMENT_INDEX_short "ind"
#define GRID_LUA_FNC_L_ELEMENT_INDEX_human "element_index"

#define GRID_LUA_FNC_L_LIST_length 1
#define GRID_LUA_FNC_L_SCREEN_INDEX_index 1
#define GRID_LUA_FNC_L_SCREEN_INDEX_helper "1"
#define GRID_LUA_FNC_L_SCREEN_INDEX_short "lin"
#define GRID_LUA_FNC_L_SCREEN_INDEX_human "screen_index"

#define GRID_LUA_FNC_L_SCREEN_WIDTH_index 2
#define GRID_LUA_FNC_L_SCREEN_WIDTH_helper "2"
#define GRID_LUA_FNC_L_SCREEN_WIDTH_short "lsw"
#define GRID_LUA_FNC_L_SCREEN_WIDTH_human "screen_width"

#define GRID_LUA_FNC_L_SCREEN_HEIGHT_index 3
#define GRID_LUA_FNC_L_SCREEN_HEIGHT_helper "3"
#define GRID_LUA_FNC_L_SCREEN_HEIGHT_short "lsh"
#define GRID_LUA_FNC_L_SCREEN_HEIGHT_human "screen_height"

#define GRID_LUA_FNC_L_LIST_length 4

#define GRID_LUA_FNC_L_DRAW_PIXEL_short "ldp"
#define GRID_LUA_FNC_L_DRAW_PIXEL_human "draw_pixel"


// LCD init function
#define GRID_LUA_L_META_init \
"lcd_meta = { __index = { \
\
" GRID_LUA_FNC_L_ELEMENT_INDEX_short "=function (self,a) return " \
"gtv(self.index, " GRID_LUA_FNC_L_ELEMENT_INDEX_helper ", a) end, \
" GRID_LUA_FNC_L_SCREEN_INDEX_short "=function (self,a) return " \
"gtv(self.index, " GRID_LUA_FNC_L_SCREEN_INDEX_helper ", a) end, \
" GRID_LUA_FNC_L_SCREEN_WIDTH_short "=function (self,a) return " \
"gtv(self.index, " GRID_LUA_FNC_L_SCREEN_WIDTH_helper ", a) end, \
" GRID_LUA_FNC_L_SCREEN_HEIGHT_short "=function (self,a) return " \
"gtv(self.index, " GRID_LUA_FNC_L_SCREEN_HEIGHT_helper ", a) end, \
\
" GRID_LUA_FNC_A_INIT_short " = function (self) print('undefined action') end, \
\
\
" GRID_LUA_FNC_L_DRAW_PIXEL_short " =function (self, ...) " \
"local screen_index = " \
"self" \
":" GRID_LUA_FNC_L_SCREEN_INDEX_short "() " \
"print('screen_index: ', screen_index) " GRID_LUA_FNC_G_GUI_DRAW_PIXEL2_short "(screen_indexm ...)" \
"end, \
\
gtt = function (self,a) " GRID_LUA_FNC_G_TIMER_START_short "(self.index,a) end,\
gtp = function (self) " GRID_LUA_FNC_G_TIMER_STOP_short "(self.index) end,\
get = function (self,a) " GRID_LUA_FNC_G_EVENT_TRIGGER_short "(self.index,a) end\
Expand Down
31 changes: 31 additions & 0 deletions grid_esp/components/grid_esp32_lcd/grid_lua_api_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,37 @@ void grid_gui_lua_draw_demo(lua_State* L, uint8_t loopcounter) {
// grid_gui_draw_polygon_filled(gui, x_points, y_points, num_points, color);
}

int l_grid_gui_draw_pixel2(lua_State* L) {

// grid_platform_printf("TEST GUI: l_grid_gui_draw_pixel\r\n");

int screen_index = luaL_checknumber(L, 1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: Code Duplication
reduced similar code in: l_grid_gui_draw_pixel


int x = luaL_checknumber(L, 2);
int y = luaL_checknumber(L, 3);
// Optional color parameter
if (lua_gettop(L) >= 4) {
luaL_checktype(L, 4, LUA_TTABLE);
lua_rawgeti(L, 4, 1);
int r = luaL_checknumber(L, -1);
lua_rawgeti(L, 4, 2);
int g = luaL_checknumber(L, -1);
lua_rawgeti(L, 4, 3);
int b = luaL_checknumber(L, -1);
// Use r, g, b values to set color
// grid_platform_printf("Received color: R=%d, G=%d, B=%d\n", r, g, b);

// use select the screen using the proper grid_gui_state
if (screen_index == 0) {
grid_gui_draw_pixel(&grid_gui_state, x, y, grid_gui_color_from_rgb(r, g, b));

} else {
grid_gui_draw_pixel(&grid_gui_state, x, y, grid_gui_color_from_rgb(r, g, b));
}
}
return 0;
}

int l_grid_gui_draw_pixel(lua_State* L) {

// grid_platform_printf("TEST GUI: l_grid_gui_draw_pixel\r\n");
Expand Down
1 change: 1 addition & 0 deletions grid_esp/components/grid_esp32_lcd/grid_lua_api_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

void grid_gui_lua_draw_demo(lua_State* L, uint8_t loopcounter);

int l_grid_gui_draw_pixel2(lua_State* L);
int l_grid_gui_draw_pixel(lua_State* L);
int l_grid_gui_draw_line(lua_State* L);
int l_grid_gui_draw_rectangle(lua_State* L);
Expand Down
1 change: 1 addition & 0 deletions grid_esp/main/grid_fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ char grid_doublebuffer_rx_memory_array[2][GRID_DOUBLE_BUFFER_RX_SIZE] = {0};
#include "grid_lua_api_gui.h"
#include "grid_ui_lcd.h"

// TODO: LCD META IS NEVER USED
void grid_lua_ui_init_tek1(struct grid_lua_model* lua) {

// define encoder_init_function
Expand Down
Loading