diff --git a/assets/epaper.lua b/assets/epaper.lua index 9c8e95e..e7f13ce 100644 --- a/assets/epaper.lua +++ b/assets/epaper.lua @@ -2,6 +2,7 @@ local math = require('math') local paper = require('paper') paper.init() +paper.set_rotation("portrait") paper.clear() local width = paper.get_width() diff --git a/main/paper.h b/main/paper.h index b262fd5..c283f56 100644 --- a/main/paper.h +++ b/main/paper.h @@ -10,6 +10,11 @@ #define WAVEFORM EPD_BUILTIN_WAVEFORM +// this file defines lua bindings to the epdiy e-ink library. +// +// see https://epdiy.readthedocs.io/en/latest/api.html for epdiy documentation. +// see https://www.lua.org/manual/5.4/manual.html for lua documentation. + EpdiyHighlevelState hl; uint8_t* fb; @@ -41,11 +46,42 @@ static int get_height (lua_State *L) { 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); + luaL_argcheck( + L, + strcmp(rotation, "landscape") == 0 || + strcmp(rotation, "portrait") == 0 || + strcmp(rotation, "inverted_landscape") == 0 || + strcmp(rotation, "inverted_portrait") == 0, + -1, + "expected `rotation` to be either 'landscape', 'portrait', 'inverted_landscape' or 'inverted_portrait'" + ); + epd_set_rotation( + strcmp(rotation, "landscape") == 0 + ? EPD_ROT_LANDSCAPE + : strcmp(rotation, "portrait") == 0 + ? EPD_ROT_PORTRAIT + : strcmp(rotation, "inverted_landscape") == 0 + ? EPD_ROT_INVERTED_LANDSCAPE + : EPD_ROT_INVERTED_PORTRAIT + ); return 0; } +static int get_rotation (lua_State *L) { + int rotation = epd_get_rotation(); + lua_pushstring( + L, + rotation == EPD_ROT_LANDSCAPE + ? "landscape" + : rotation == EPD_ROT_PORTRAIT + ? "portrait" + : rotation == EPD_ROT_INVERTED_LANDSCAPE + ? "inverted_landscape" + : "inverted_portrait" + ); + return 1; +} + static int draw_pixel (lua_State *L) { int x, y, color; int isnum; @@ -260,6 +296,7 @@ static const struct luaL_Reg paper[] = { {"get_height", get_height}, {"set_rotation", set_rotation}, + {"get_rotation", get_rotation}, {"draw_pixel", draw_pixel}, {"draw_line", draw_line},