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

@ -1,6 +1,20 @@
local paper = require('paper') local paper = require('paper')
paper.init() paper.init()
paper.clear()
print( print(
'width: ' .. paper.get_width(), 'width: ' .. paper.get_width(),
'height: ' .. paper.get_height() 'height: ' .. paper.get_height()
) )
pad_w = paper.get_width() * 0.12
pad_h = paper.get_height() * 0.12
for i = 0, 15 do
for j = 1, 4 do
paper.draw_line(paper.get_height() / 16 * i, j, paper.get_width(), paper.get_height() - 4 + j, i * 16)
end
-- paper.draw_line(0, paper.get_height(), paper.get_width(), paper.get, i * 16)
end
paper.update()

View file

@ -39,7 +39,29 @@ static int get_height (lua_State *L) {
return 1; 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) { 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; return 0;
} }
@ -58,6 +80,7 @@ static const struct luaL_Reg paper[] = {
{"get_width", get_width}, {"get_width", get_width},
{"get_height", get_height}, {"get_height", get_height},
{"set_rotation", set_rotation},
{"draw_line", draw_line}, {"draw_line", draw_line},
{"update", update}, {"update", update},