2013-10-18 20:38:07 +00:00
|
|
|
local KindleFrontLight = require("ui/device/kindlefrontlight")
|
|
|
|
local KoboFrontLight = require("ui/device/kobofrontlight")
|
|
|
|
local BaseFrontLight = require("ui/device/basefrontlight")
|
2013-10-22 15:11:31 +00:00
|
|
|
local Screen = require("ui/device/screen")
|
2013-10-18 20:38:07 +00:00
|
|
|
-- util
|
|
|
|
-- lfs
|
|
|
|
|
|
|
|
local Device = {
|
2012-06-13 17:52:08 +00:00
|
|
|
screen_saver_mode = false,
|
|
|
|
charging_mode = false,
|
2013-03-17 11:33:59 +00:00
|
|
|
survive_screen_saver = false,
|
|
|
|
touch_dev = nil,
|
2012-12-11 00:01:32 +00:00
|
|
|
model = nil,
|
2013-08-08 10:09:43 +00:00
|
|
|
firmware_rev = nil,
|
2013-08-12 05:11:54 +00:00
|
|
|
frontlight = nil,
|
2013-11-25 15:30:44 +00:00
|
|
|
has_no_keyboard = nil,
|
|
|
|
is_touch_device = nil,
|
|
|
|
has_front_light = nil,
|
2013-10-22 15:11:31 +00:00
|
|
|
screen = Screen
|
2013-08-12 05:11:54 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 15:11:31 +00:00
|
|
|
Screen.device = Device
|
|
|
|
|
2013-11-22 23:09:37 +00:00
|
|
|
function Set (list)
|
|
|
|
local set = {}
|
|
|
|
for _, l in ipairs(list) do set[l] = true end
|
|
|
|
return set
|
|
|
|
end
|
|
|
|
|
2012-10-14 06:22:01 +00:00
|
|
|
function Device:getModel()
|
2013-04-30 05:47:30 +00:00
|
|
|
if self.model then return self.model end
|
2013-08-22 13:10:29 +00:00
|
|
|
if util.isEmulated() then
|
2013-07-10 07:10:38 +00:00
|
|
|
self.model = "Emulator"
|
|
|
|
return self.model
|
|
|
|
end
|
2013-11-22 23:09:37 +00:00
|
|
|
self.model = nil
|
|
|
|
local kindle_sn = io.open("/proc/usid", "r")
|
|
|
|
if kindle_sn then
|
|
|
|
local kindle_devcode = string.sub(kindle_sn:read(),3,4)
|
|
|
|
kindle_sn:close()
|
|
|
|
-- NOTE: Update me when new models come out :)
|
|
|
|
local k2_set = Set { "02", "03" }
|
|
|
|
local dx_set = Set { "04", "05" }
|
|
|
|
local dxg_set = Set { "09" }
|
|
|
|
local k3_set = Set { "08", "06", "0A" }
|
|
|
|
local k4_set = Set { "0E", "23" }
|
|
|
|
local touch_set = Set { "0F", "11", "10", "12" }
|
|
|
|
local pw_set = Set { "24", "1B", "1D", "1F", "1C", "20" }
|
2013-12-01 13:06:33 +00:00
|
|
|
local pw2_set = Set { "D4", "5A", "D5", "D7", "D8", "F2" }
|
2013-11-22 23:09:37 +00:00
|
|
|
|
|
|
|
if k2_set[kindle_devcode] then
|
|
|
|
self.model = "Kindle2"
|
|
|
|
elseif dx_set[kindle_devcode] then
|
|
|
|
self.model = "Kindle2"
|
|
|
|
elseif dxg_set[kindle_devcode] then
|
|
|
|
self.model = "Kindle2"
|
|
|
|
elseif k3_set[kindle_devcode] then
|
|
|
|
self.model = "Kindle3"
|
|
|
|
elseif k4_set[kindle_devcode] then
|
|
|
|
self.model = "Kindle4"
|
|
|
|
elseif touch_set[kindle_devcode] then
|
|
|
|
self.model = "KindleTouch"
|
|
|
|
elseif pw_set[kindle_devcode] then
|
|
|
|
self.model = "KindlePaperWhite"
|
|
|
|
elseif pw2_set[kindle_devcode] then
|
2013-11-25 15:30:44 +00:00
|
|
|
self.model = "KindlePaperWhite2"
|
2012-10-14 18:32:08 +00:00
|
|
|
end
|
2013-11-22 23:09:37 +00:00
|
|
|
else
|
2013-06-11 19:54:36 +00:00
|
|
|
local kg_test_fd = lfs.attributes("/bin/kobo_config.sh")
|
2013-11-22 23:09:37 +00:00
|
|
|
if kg_test_fd then
|
2013-07-10 07:10:38 +00:00
|
|
|
local std_out = io.popen("/bin/kobo_config.sh", "r")
|
|
|
|
local codename = std_out:read()
|
|
|
|
self.model = "Kobo_" .. codename
|
2013-08-08 10:09:43 +00:00
|
|
|
local version_file = io.open("/mnt/onboard/.kobo/version", "r")
|
|
|
|
self.firmware_rev = string.sub(version_file:read(),24,28)
|
|
|
|
version_file:close()
|
2012-10-14 06:22:01 +00:00
|
|
|
end
|
|
|
|
end
|
2013-04-30 05:47:30 +00:00
|
|
|
return self.model
|
2012-10-14 06:22:01 +00:00
|
|
|
end
|
|
|
|
|
2013-08-08 10:09:43 +00:00
|
|
|
function Device:getFirmVer()
|
2013-08-12 05:11:54 +00:00
|
|
|
if not self.model then self:getModel() end
|
2013-08-08 10:09:43 +00:00
|
|
|
return self.firmware_rev
|
|
|
|
end
|
|
|
|
|
2012-06-13 17:52:08 +00:00
|
|
|
function Device:isKindle4()
|
2012-12-12 02:03:16 +00:00
|
|
|
return (self:getModel() == "Kindle4")
|
2012-06-13 13:27:38 +00:00
|
|
|
end
|
|
|
|
|
2012-06-13 17:52:08 +00:00
|
|
|
function Device:isKindle3()
|
2013-08-12 05:11:54 +00:00
|
|
|
return (self:getModel() == "Kindle3")
|
2012-06-13 13:27:38 +00:00
|
|
|
end
|
|
|
|
|
2012-06-13 17:52:08 +00:00
|
|
|
function Device:isKindle2()
|
2013-08-12 05:11:54 +00:00
|
|
|
return (self:getModel() == "Kindle2")
|
2012-06-13 13:27:38 +00:00
|
|
|
end
|
2012-06-13 17:52:08 +00:00
|
|
|
|
2013-07-10 07:10:38 +00:00
|
|
|
function Device:isKobo()
|
2013-08-12 05:11:54 +00:00
|
|
|
return string.find(self:getModel(),"Kobo_") == 1
|
2013-07-10 07:10:38 +00:00
|
|
|
end
|
|
|
|
|
2012-12-11 00:01:32 +00:00
|
|
|
function Device:hasNoKeyboard()
|
2013-11-25 15:30:44 +00:00
|
|
|
if self.has_no_keyboard ~= nil then return self.has_no_keyboard end
|
2013-10-13 07:28:40 +00:00
|
|
|
local model = self:getModel()
|
2013-11-25 15:30:44 +00:00
|
|
|
self.has_no_keyboard = (model == "KindlePaperWhite") or (model == "KindlePaperWhite2")
|
|
|
|
or (model == "KindleTouch") or self:isKobo()
|
|
|
|
return self.has_no_keyboard
|
2012-12-11 00:01:32 +00:00
|
|
|
end
|
|
|
|
|
2013-01-01 01:44:52 +00:00
|
|
|
function Device:hasKeyboard()
|
|
|
|
return not self:hasNoKeyboard()
|
|
|
|
end
|
|
|
|
|
2012-11-11 07:24:11 +00:00
|
|
|
function Device:isTouchDevice()
|
2013-11-25 15:30:44 +00:00
|
|
|
if self.is_touch_device ~= nil then return self.is_touch_device end
|
2013-08-12 05:11:54 +00:00
|
|
|
local model = self:getModel()
|
2013-11-25 15:30:44 +00:00
|
|
|
self.is_touch_device = (model == "KindlePaperWhite") or (model == "KindlePaperWhite2")
|
|
|
|
or (model == "KindleTouch") or self:isKobo() or util.isEmulated()
|
|
|
|
return self.is_touch_device
|
2012-11-11 07:24:11 +00:00
|
|
|
end
|
|
|
|
|
2013-08-05 21:06:26 +00:00
|
|
|
function Device:hasFrontlight()
|
2013-11-25 15:30:44 +00:00
|
|
|
if self.has_front_light ~= nil then return self.has_front_light end
|
2013-08-12 05:11:54 +00:00
|
|
|
local model = self:getModel()
|
2013-11-25 15:30:44 +00:00
|
|
|
self.has_front_light = (model == "KindlePaperWhite") or (model == "KindlePaperWhite2")
|
|
|
|
or (model == "Kobo_dragon") or (model == "Kobo_kraken") or (model == "Kobo_phoenix")
|
|
|
|
or util.isEmulated()
|
|
|
|
return self.has_front_light
|
2013-08-05 21:06:26 +00:00
|
|
|
end
|
|
|
|
|
2013-03-17 11:33:59 +00:00
|
|
|
function Device:setTouchInputDev(dev)
|
|
|
|
self.touch_dev = dev
|
|
|
|
end
|
|
|
|
|
|
|
|
function Device:getTouchInputDev()
|
|
|
|
return self.touch_dev
|
|
|
|
end
|
|
|
|
|
2012-06-13 17:52:08 +00:00
|
|
|
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
|
2013-10-22 15:11:31 +00:00
|
|
|
self.screen:saveCurrentBB()
|
2013-02-02 08:37:48 +00:00
|
|
|
--UIManager:show(InfoMessage:new{
|
|
|
|
--text = "Going into screensaver... ",
|
|
|
|
--timeout = 2,
|
|
|
|
--})
|
2013-01-10 06:23:11 +00:00
|
|
|
--util.sleep(1)
|
|
|
|
--os.execute("killall -cont cvm")
|
2012-06-13 17:52:08 +00:00
|
|
|
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)
|
2013-01-10 06:23:11 +00:00
|
|
|
--os.execute("killall -stop cvm")
|
2013-10-22 15:11:31 +00:00
|
|
|
self.screen:restoreFromSavedBB()
|
|
|
|
self.screen:refresh(0)
|
2013-03-17 11:33:59 +00:00
|
|
|
self.survive_screen_saver = true
|
2012-06-13 17:52:08 +00:00
|
|
|
end
|
|
|
|
self.screen_saver_mode = false
|
|
|
|
end
|
|
|
|
|
2013-09-30 20:17:22 +00:00
|
|
|
function Device:prepareSuspend() -- currently only used for kobo devices
|
2013-09-09 19:30:29 +00:00
|
|
|
local fl = self:getFrontlight()
|
|
|
|
if fl ~= nil then
|
2013-09-30 19:48:46 +00:00
|
|
|
fl.fl:sleep()
|
2013-09-09 07:04:09 +00:00
|
|
|
end
|
2013-10-22 15:11:31 +00:00
|
|
|
self.screen:refresh(0)
|
2013-09-09 10:30:27 +00:00
|
|
|
self.screen_saver_mode = true
|
2013-09-30 19:48:46 +00:00
|
|
|
end
|
|
|
|
|
2013-09-30 20:17:22 +00:00
|
|
|
function Device:Suspend() -- currently only used for kobo devices
|
2013-09-09 10:30:27 +00:00
|
|
|
os.execute("./kobo_suspend.sh")
|
2013-09-09 07:04:09 +00:00
|
|
|
end
|
|
|
|
|
2013-09-30 20:17:22 +00:00
|
|
|
function Device:Resume() -- currently only used for kobo devices
|
2013-09-09 10:30:27 +00:00
|
|
|
os.execute("echo 0 > /sys/power/state-extended")
|
2013-10-22 15:11:31 +00:00
|
|
|
self.screen:refresh(0)
|
2013-09-09 19:30:29 +00:00
|
|
|
local fl = self:getFrontlight()
|
|
|
|
if fl ~= nil then
|
2013-09-30 19:48:46 +00:00
|
|
|
fl.fl:restore()
|
2013-09-09 07:04:09 +00:00
|
|
|
end
|
2013-09-09 10:30:27 +00:00
|
|
|
self.screen_saver_mode = false
|
|
|
|
end
|
|
|
|
|
2012-06-13 17:52:08 +00:00
|
|
|
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
|
2013-10-22 15:11:31 +00:00
|
|
|
self.screen:saveCurrentBB()
|
2013-02-02 08:37:48 +00:00
|
|
|
--UIManager:show(InfoMessage:new{
|
2013-04-07 08:33:58 +00:00
|
|
|
--text = "Going into USB mode... ",
|
2013-02-02 08:37:48 +00:00
|
|
|
--timeout = 2,
|
|
|
|
--})
|
2013-02-02 06:36:29 +00:00
|
|
|
--util.sleep(1)
|
|
|
|
--os.execute("killall -cont cvm")
|
2012-06-13 17:52:08 +00:00
|
|
|
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")
|
2013-10-22 15:11:31 +00:00
|
|
|
self.screen:restoreFromSavedBB()
|
|
|
|
self.screen:refresh(0)
|
2012-06-13 17:52:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--@TODO signal filemanager for file changes 13.06 2012 (houqp)
|
|
|
|
self.charging_mode = false
|
|
|
|
end
|
2013-08-12 05:11:54 +00:00
|
|
|
|
|
|
|
function Device:getFrontlight()
|
|
|
|
if self.frontlight ~= nil then
|
|
|
|
return self.frontlight
|
|
|
|
elseif self:hasFrontlight() then
|
2013-11-25 15:30:44 +00:00
|
|
|
local model = self:getModel()
|
|
|
|
if model == "KindlePaperWhite" or model == "KindlePaperWhite2" then
|
2013-08-12 05:11:54 +00:00
|
|
|
self.frontlight = KindleFrontLight
|
|
|
|
elseif self:isKobo() then
|
|
|
|
self.frontlight = KoboFrontLight
|
2013-08-22 13:10:29 +00:00
|
|
|
else -- emulated FrontLight
|
|
|
|
self.frontlight = BaseFrontLight
|
2013-08-12 05:11:54 +00:00
|
|
|
end
|
2013-08-22 13:10:29 +00:00
|
|
|
self.frontlight:init()
|
2013-08-12 05:11:54 +00:00
|
|
|
end
|
|
|
|
return self.frontlight
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return Device
|