From 262b8113f741d028a9c1cd6ad64a04173368a690 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 17 Feb 2012 14:52:54 +0800 Subject: [PATCH] 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. --- filechooser.lua | 52 +++-------------------------------- fontchooser.lua | 1 + keys.lua | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 49 deletions(-) diff --git a/filechooser.lua b/filechooser.lua index ae5104c82..369125944 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -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) diff --git a/fontchooser.lua b/fontchooser.lua index 920a32ec8..6dfa86abc 100644 --- a/fontchooser.lua +++ b/fontchooser.lua @@ -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 diff --git a/keys.lua b/keys.lua index b757dd5b0..eef4f37a3 100644 --- a/keys.lua +++ b/keys.lua @@ -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