add: adjustFWKey(code)

adjustFWKey() will change code event for five way keys
according to current rotation mode. Add this to the
input.waitForEvent loop and your UI can navigate properly
in different rotation mode.
pull/2/merge
Qingping Hou 12 years ago
parent 599e0fd1df
commit 262b8113f7

@ -51,33 +51,6 @@ function FileChooser:setPath(newPath)
return true
end
function FileChooser:rotationMode()
--[[
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
---------
| |
| |
| |
3 | | 1
| |
| |
| |
---------
0
--]]
if KEY_FW_DOWN == 116 then
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 FileChooser:choose(ypos, height)
local perpage = math.floor(height / self.spacing) - 1
@ -151,30 +124,11 @@ function FileChooser:choose(ypos, height)
end
local ev = input.waitForEvent()
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
ev.code = adjustFWKey(ev.code)
if ev.code == KEY_FW_UP then
if self:rotationMode() == 0 then
prevItem()
elseif self:rotationMode() == 2 then
nextItem()
end
prevItem()
elseif ev.code == KEY_FW_DOWN then
if self:rotationMode() == 0 then
nextItem()
elseif self:rotationMode() == 2 then
prevItem()
end
elseif ev.code == KEY_FW_LEFT then
if self:rotationMode() == 1 then
prevItem()
elseif self:rotationMode() == 3 then
nextItem()
end
elseif ev.code == KEY_FW_RIGHT then
if self:rotationMode() == 1 then
nextItem()
elseif self:rotationMode() == 3 then
prevItem()
end
nextItem()
elseif ev.code == KEY_F then
FontChooser:init()
newfont = FontChooser:choose(0, height)

@ -119,6 +119,7 @@ function FontChooser:choose(ypos, height)
local ev = input.waitForEvent()
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
ev.code = adjustFWKey(ev.code)
if ev.code == KEY_FW_UP then
prevItem()
elseif ev.code == KEY_FW_DOWN then

@ -131,3 +131,75 @@ function set_emu_keycodes()
KEY_VPLUS = 95 -- F11
KEY_VMINUS = 96 -- F12
end
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
-----------
| ------- |
| | | |
| | | |
| | | |
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 adjustFWKey(code)
if getRotationMode() == 0 then
return code
elseif getRotationMode() == 1 then
if code == KEY_FW_UP then
return KEY_FW_RIGHT
elseif code == KEY_FW_RIGHT then
return KEY_FW_DOWN
elseif code == KEY_FW_DOWN then
return KEY_FW_LEFT
elseif code == KEY_FW_LEFT then
return KEY_FW_UP
else
return code
end
elseif getRotationMode() == 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 getRotationMode() == 3 then
if code == KEY_FW_UP then
return KEY_FW_LEFT
elseif code == KEY_FW_RIGHT then
return KEY_FW_UP
elseif code == KEY_FW_DOWN then
return KEY_FW_RIGHT
elseif code == KEY_FW_LEFT then
return KEY_FW_DOWN
else
return code
end
end
end

Loading…
Cancel
Save