2
0
mirror of https://github.com/koreader/koreader synced 2024-11-13 19:11:25 +00:00
koreader/frontend/ui/device.lua

135 lines
3.3 KiB
Lua
Raw Normal View History

Device = {
screen_saver_mode = false,
charging_mode = false,
model = nil,
}
2012-10-14 06:22:01 +00:00
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
2012-10-14 18:32:08 +00:00
local ret = os.execute("grep 'Hardware : Mario Platform' /proc/cpuinfo", "r")
if ret ~= 0 then
return nil
else
return "KindleDXG"
end
2012-10-14 06:22:01 +00:00
end
if cpu_mod == "MX50" then
2012-12-08 06:06:47 +00:00
-- for KPW
local pw_test_fd = lfs.attributes("/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity")
-- for KT
local kt_test_fd = lfs.attributes("/sys/devices/platform/whitney-button")
-- another special file for KT is Neonode zForce touchscreen:
-- /sys/devices/platform/zforce.0/
if pw_test_fd then
2012-10-14 06:22:01 +00:00
return "KindlePaperWhite"
2012-12-08 06:06:47 +00:00
elseif kt_test_fd then
return "KindleTouch"
2012-10-14 06:22:01 +00:00
else
return "Kindle4"
end
elseif cpu_mod == "MX35" then
-- check if we are running on Kindle 3 (additional volume input)
2012-10-14 18:32:08 +00:00
return "Kindle3"
2012-10-14 06:22:01 +00:00
elseif cpu_mod == "MX3" then
return "Kindle2"
else
return nil
end
end
function Device:isKindle4()
2012-12-12 02:03:16 +00:00
return (self:getModel() == "Kindle4")
end
function Device:isKindle3()
re_val = os.execute("cat /proc/cpuinfo | grep MX35")
if re_val == 0 then
return true
else
return false
end
end
function Device:isKindle2()
re_val = os.execute("cat /proc/cpuinfo | grep MX3")
if re_val == 0 then
return true
else
return false
end
end
function Device:hasNoKeyboard()
if not self.model then
self.model = self:getModel()
end
return self:isTouchDevice() or (self.model == "Kindle4")
end
2013-01-01 01:44:52 +00:00
function Device:hasKeyboard()
return not self:hasNoKeyboard()
end
function Device:isTouchDevice()
if not self.model then
self.model = self:getModel()
end
return (self.model == "KindlePaperWhite") or (self.model == "KindleTouch") or util.isEmulated()
end
function Device:intoScreenSaver()
--os.execute("echo 'screensaver in' >> /mnt/us/event_test.txt")
if self.charging_mode == false and self.screen_saver_mode == false then
Screen:saveCurrentBB()
2013-02-02 08:37:48 +00:00
--UIManager:show(InfoMessage:new{
--text = "Going into screensaver... ",
--timeout = 2,
--})
--util.sleep(1)
--os.execute("killall -cont cvm")
self.screen_saver_mode = true
end
end
function Device:outofScreenSaver()
--os.execute("echo 'screensaver out' >> /mnt/us/event_test.txt")
if self.screen_saver_mode == true and self.charging_mode == false then
2013-02-02 08:37:48 +00:00
-- wait for native system update screen before we recover saved
-- Blitbuffer.
util.usleep(1500000)
--os.execute("killall -stop cvm")
Screen:restoreFromSavedBB()
2013-02-02 06:36:29 +00:00
Screen:refresh(0)
end
self.screen_saver_mode = false
end
function Device:usbPlugIn()
--os.execute("echo 'usb in' >> /mnt/us/event_test.txt")
if self.charging_mode == false and self.screen_saver_mode == false then
Screen:saveCurrentBB()
2013-02-02 08:37:48 +00:00
--UIManager:show(InfoMessage:new{
--text = "Going into USB mode... ",
--timeout = 2,
--})
2013-02-02 06:36:29 +00:00
--util.sleep(1)
--os.execute("killall -cont cvm")
end
self.charging_mode = true
end
function Device:usbPlugOut()
--os.execute("echo 'usb out' >> /mnt/us/event_test.txt")
if self.charging_mode == true and self.screen_saver_mode == false then
2013-02-02 06:36:29 +00:00
--util.usleep(1500000)
--os.execute("killall -stop cvm")
Screen:restoreFromSavedBB()
2013-02-02 06:36:29 +00:00
Screen:refresh(0)
end
--@TODO signal filemanager for file changes 13.06 2012 (houqp)
self.charging_mode = false
end