2014-07-15 08:23:38 +00:00
|
|
|
local AndroidPowerd = require("ui/device/androidpowerd")
|
2014-01-04 13:38:07 +00:00
|
|
|
local KindlePowerD = require("ui/device/kindlepowerd")
|
2014-08-14 11:49:42 +00:00
|
|
|
local isAndroid, android = pcall(require, "android")
|
2014-01-04 13:38:07 +00:00
|
|
|
local KoboPowerD = require("ui/device/kobopowerd")
|
|
|
|
local BasePowerD = require("ui/device/basepowerd")
|
2014-08-14 11:49:42 +00:00
|
|
|
local lfs = require("libs/libkoreader-lfs")
|
2013-10-22 15:11:31 +00:00
|
|
|
local Screen = require("ui/device/screen")
|
2014-05-15 08:07:38 +00:00
|
|
|
local util = require("ffi/util")
|
2014-06-02 15:48:34 +00:00
|
|
|
local ffi = require("ffi")
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
local Device = {
|
2014-03-13 13:52:43 +00:00
|
|
|
screen_saver_mode = false,
|
|
|
|
charging_mode = false,
|
|
|
|
survive_screen_saver = false,
|
2014-07-04 03:16:28 +00:00
|
|
|
is_special_offers = nil,
|
2014-03-13 13:52:43 +00:00
|
|
|
touch_dev = nil,
|
|
|
|
model = nil,
|
|
|
|
firmware_rev = nil,
|
|
|
|
powerd = nil,
|
|
|
|
has_no_keyboard = nil,
|
|
|
|
is_touch_device = nil,
|
|
|
|
has_front_light = nil,
|
|
|
|
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)
|
2014-03-13 13:52:43 +00:00
|
|
|
local set = {}
|
|
|
|
for _, l in ipairs(list) do set[l] = true end
|
|
|
|
return set
|
2013-11-22 23:09:37 +00:00
|
|
|
end
|
|
|
|
|
2012-10-14 06:22:01 +00:00
|
|
|
function Device:getModel()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.model then return self.model end
|
|
|
|
if util.isEmulated() then
|
|
|
|
self.model = "Emulator"
|
|
|
|
return self.model
|
|
|
|
end
|
2014-05-28 15:21:08 +00:00
|
|
|
self.model = ""
|
2014-03-13 13:52:43 +00:00
|
|
|
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()
|
2014-07-04 01:53:26 +00:00
|
|
|
-- NOTE: Update me when new devices come out :)
|
2014-03-13 13:52:43 +00:00
|
|
|
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" }
|
2014-08-01 17:32:24 +00:00
|
|
|
local pw2_set = Set { "D4", "5A", "D5", "D6", "D7", "D8", "F2", "17", "60", "F4", "F9", "62", "61", "5F" }
|
2014-03-13 13:52:43 +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
|
|
|
|
self.model = "KindlePaperWhite2"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
local kg_test_fd = lfs.attributes("/bin/kobo_config.sh")
|
|
|
|
if kg_test_fd then
|
2014-07-03 18:55:45 +00:00
|
|
|
local std_out = io.popen("/bin/kobo_config.sh 2>/dev/null", "r")
|
2014-03-13 13:52:43 +00:00
|
|
|
local codename = std_out:read()
|
|
|
|
self.model = "Kobo_" .. codename
|
|
|
|
local version_file = io.open("/mnt/onboard/.kobo/version", "r")
|
|
|
|
self.firmware_rev = string.sub(version_file:read(),24,28)
|
|
|
|
version_file:close()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return self.model
|
2012-10-14 06:22:01 +00:00
|
|
|
end
|
|
|
|
|
2013-08-08 10:09:43 +00:00
|
|
|
function Device:getFirmVer()
|
2014-03-13 13:52:43 +00:00
|
|
|
if not self.model then self:getModel() end
|
|
|
|
return self.firmware_rev
|
2013-08-08 10:09:43 +00:00
|
|
|
end
|
|
|
|
|
2012-06-13 17:52:08 +00:00
|
|
|
function Device:isKindle4()
|
2014-03-13 13:52:43 +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()
|
2014-03-13 13:52:43 +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()
|
2014-03-13 13:52:43 +00:00
|
|
|
return (self:getModel() == "Kindle2")
|
2012-06-13 13:27:38 +00:00
|
|
|
end
|
2012-06-13 17:52:08 +00:00
|
|
|
|
2014-06-26 17:37:03 +00:00
|
|
|
function Device:isKindle()
|
|
|
|
local is_kindle = false
|
|
|
|
local kindle_sn = io.open("/proc/usid", "r")
|
|
|
|
if kindle_sn then
|
|
|
|
is_kindle = true
|
|
|
|
kindle_sn:close()
|
|
|
|
end
|
|
|
|
return is_kindle
|
|
|
|
end
|
|
|
|
|
2013-07-10 07:10:38 +00:00
|
|
|
function Device:isKobo()
|
2014-05-26 15:38:51 +00:00
|
|
|
return string.find(self:getModel() or "", "Kobo_") == 1
|
2013-07-10 07:10:38 +00:00
|
|
|
end
|
|
|
|
|
2014-06-02 15:25:11 +00:00
|
|
|
Device.isAndroid = util.isAndroid
|
|
|
|
|
2014-06-10 07:32:28 +00:00
|
|
|
-- device has qwerty keyboard
|
|
|
|
function Device:hasKeyboard()
|
|
|
|
if self.has_keyboard ~= nil then return self.has_keyboard end
|
2014-06-02 15:48:34 +00:00
|
|
|
if not isAndroid then
|
|
|
|
local model = self:getModel()
|
2014-06-10 07:32:28 +00:00
|
|
|
self.has_keyboard = (model == "Kindle2") or (model == "Kindle3")
|
|
|
|
or util.isEmulated()
|
2014-06-02 15:48:34 +00:00
|
|
|
else
|
2014-06-10 07:32:28 +00:00
|
|
|
self.has_keyboard = ffi.C.AConfiguration_getKeyboard(android.app.config)
|
|
|
|
== ffi.C.ACONFIGURATION_KEYBOARD_QWERTY
|
2014-06-02 15:48:34 +00:00
|
|
|
end
|
2014-06-10 07:32:28 +00:00
|
|
|
return self.has_keyboard
|
2012-12-11 00:01:32 +00:00
|
|
|
end
|
|
|
|
|
2014-06-10 07:32:28 +00:00
|
|
|
function Device:hasNoKeyboard()
|
|
|
|
return not self:hasKeyboard()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- device has hardware keys for pagedown/pageup
|
|
|
|
function Device:hasKeys()
|
|
|
|
if self.has_keys ~= nil then return self.has_keys end
|
|
|
|
local model = self:getModel()
|
|
|
|
self.has_keys = (model ~= "KindlePaperWhite") and (model ~= "KindlePaperWhite2")
|
|
|
|
and (model ~= "KindleTouch") and not self:isKobo()
|
|
|
|
return self.has_keys
|
2013-01-01 01:44:52 +00:00
|
|
|
end
|
|
|
|
|
2012-11-11 07:24:11 +00:00
|
|
|
function Device:isTouchDevice()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.is_touch_device ~= nil then return self.is_touch_device end
|
2014-06-02 15:48:34 +00:00
|
|
|
if not isAndroid then
|
|
|
|
local model = self:getModel()
|
|
|
|
self.is_touch_device = (model == "KindlePaperWhite") or (model == "KindlePaperWhite2")
|
|
|
|
or (model == "KindleTouch") or self:isKobo() or util.isEmulated()
|
|
|
|
else
|
|
|
|
self.is_touch_device = ffi.C.AConfiguration_getTouchscreen(android.app.config)
|
|
|
|
~= ffi.C.ACONFIGURATION_TOUCHSCREEN_NOTOUCH
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
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()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.has_front_light ~= nil then return self.has_front_light end
|
|
|
|
local model = self:getModel()
|
|
|
|
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)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.touch_dev = dev
|
2013-03-17 11:33:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Device:getTouchInputDev()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.touch_dev
|
2013-03-17 11:33:59 +00:00
|
|
|
end
|
|
|
|
|
2012-06-13 17:52:08 +00:00
|
|
|
function Device:intoScreenSaver()
|
2014-03-13 13:52:43 +00:00
|
|
|
--os.execute("echo 'screensaver in' >> /mnt/us/event_test.txt")
|
|
|
|
if self.charging_mode == false and self.screen_saver_mode == false then
|
|
|
|
self.screen:saveCurrentBB()
|
|
|
|
--UIManager:show(InfoMessage:new{
|
|
|
|
--text = "Going into screensaver... ",
|
|
|
|
--timeout = 2,
|
|
|
|
--})
|
|
|
|
--util.sleep(1)
|
|
|
|
--os.execute("killall -cont cvm")
|
|
|
|
self.screen_saver_mode = true
|
|
|
|
end
|
2012-06-13 17:52:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Device:outofScreenSaver()
|
2014-03-13 13:52:43 +00:00
|
|
|
--os.execute("echo 'screensaver out' >> /mnt/us/event_test.txt")
|
|
|
|
if self.screen_saver_mode == true and self.charging_mode == false then
|
|
|
|
-- wait for native system update screen before we recover saved
|
|
|
|
-- Blitbuffer.
|
|
|
|
util.usleep(1500000)
|
|
|
|
--os.execute("killall -stop cvm")
|
|
|
|
self.screen:restoreFromSavedBB()
|
|
|
|
self.screen:refresh(0)
|
|
|
|
self.survive_screen_saver = true
|
|
|
|
end
|
|
|
|
self.screen_saver_mode = false
|
2012-06-13 17:52:08 +00:00
|
|
|
end
|
|
|
|
|
2013-09-30 20:17:22 +00:00
|
|
|
function Device:prepareSuspend() -- currently only used for kobo devices
|
2014-03-13 13:52:43 +00:00
|
|
|
local powerd = self:getPowerDevice()
|
|
|
|
if powerd ~= nil then
|
|
|
|
powerd.fl:sleep()
|
|
|
|
end
|
|
|
|
self.screen:refresh(0)
|
|
|
|
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
|
2014-06-09 18:51:25 +00:00
|
|
|
os.execute("./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
|
2014-03-13 13:52:43 +00:00
|
|
|
os.execute("echo 0 > /sys/power/state-extended")
|
2014-08-15 20:07:01 +00:00
|
|
|
self.screen:refresh(1)
|
2014-03-13 13:52:43 +00:00
|
|
|
local powerd = self:getPowerDevice()
|
|
|
|
if powerd ~= nil then
|
|
|
|
powerd.fl:restore()
|
|
|
|
end
|
|
|
|
self.screen_saver_mode = false
|
2013-09-09 10:30:27 +00:00
|
|
|
end
|
|
|
|
|
2012-06-13 17:52:08 +00:00
|
|
|
function Device:usbPlugIn()
|
2014-03-13 13:52:43 +00:00
|
|
|
--os.execute("echo 'usb in' >> /mnt/us/event_test.txt")
|
|
|
|
if self.charging_mode == false and self.screen_saver_mode == false then
|
|
|
|
self.screen:saveCurrentBB()
|
|
|
|
--UIManager:show(InfoMessage:new{
|
|
|
|
--text = "Going into USB mode... ",
|
|
|
|
--timeout = 2,
|
|
|
|
--})
|
|
|
|
--util.sleep(1)
|
|
|
|
--os.execute("killall -cont cvm")
|
|
|
|
end
|
|
|
|
self.charging_mode = true
|
2012-06-13 17:52:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Device:usbPlugOut()
|
2014-03-13 13:52:43 +00:00
|
|
|
--os.execute("echo 'usb out' >> /mnt/us/event_test.txt")
|
|
|
|
if self.charging_mode == true and self.screen_saver_mode == false then
|
|
|
|
--util.usleep(1500000)
|
|
|
|
--os.execute("killall -stop cvm")
|
|
|
|
self.screen:restoreFromSavedBB()
|
|
|
|
self.screen:refresh(0)
|
|
|
|
end
|
2012-06-13 17:52:08 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
--@TODO signal filemanager for file changes 13.06 2012 (houqp)
|
|
|
|
self.charging_mode = false
|
2012-06-13 17:52:08 +00:00
|
|
|
end
|
2013-08-12 05:11:54 +00:00
|
|
|
|
2014-01-04 13:38:07 +00:00
|
|
|
function Device:getPowerDevice()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.powerd ~= nil then
|
|
|
|
return self.powerd
|
|
|
|
else
|
|
|
|
local model = self:getModel()
|
|
|
|
if model == "KindleTouch" or model == "KindlePaperWhite" or model == "KindlePaperWhite2" then
|
|
|
|
self.powerd = KindlePowerD:new{model = model}
|
|
|
|
elseif self:isKobo() then
|
|
|
|
self.powerd = KoboPowerD:new()
|
2014-07-15 08:23:38 +00:00
|
|
|
elseif self.isAndroid then
|
|
|
|
self.powerd = AndroidPowerd:new()
|
2014-03-13 13:52:43 +00:00
|
|
|
else -- emulated FrontLight
|
|
|
|
self.powerd = BasePowerD:new()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return self.powerd
|
2013-08-12 05:11:54 +00:00
|
|
|
end
|
|
|
|
|
2014-07-04 03:16:28 +00:00
|
|
|
function Device:isSpecialOffers()
|
|
|
|
if self.is_special_offers ~= nil then return self.is_special_offers end
|
|
|
|
-- K5 only
|
|
|
|
if self:isTouchDevice() and self:isKindle() then
|
|
|
|
-- Look at the current blanket modules to see if the SO screensavers are enabled...
|
|
|
|
local lipc = require("liblipclua")
|
|
|
|
local lipc_handle = nil
|
|
|
|
if lipc then
|
|
|
|
lipc_handle = lipc.init("com.github.koreader.device")
|
|
|
|
end
|
|
|
|
if lipc_handle then
|
|
|
|
local loaded_blanket_modules = lipc_handle:get_string_property("com.lab126.blanket", "load")
|
|
|
|
if string.find(loaded_blanket_modules, "ad_screensaver") then
|
|
|
|
self.is_special_offers = true
|
|
|
|
end
|
|
|
|
lipc_handle:close()
|
|
|
|
else
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return self.is_special_offers
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return Device
|