Implement get_rotation
this also stops the automatic call to `.set_rotation` in `.init`; the default rotation is landscape.
This commit is contained in:
parent
a51f98b44f
commit
8d460d4b04
2 changed files with 40 additions and 2 deletions
41
main/paper.h
41
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},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue