diff --git a/frontend/ui/device.lua b/frontend/ui/device.lua index f480ac46e..813fc1520 100644 --- a/frontend/ui/device.lua +++ b/frontend/ui/device.lua @@ -3,6 +3,34 @@ Device = { charging_mode = false, } +function Device:getModel() + local std_out = io.popen("grep 'MX' /proc/cpuinfo | cut -d':' -f2 | awk {'print $2'}", "r") + local cpu_mod = std_out:read() + if not cpu_mod then + local ret = os.execute("grep 'Hardware : Mario Platform' /proc/cpuinfo", "r") + if ret ~= 0 then + return nil + else + return "KindleDXG" + end + end + if cpu_mod == "MX50" then + local f = lfs.attributes("/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity") + if f then + return "KindlePaperWhite" + else + return "Kindle4" + end + elseif cpu_mod == "MX35" then + -- check if we are running on Kindle 3 (additional volume input) + return "Kindle3" + elseif cpu_mod == "MX3" then + return "Kindle2" + else + return nil + end +end + function Device:isKindle4() re_val = os.execute("cat /proc/cpuinfo | grep MX50") if re_val == 0 then diff --git a/frontend/ui/inputevent.lua b/frontend/ui/inputevent.lua index 3f2674d69..3dad29fbe 100644 --- a/frontend/ui/inputevent.lua +++ b/frontend/ui/inputevent.lua @@ -230,21 +230,27 @@ function Input:init() self.event_map = self.sdl_event_map else input.open("fake_events") + local dev_mod = Device:getModel() + input.open("/dev/input/event0") - input.open("/dev/input/event1") - - -- check if we are running on Kindle 3 (additional volume input) - local f=lfs.attributes("/dev/input/event2") - if f then - input.open("/dev/input/event2") - if Device:isKindle3() then - print("Auto-detected Kindle 3") - end - end - - if Device:isKindle4() then + if dev_mod ~= "KindlePaperWhite" then + -- we don't have event1 in KindlePaperWhite + input.open("/dev/input/event1") + elseif dev_mod == "KindlePaperWhite" then + print("Auto-detected Kindle PaperWhite") + elseif dev_mod == "Kindle4" then print("Auto-detected Kindle 4") self:adjustKindle4EventMap() + elseif dev_mod == "Kindle3" then + input.open("/dev/input/event2") + print("Auto-detected Kindle 3") + elseif dev_mod == "KindleDXG" then + print("Auto-detected Kindle DXG") + elseif dev_mod == "Kindle2" then + print("Auto-detected Kindle 2") + else + print("Not supported device model!") + os.exit(-1) end end end diff --git a/input.c b/input.c index 06e1ce785..ca5a0a915 100644 --- a/input.c +++ b/input.c @@ -77,7 +77,7 @@ static int openInputDevice(lua_State *L) { return luaL_error(L, "no free slot for new input device <%s>", inputdevice); } - if(!strcmp("slider",inputdevice)) { + if(!strcmp("fake_events", inputdevice)) { /* special case: the power slider */ int pipefd[2]; int childpid;