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.
This commit is contained in:
Qingping Hou
2012-03-09 09:40:46 +08:00
parent 3dbf9877bc
commit d2aaf15dce
3 changed files with 8 additions and 51 deletions

View File

@@ -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

View File

@@ -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")

View File

@@ -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()