esp32-lilygo-t5/main/paper.h

95 lines
2.4 KiB
C

#ifndef PAPER_H_
#define PAPER_H_
#include <lua.h>
#include <lauxlib.h>
#include <epdiy.h>
#include "departure_mono_11.h"
#include "departure_mono_22.h"
#define WAVEFORM EPD_BUILTIN_WAVEFORM
EpdiyHighlevelState hl;
uint8_t* fb;
static int init (lua_State *L) {
epd_init(&epd_board_lilygo_t5_47, &ED097TC2, EPD_LUT_64K);
// epd_set_vcom(1560);
hl = epd_hl_init(WAVEFORM);
epd_set_rotation(EPD_ROT_LANDSCAPE);
fb = epd_hl_get_framebuffer(&hl);
return 0;
}
static int clear (lua_State *L){
epd_clear();
return 0;
}
static int get_width (lua_State *L) {
int width = epd_rotated_display_width();
lua_pushnumber(L, width);
return 1;
}
static int get_height (lua_State *L) {
int height = epd_rotated_display_height();
lua_pushnumber(L, height);
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;
}
static int update (lua_State *L) {
int temperature = 25;
epd_poweron();
epd_hl_update_screen(&hl, MODE_GC16, temperature);
epd_poweroff();
return 0;
}
static const struct luaL_Reg paper[] = {
{"init", init},
{"clear", clear},
{"get_width", get_width},
{"get_height", get_height},
{"set_rotation", set_rotation},
{"draw_line", draw_line},
{"update", update},
{NULL, NULL},
};
int luaopen_paper (lua_State *L) {
luaL_newlib(L, paper);
return 1;
}
#endif // PAPER_H_