From d2aaf15dce328402eee84d4ed282a6b07ac9a5f3 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 9 Mar 2012 09:40:46 +0800 Subject: [PATCH] add: screen.lua * move rotation mode to global variable, now check rotation with Screen.cur_rotation_mode * move screenRotate to screen module so other UIs can use it. --- keys.lua | 43 ++++--------------------------------------- reader.lua | 3 +++ unireader.lua | 13 +------------ 3 files changed, 8 insertions(+), 51 deletions(-) diff --git a/keys.lua b/keys.lua index f7c6fe25a..d6a3854af 100644 --- a/keys.lua +++ b/keys.lua @@ -178,41 +178,6 @@ function set_emu_keycodes() KEY_VMINUS = 96 -- F12 end ---@TODO rotation does not fit in key module, we should move it --- to some other module in the future. 08.03 2012 -rotation_mode = {"Up","Right","Down","Left"} - -function getRotationMode() - --[[ - return code for four kinds of rotation mode: - - 0 for no rotation, - 1 for landscape with bottom on the right side of screen, etc. - - 2 - +--------------+ - | +----------+ | - | | | | - | | Freedom! | | - | | | | - | | | | - 3 | | | | 1 - | | | | - | | | | - | +----------+ | - | | - | | - +--------------+ - 0 - --]] - if KEY_FW_DOWN == 116 then -- in EMU mode always return 0 - return 0 - end - 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")) - mode = orie_fd:read() + (updown_fd:read() * 2) - return mode -end function adjustKeyEvents(ev) if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then @@ -231,9 +196,9 @@ function adjustKeyEvents(ev) -- adjust five way key according to rotation mode local code = ev.code - if getRotationMode() == 0 then + if Screen.cur_rotation_mode == 1 then return code - elseif getRotationMode() == 1 then + elseif Screen.cur_rotation_mode == 2 then if code == KEY_FW_UP then return KEY_FW_RIGHT elseif code == KEY_FW_RIGHT then @@ -245,7 +210,7 @@ function adjustKeyEvents(ev) else return code end - elseif getRotationMode() == 2 then + elseif Screen.cur_rotation_mode == 3 then if code == KEY_FW_UP then return KEY_FW_DOWN elseif code == KEY_FW_RIGHT then @@ -257,7 +222,7 @@ function adjustKeyEvents(ev) else return code end - elseif getRotationMode() == 3 then + elseif Screen.cur_rotation_mode == 4 then if code == KEY_FW_UP then return KEY_FW_LEFT elseif code == KEY_FW_RIGHT then diff --git a/reader.lua b/reader.lua index 9d07f9d92..27ab1d335 100755 --- a/reader.lua +++ b/reader.lua @@ -22,6 +22,7 @@ require "pdfreader" require "djvureader" require "filechooser" require "settings" +require "screen" -- option parsing: longopts = { @@ -111,6 +112,8 @@ end fb = einkfb.open("/dev/fb0") width, height = fb:getSize() +-- read current rotation mode +Screen:updateRotationMode() -- set up reader's setting: font reader_settings = DocSettings:open(".reader") diff --git a/unireader.lua b/unireader.lua index ef6adeffa..ab04978be 100644 --- a/unireader.lua +++ b/unireader.lua @@ -528,18 +528,7 @@ end -- @ orien: 1 for clockwise rotate, -1 for anti-clockwise function UniReader:screenRotate(orien) - if orien == "clockwise" then - orien = 1 - elseif orien == "anticlockwise" then - orien = -1 - else - return - end - - fb:close() - local mode = rotation_mode[(getRotationMode()+1*orien)%4 + 1] - os.execute("lipc-send-event -r 3 com.lab126.hal orientation"..mode) - fb = einkfb.open("/dev/fb0") + Screen:screenRotate(orien) width, height = fb:getSize() self:clearcache()