From 319826c3855913a62586d2e7af1d4abf0ba3150d Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 9 Mar 2012 18:34:56 +0800 Subject: [PATCH] mod: screen rotation implemented by ioctl Now you get a instance rotate :) With only one bug. I have to restore to previous rotation state of the native system after exists. Because the native system does poll the new rotation state that changed by ioctl. Currently, I don't know how to force the native system to detect the changes. --- einkfb.c | 24 ++++++++++++++++++++++++ keys.lua | 31 +++++++++++++++++-------------- reader.lua | 5 +++++ screen.lua | 27 ++++++++++++++------------- unireader.lua | 7 ++----- 5 files changed, 62 insertions(+), 32 deletions(-) diff --git a/einkfb.c b/einkfb.c index 77cb5c867..4abb81b23 100644 --- a/einkfb.c +++ b/einkfb.c @@ -180,6 +180,29 @@ static int einkUpdate(lua_State *L) { return 0; } +/* NOTICE!!! You must close and reopen framebuffer after called this method. + * Otherwise, screen resolution will not be updated! */ +static int einkSetOrientation(lua_State *L) { +#ifndef EMULATE_READER + FBInfo *fb = (FBInfo*) luaL_checkudata(L, 1, "einkfb"); + int mode = luaL_optint(L, 2, 0); + + if (mode < 0 || mode > 3) { + return luaL_error(L, "Wrong rotation mode %d given!", mode); + } + + /* ioctl has a different definition for rotation mode. */ + if (mode == 1) + mode = 2; + else if (mode == 2) + mode = 1; + + ioctl(fb->fd, FBIO_EINK_SET_DISPLAY_ORIENTATION, mode); +#endif + return 0; +} + + static const struct luaL_reg einkfb_func[] = { {"open", openFrameBuffer}, {NULL, NULL} @@ -189,6 +212,7 @@ static const struct luaL_reg einkfb_meth[] = { {"close", closeFrameBuffer}, {"__gc", closeFrameBuffer}, {"refresh", einkUpdate}, + {"setOrientation", einkSetOrientation}, {"getSize", getSize}, {NULL, NULL} }; diff --git a/keys.lua b/keys.lua index d6a3854af..cc630f09e 100644 --- a/keys.lua +++ b/keys.lua @@ -196,9 +196,9 @@ function adjustKeyEvents(ev) -- adjust five way key according to rotation mode local code = ev.code - if Screen.cur_rotation_mode == 1 then + if Screen.cur_rotation_mode == 0 then return code - elseif Screen.cur_rotation_mode == 2 then + elseif Screen.cur_rotation_mode == 1 then if code == KEY_FW_UP then return KEY_FW_RIGHT elseif code == KEY_FW_RIGHT then @@ -210,19 +210,19 @@ function adjustKeyEvents(ev) else return code end + elseif Screen.cur_rotation_mode == 2 then + if code == KEY_FW_UP then + return KEY_FW_DOWN + elseif code == KEY_FW_RIGHT then + return KEY_FW_LEFT + elseif code == KEY_FW_DOWN then + return KEY_FW_UP + elseif code == KEY_FW_LEFT then + return KEY_FW_RIGHT + else + return code + end elseif Screen.cur_rotation_mode == 3 then - if code == KEY_FW_UP then - return KEY_FW_DOWN - elseif code == KEY_FW_RIGHT then - return KEY_FW_LEFT - elseif code == KEY_FW_DOWN then - return KEY_FW_UP - elseif code == KEY_FW_LEFT then - return KEY_FW_RIGHT - else - return code - end - elseif Screen.cur_rotation_mode == 4 then if code == KEY_FW_UP then return KEY_FW_LEFT elseif code == KEY_FW_RIGHT then @@ -235,4 +235,7 @@ function adjustKeyEvents(ev) return code end end + -- This should not happen. + print("# Unrecognizable rotation mode "..Screen.cur_rotation_mode.."!") + return nil end diff --git a/reader.lua b/reader.lua index 27ab1d335..ae48c575e 100755 --- a/reader.lua +++ b/reader.lua @@ -114,6 +114,7 @@ fb = einkfb.open("/dev/fb0") width, height = fb:getSize() -- read current rotation mode Screen:updateRotationMode() +origin_rotation_mode = Screen.cur_rotation_mode -- set up reader's setting: font reader_settings = DocSettings:open(".reader") @@ -158,6 +159,10 @@ end reader_settings:savesetting("cfont", FontChooser.cfont) reader_settings:close() +-- @TODO dirty workaround, find a way to force native system poll +-- screen orientation and upside down mode 09.03 2012 +fb:setOrientation(origin_rotation_mode) + input.closeAll() --os.execute('test -e /proc/keypad && echo "send '..KEY_HOME..'" > /proc/keypad ') if optarg["d"] ~= "emu" then diff --git a/screen.lua b/screen.lua index db5ccf4fe..d587166d6 100644 --- a/screen.lua +++ b/screen.lua @@ -21,53 +21,54 @@ Codes for rotation modes: 1 for no rotation, 2 for landscape with bottom on the right side of screen, etc. - 3 + 2 +--------------+ | +----------+ | | | | | | | Freedom! | | | | | | | | | | - 4 | | | | 2 + 3 | | | | 1 | | | | | | | | | +----------+ | | | | | +--------------+ - 1 + 0 --]] Screen = { - rotation_modes = {"Up","Right","Down","Left"}, - cur_rotation_mode = 1, + cur_rotation_mode = 0, } -- @ orien: 1 for clockwise rotate, -1 for anti-clockwise function Screen:screenRotate(orien) if orien == "clockwise" then - orien = 1 - elseif orien == "anticlockwise" then orien = -1 + elseif orien == "anticlockwise" then + orien = 1 else return end + self.cur_rotation_mode = (self.cur_rotation_mode + orien) % 4 + fb:setOrientation(self.cur_rotation_mode) fb:close() - self.cur_rotation_mode = (self.cur_rotation_mode-1 + 1*orien)%4 + 1 - local mode = self.rotation_modes[self.cur_rotation_mode] - os.execute("lipc-send-event -r 3 com.lab126.hal orientation"..mode) + --local mode = self.rotation_modes[self.cur_rotation_mode] + --self.cur_rotation_mode = (self.cur_rotation_mode-1 + 1*orien)%4 + 1 + --os.execute("lipc-send-event -r 3 com.lab126.hal orientation"..mode) fb = einkfb.open("/dev/fb0") end function Screen:updateRotationMode() - if KEY_FW_DOWN == 116 then -- in EMU mode always set to 1 - self.cur_rotation_mode = 1 + if KEY_FW_DOWN == 116 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) + 1 + self.cur_rotation_mode = orie_fd:read() + (updown_fd:read() * 2) end end diff --git a/unireader.lua b/unireader.lua index 2394f270a..ac777cf5f 100644 --- a/unireader.lua +++ b/unireader.lua @@ -544,10 +544,7 @@ end function UniReader:screenRotate(orien) Screen:screenRotate(orien) width, height = fb:getSize() - self:clearcache() - --@TODO write a sleep in util module to replace it 08.03 2012 - os.execute("sleep 2") self:goto(self.pageno) end @@ -714,13 +711,13 @@ function UniReader:inputloop() end elseif ev.code == KEY_J then if Keys.shiftmode then - self:screenRotate("anticlockwise") + self:screenRotate("clockwise") else self:setrotate( self.globalrotate + 10 ) end elseif ev.code == KEY_K then if Keys.shiftmode then - self:screenRotate("clockwise") + self:screenRotate("anticlockwise") else self:setrotate( self.globalrotate - 10 ) end