implement set_rotation and draw_line

This commit is contained in:
arne 2025-10-04 20:14:41 +02:00
commit 474aa42696
2 changed files with 37 additions and 0 deletions

View file

@ -39,7 +39,29 @@ static int get_height (lua_State *L) {
return 1;
}
static int set_rotation (lua_State *L) {
char *rotation = lua_tostring(L, -1);
luaL_argcheck(L, strcmp(rotation, "landscape") == 0 || strcmp(rotation, "portrait") == 0, -1, "expected `rotation` to be either 'landscape' or 'portrait'");
epd_set_rotation(strcmp(rotation, "landscape") == 0 ? EPD_ROT_LANDSCAPE : EPD_ROT_PORTRAIT);
return 0;
}
static int draw_line (lua_State *L) {
int x1, y1, x2, y2, color;
int isnum;
x1 = lua_tonumberx(L, -5, &isnum);
luaL_argcheck(L, isnum, -5, "expected `x1` to be a number");
y1 = lua_tonumberx(L, -4, &isnum);
luaL_argcheck(L, isnum, -4, "expected `y1` to be a number");
x2 = lua_tonumberx(L, -3, &isnum);
luaL_argcheck(L, isnum, -3, "expected `x2` to be a number");
y2 = lua_tonumberx(L, -2, &isnum);
luaL_argcheck(L, isnum, -2, "expected `y2` to be a number");
color = lua_tonumberx(L, -1, &isnum);
luaL_argcheck(L, isnum && color >= 0 && color < 256, -1, "expected `color` to be a number within [0, 255]");
epd_draw_line(x1, y1, x2, y2, color, fb);
return 0;
}
@ -58,6 +80,7 @@ static const struct luaL_Reg paper[] = {
{"get_width", get_width},
{"get_height", get_height},
{"set_rotation", set_rotation},
{"draw_line", draw_line},
{"update", update},