From 2d104d7792de160c2ca6465bd04b67132ec72697 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 13 Jun 2012 21:27:38 +0800 Subject: [PATCH] adjust keycodes for k4 & add device.lua --- frontend/ui/device.lua | 26 ++++++++++++++++++++++++++ frontend/ui/inputevent.lua | 28 +++++++++++++++++++++------- frontend/ui/ui.lua | 1 + 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 frontend/ui/device.lua diff --git a/frontend/ui/device.lua b/frontend/ui/device.lua new file mode 100644 index 000000000..2aacc05de --- /dev/null +++ b/frontend/ui/device.lua @@ -0,0 +1,26 @@ +function util.isKindle4() + re_val = os.execute("cat /proc/cpuinfo | grep MX50") + if re_val == 0 then + return true + else + return false + end +end + +function util.isKindle3() + re_val = os.execute("cat /proc/cpuinfo | grep MX35") + if re_val == 0 then + return true + else + return false + end +end + +function util.isKindle2() + re_val = os.execute("cat /proc/cpuinfo | grep MX3") + if re_val == 0 then + return true + else + return false + end +end diff --git a/frontend/ui/inputevent.lua b/frontend/ui/inputevent.lua index 898ef64bf..125344e54 100644 --- a/frontend/ui/inputevent.lua +++ b/frontend/ui/inputevent.lua @@ -1,4 +1,5 @@ require "ui/event" +require "ui/device" -- constants from EV_KEY = 1 @@ -110,6 +111,7 @@ Input = { [44] = "Z", [45] = "X", [46] = "C", [47] = "V", [48] = "B", [49] = "N", [50] = "M", [52] = ".", [53] = "/", -- only KDX [28] = "Enter", + [29] = "ScreenKB", -- K[4] [42] = "Shift", [56] = "Alt", [57] = " ", @@ -118,12 +120,12 @@ Input = { [92] = "Press", -- KDX [94] = "Sym", -- KDX [98] = "Home", -- KDX - [102] = "Home", -- K[3] + [102] = "Home", -- K[3] & k[4] [104] = "LPgBack", -- K[3] only - [103] = "Up", -- K[3] + [103] = "Up", -- K[3] & k[4] [105] = "Left", [106] = "Right", - [108] = "Down", -- K[3] + [108] = "Down", -- K[3] & k[4] [109] = "RPgBack", [114] = "VMinus", [115] = "VPlus", @@ -132,11 +134,11 @@ Input = { [124] = "RPgFwd", -- KDX [126] = "Sym", -- K[3] [139] = "Menu", - [158] = "Back", -- K[3] + [158] = "Back", -- K[3] & K[4] [190] = "AA", -- K[3] - [191] = "RPgFwd", -- K[3] + [191] = "RPgFwd", -- K[3] & k[4] [193] = "LPgFwd", -- K[3] only - [194] = "Press", -- K[3] + [194] = "Press", -- K[3] & k[4] }, sdl_event_map = { [10] = "1", [11] = "2", [12] = "3", [13] = "4", [14] = "5", [15] = "6", [16] = "7", [17] = "8", [18] = "9", [19] = "0", @@ -229,12 +231,24 @@ function Input:init() -- check if we are running on Kindle 3 (additional volume input) local f=lfs.attributes("/dev/input/event2") if f then - print("Auto-detected Kindle 3") input.open("/dev/input/event2") + if util.isKindle3() then + print("Auto-detected Kindle 3") + end + end + + if util.isKindle4() then + print("Auto-detected Kindle 4") + self:adjustKindle4EventMap() end end end +function Input:adjustKindle4EventMap() + self.event_map[193] = "LPgBack" + self.event_map[104] = "LPgFwd" +end + function Input:waitEvent(timeout_us, timeout_s) -- wrapper for input.waitForEvents that will retry for some cases local ok, ev diff --git a/frontend/ui/ui.lua b/frontend/ui/ui.lua index d7de574d4..44e5732da 100644 --- a/frontend/ui/ui.lua +++ b/frontend/ui/ui.lua @@ -1,4 +1,5 @@ require "ui/geometry" +require "ui/device" require "ui/inputevent" require "ui/widget" require "ui/screen"