diff --git a/einkfb.c b/einkfb.c index fdd058aae..b7784e592 100644 --- a/einkfb.c +++ b/einkfb.c @@ -225,7 +225,23 @@ static int einkSetOrientation(lua_State *L) { return luaL_error(L, "Wrong rotation mode %d given!", mode); } - /* ioctl has a different definition for rotation mode. */ + /* ioctl has a different definition for rotation mode. + * 1 + * +--------------+ + * | +----------+ | + * | | | | + * | | Freedom! | | + * | | | | + * | | | | + * 3 | | | | 2 + * | | | | + * | | | | + * | +----------+ | + * | | + * | | + * +--------------+ + * 0 + * */ if (mode == 1) mode = 2; else if (mode == 2) @@ -236,6 +252,24 @@ static int einkSetOrientation(lua_State *L) { return 0; } +static int einkGetOrientation(lua_State *L) { + int mode = 0; +#ifndef EMULATE_READER + FBInfo *fb = (FBInfo*) luaL_checkudata(L, 1, "einkfb"); + + ioctl(fb->fd, FBIO_EINK_GET_DISPLAY_ORIENTATION, &mode); + + /* adjust ioctl's rotate mode definition to KPV's + * refer to screen.lua */ + if (mode == 2) + mode = 1; + else if (mode == 1) + mode = 2; +#endif + lua_pushinteger(L, mode); + return 1; +} + static const struct luaL_Reg einkfb_func[] = { {"open", openFrameBuffer}, @@ -246,6 +280,7 @@ static const struct luaL_Reg einkfb_meth[] = { {"close", closeFrameBuffer}, {"__gc", closeFrameBuffer}, {"refresh", einkUpdate}, + {"getOrientation", einkGetOrientation}, {"setOrientation", einkSetOrientation}, {"getSize", getSize}, {NULL, NULL} diff --git a/frontend/ui/screen.lua b/frontend/ui/screen.lua index 9b4b78887..dc3e721d6 100644 --- a/frontend/ui/screen.lua +++ b/frontend/ui/screen.lua @@ -84,13 +84,8 @@ function Screen:getHeight() end function Screen:updateRotationMode() - if util.isEmulated() then -- in EMU mode always set to 0 - self.cur_rotation_mode = 0 - else - orie_fd = assert(io.open("/sys/module/eink_fb_hal_broads/parameters/bs_orientation", "r")) - updown_fd = assert(io.open("/sys/module/eink_fb_hal_broads/parameters/bs_upside_down", "r")) - self.cur_rotation_mode = orie_fd:read() + (updown_fd:read() * 2) - end + -- in EMU mode, you will always get 0 from getOrientation() + self.cur_rotation_mode = self.fb:getOrientation() end function Screen:saveCurrentBB()