2015-01-09 14:10:25 +00:00
|
|
|
local Generic = require("device/generic/device") -- <= look at this file!
|
2016-12-29 08:10:38 +00:00
|
|
|
local logger = require("logger")
|
2017-10-22 16:08:53 +00:00
|
|
|
local ffi = require("ffi")
|
|
|
|
local inkview = ffi.load("inkview")
|
2015-01-09 14:10:25 +00:00
|
|
|
|
2016-02-16 07:10:07 +00:00
|
|
|
-- luacheck: push
|
|
|
|
-- luacheck: ignore
|
2015-01-15 14:23:03 +00:00
|
|
|
local EVT_INIT = 21
|
|
|
|
local EVT_EXIT = 22
|
|
|
|
local EVT_SHOW = 23
|
|
|
|
local EVT_REPAINT = 23
|
|
|
|
local EVT_HIDE = 24
|
|
|
|
local EVT_KEYDOWN = 25
|
|
|
|
local EVT_KEYPRESS = 25
|
|
|
|
local EVT_KEYUP = 26
|
|
|
|
local EVT_KEYRELEASE = 26
|
|
|
|
local EVT_KEYREPEAT = 28
|
2015-01-17 01:09:36 +00:00
|
|
|
local EVT_FOREGROUND = 151
|
|
|
|
local EVT_BACKGROUND = 152
|
2015-01-15 14:23:03 +00:00
|
|
|
|
|
|
|
local KEY_POWER = 0x01
|
|
|
|
local KEY_DELETE = 0x08
|
|
|
|
local KEY_OK = 0x0a
|
|
|
|
local KEY_UP = 0x11
|
|
|
|
local KEY_DOWN = 0x12
|
|
|
|
local KEY_LEFT = 0x13
|
|
|
|
local KEY_RIGHT = 0x14
|
|
|
|
local KEY_MINUS = 0x15
|
|
|
|
local KEY_PLUS = 0x16
|
|
|
|
local KEY_MENU = 0x17
|
|
|
|
local KEY_PREV = 0x18
|
|
|
|
local KEY_NEXT = 0x19
|
|
|
|
local KEY_HOME = 0x1a
|
|
|
|
local KEY_BACK = 0x1b
|
|
|
|
local KEY_PREV2 = 0x1c
|
|
|
|
local KEY_NEXT2 = 0x1d
|
2018-04-29 13:15:11 +00:00
|
|
|
local KEY_COVEROPEN = 0x02
|
|
|
|
local KEY_COVERCLOSE = 0x03
|
2019-03-12 06:05:43 +00:00
|
|
|
|
|
|
|
local CONNECTING = 1
|
|
|
|
local CONNECTED = 2
|
|
|
|
local NET_OK = 0
|
2016-02-16 07:10:07 +00:00
|
|
|
-- luacheck: pop
|
2015-01-15 14:23:03 +00:00
|
|
|
|
2017-10-22 16:08:53 +00:00
|
|
|
ffi.cdef[[
|
|
|
|
char *GetSoftwareVersion(void);
|
|
|
|
char *GetDeviceModel(void);
|
2019-03-12 06:05:43 +00:00
|
|
|
int GetNetState(void);
|
|
|
|
int NetConnect(const char *name);
|
|
|
|
int NetDisconnect();
|
2017-10-22 16:08:53 +00:00
|
|
|
]]
|
|
|
|
|
2015-01-09 14:10:25 +00:00
|
|
|
local function yes() return true end
|
2017-12-02 09:28:11 +00:00
|
|
|
local function no() return false end
|
2015-01-09 14:10:25 +00:00
|
|
|
|
2016-06-12 18:50:30 +00:00
|
|
|
|
2015-01-09 14:10:25 +00:00
|
|
|
local PocketBook = Generic:new{
|
2015-01-12 16:14:56 +00:00
|
|
|
model = "PocketBook",
|
|
|
|
isPocketBook = yes,
|
2015-01-17 15:17:46 +00:00
|
|
|
isInBackGround = false,
|
2018-10-06 05:55:35 +00:00
|
|
|
hasOTAUpdates = yes,
|
2019-03-12 06:05:43 +00:00
|
|
|
hasWifiToggle = yes,
|
2020-05-19 18:07:18 +00:00
|
|
|
isTouchDevice = yes,
|
|
|
|
hasKeys = yes,
|
|
|
|
hasFrontlight = yes,
|
|
|
|
emu_events_dev = "/dev/shm/emu_events",
|
2015-01-09 14:10:25 +00:00
|
|
|
}
|
|
|
|
|
2019-05-02 02:27:48 +00:00
|
|
|
-- Make sure the C BB cannot be used on devices with a 24bpp fb
|
|
|
|
function PocketBook:blacklistCBB()
|
|
|
|
local dummy = require("ffi/posix_h")
|
|
|
|
local C = ffi.C
|
|
|
|
|
|
|
|
-- As well as on those than can't do HW inversion, as otherwise NightMode would be ineffective.
|
2019-08-23 17:53:53 +00:00
|
|
|
--- @fixme Either relax the HWInvert check, or actually enable HWInvert on PB if it's safe and it works,
|
2019-05-02 02:27:48 +00:00
|
|
|
-- as, currently, no PB device is marked as canHWInvert, so, the C BB is essentially *always* blacklisted.
|
|
|
|
if not self:canUseCBB() or not self:canHWInvert() then
|
|
|
|
logger.info("Blacklisting the C BB on this device")
|
|
|
|
if ffi.os == "Windows" then
|
|
|
|
C._putenv("KO_NO_CBB=true")
|
|
|
|
else
|
|
|
|
C.setenv("KO_NO_CBB", "true", 1)
|
|
|
|
end
|
|
|
|
-- Enforce the global setting, too, so the Dev menu is accurate...
|
|
|
|
G_reader_settings:saveSetting("dev_no_c_blitter", true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-09 14:10:25 +00:00
|
|
|
function PocketBook:init()
|
2019-05-02 02:27:48 +00:00
|
|
|
-- Blacklist the C BB before the first BB require...
|
|
|
|
self:blacklistCBB()
|
|
|
|
|
2018-01-06 12:14:26 +00:00
|
|
|
self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = logger.dbg}
|
|
|
|
self.powerd = require("device/pocketbook/powerd"):new{device = self}
|
|
|
|
self.input = require("device/input"):new{
|
|
|
|
device = self,
|
|
|
|
event_map = {
|
|
|
|
[KEY_MENU] = "Menu",
|
|
|
|
[KEY_PREV] = "LPgBack",
|
|
|
|
[KEY_NEXT] = "LPgFwd",
|
|
|
|
},
|
|
|
|
handleMiscEv = function(this, ev)
|
|
|
|
if ev.code == EVT_BACKGROUND then
|
|
|
|
self.isInBackGround = true
|
|
|
|
return "Suspend"
|
|
|
|
elseif ev.code == EVT_FOREGROUND then
|
|
|
|
if self.isInBackGround then
|
|
|
|
self.isInBackGround = false
|
|
|
|
return "Resume"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
-- in contrast to kobo/kindle, pocketbook-devices do not use linux/input
|
|
|
|
-- events directly. To be able to use input.lua nevertheless, we make
|
|
|
|
-- inkview-events look like linux/input events or handle them directly
|
|
|
|
-- here.
|
|
|
|
-- Unhandled events will leave Input:waitEvent() as "GenericInput"
|
2015-01-15 14:23:03 +00:00
|
|
|
self.input:registerEventAdjustHook(function(_input, ev)
|
|
|
|
if ev.type == EVT_KEYDOWN or ev.type == EVT_KEYUP then
|
|
|
|
ev.value = ev.type == EVT_KEYDOWN and 1 or 0
|
2018-01-06 12:14:26 +00:00
|
|
|
ev.type = 1 -- linux/input.h Key-Event
|
|
|
|
end
|
|
|
|
|
|
|
|
-- handle EVT_BACKGROUND and EVT_FOREGROUND as MiscEvent as this makes
|
|
|
|
-- it easy to return a string directly which can be used in
|
|
|
|
-- uimanager.lua as event_handler index.
|
|
|
|
if ev.type == EVT_BACKGROUND or ev.type == EVT_FOREGROUND then
|
|
|
|
ev.code = ev.type
|
|
|
|
ev.type = 4 -- handle as MiscEvent, see above
|
|
|
|
end
|
|
|
|
|
|
|
|
-- auto shutdown event from inkview framework, gracefully close
|
|
|
|
-- everything and let the framework shutdown the device
|
|
|
|
if ev.type == EVT_EXIT then
|
2016-06-14 07:00:50 +00:00
|
|
|
require("ui/uimanager"):broadcastEvent(
|
|
|
|
require("ui/event"):new("Close"))
|
2015-01-15 14:23:03 +00:00
|
|
|
end
|
2015-01-09 14:10:25 +00:00
|
|
|
end)
|
|
|
|
|
2018-09-30 19:37:14 +00:00
|
|
|
-- fix rotation for Color Lux device
|
|
|
|
if PocketBook:getDeviceModel() == "PocketBook Color Lux" then
|
|
|
|
self.screen.blitbuffer_rotation_mode = 0
|
|
|
|
self.screen.native_rotation_mode = 0
|
|
|
|
end
|
|
|
|
|
2015-01-12 16:14:56 +00:00
|
|
|
os.remove(self.emu_events_dev)
|
2018-04-04 16:26:44 +00:00
|
|
|
os.execute("mkfifo " .. self.emu_events_dev)
|
2015-01-12 16:14:56 +00:00
|
|
|
self.input.open(self.emu_events_dev, 1)
|
2015-01-09 14:10:25 +00:00
|
|
|
Generic.init(self)
|
|
|
|
end
|
|
|
|
|
2018-01-06 12:14:26 +00:00
|
|
|
function PocketBook:supportsScreensaver() return true end
|
|
|
|
|
2017-09-18 17:04:36 +00:00
|
|
|
function PocketBook:setDateTime(year, month, day, hour, min, sec)
|
2017-08-15 17:54:02 +00:00
|
|
|
if hour == nil or min == nil then return true end
|
2017-09-18 17:04:36 +00:00
|
|
|
local command
|
|
|
|
if year and month and day then
|
|
|
|
command = string.format("date -s '%d-%d-%d %d:%d:%d'", year, month, day, hour, min, sec)
|
|
|
|
else
|
|
|
|
command = string.format("date -s '%d:%d'",hour, min)
|
|
|
|
end
|
|
|
|
if os.execute(command) == 0 then
|
2017-08-15 17:54:02 +00:00
|
|
|
os.execute('hwclock -u -w')
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-12 18:50:30 +00:00
|
|
|
function PocketBook:initNetworkManager(NetworkMgr)
|
2019-03-12 06:05:43 +00:00
|
|
|
function NetworkMgr:turnOnWifi(complete_callback)
|
|
|
|
if inkview.NetConnect(nil) ~= NET_OK then
|
|
|
|
logger.info('NetConnect failed')
|
|
|
|
end
|
|
|
|
if complete_callback then
|
|
|
|
complete_callback()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function NetworkMgr:turnOffWifi(complete_callback)
|
|
|
|
inkview.NetDisconnect()
|
|
|
|
if complete_callback then
|
|
|
|
complete_callback()
|
|
|
|
end
|
2016-06-12 18:50:30 +00:00
|
|
|
end
|
|
|
|
|
2019-03-12 06:05:43 +00:00
|
|
|
function NetworkMgr:isWifiOn()
|
|
|
|
return inkview.GetNetState() == CONNECTED
|
2016-06-12 18:50:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-22 16:08:53 +00:00
|
|
|
function PocketBook:getSoftwareVersion()
|
|
|
|
return ffi.string(inkview.GetSoftwareVersion())
|
|
|
|
end
|
|
|
|
|
|
|
|
function PocketBook:getDeviceModel()
|
|
|
|
return ffi.string(inkview.GetDeviceModel())
|
|
|
|
end
|
|
|
|
|
|
|
|
-- PocketBook InkPad
|
2015-01-17 01:09:36 +00:00
|
|
|
local PocketBook840 = PocketBook:new{
|
2019-01-13 23:49:29 +00:00
|
|
|
model = "PBInkPad",
|
2015-01-17 01:09:36 +00:00
|
|
|
display_dpi = 250,
|
|
|
|
}
|
|
|
|
|
2018-11-26 14:19:00 +00:00
|
|
|
-- PocketBook Lux 4
|
|
|
|
local PocketBook627 = PocketBook:new{
|
2019-01-13 23:49:29 +00:00
|
|
|
model = "PBLux4",
|
2018-11-26 14:19:00 +00:00
|
|
|
display_dpi = 212,
|
|
|
|
}
|
|
|
|
|
2019-01-13 23:49:29 +00:00
|
|
|
-- PocketBook Touch HD
|
2017-10-22 16:08:53 +00:00
|
|
|
local PocketBook631 = PocketBook:new{
|
2019-01-13 23:49:29 +00:00
|
|
|
model = "PBTouchHD",
|
2017-10-22 16:08:53 +00:00
|
|
|
display_dpi = 300,
|
|
|
|
}
|
|
|
|
|
2018-12-25 23:56:02 +00:00
|
|
|
-- PocketBook Touch HD Plus
|
|
|
|
local PocketBook632 = PocketBook:new{
|
2019-01-13 23:49:29 +00:00
|
|
|
model = "PBTouchHDPlus",
|
2018-12-25 23:56:02 +00:00
|
|
|
display_dpi = 300,
|
|
|
|
isAlwaysPortrait = yes,
|
|
|
|
}
|
|
|
|
|
2017-11-07 19:51:52 +00:00
|
|
|
-- PocketBook Lux 3
|
|
|
|
local PocketBook626 = PocketBook:new{
|
2019-01-13 23:49:29 +00:00
|
|
|
model = "PBLux3",
|
2017-11-07 19:51:52 +00:00
|
|
|
display_dpi = 212,
|
|
|
|
}
|
|
|
|
|
2017-12-02 09:28:11 +00:00
|
|
|
-- PocketBook Basic Touch
|
|
|
|
local PocketBook624 = PocketBook:new{
|
2019-01-13 23:49:29 +00:00
|
|
|
model = "PBBasicTouch",
|
2017-12-02 09:28:11 +00:00
|
|
|
hasFrontlight = no,
|
|
|
|
display_dpi = 166,
|
|
|
|
}
|
|
|
|
|
2019-01-08 02:46:32 +00:00
|
|
|
-- PocketBook Basic Touch 2
|
|
|
|
local PocketBook625 = PocketBook:new{
|
2019-01-13 23:49:29 +00:00
|
|
|
model = "PBBasicTouch2",
|
2019-01-08 02:46:32 +00:00
|
|
|
hasFrontlight = no,
|
|
|
|
display_dpi = 166,
|
|
|
|
}
|
|
|
|
|
2019-07-15 12:39:37 +00:00
|
|
|
-- PocketBook Touch
|
|
|
|
local PocketBook622 = PocketBook:new{
|
|
|
|
model = "PBTouch",
|
|
|
|
hasFrontlight = no,
|
|
|
|
display_dpi = 166,
|
|
|
|
}
|
|
|
|
|
2017-12-10 19:02:34 +00:00
|
|
|
-- PocketBook Touch Lux
|
|
|
|
local PocketBook623 = PocketBook:new{
|
2019-01-13 23:49:29 +00:00
|
|
|
model = "PBTouchLux",
|
2017-12-10 19:02:34 +00:00
|
|
|
display_dpi = 212,
|
|
|
|
}
|
|
|
|
|
2018-04-04 16:26:44 +00:00
|
|
|
-- PocketBook InkPad 3
|
|
|
|
local PocketBook740 = PocketBook:new{
|
2019-01-13 23:49:29 +00:00
|
|
|
model = "PBInkPad3",
|
2018-04-04 16:26:44 +00:00
|
|
|
isAlwaysPortrait = yes,
|
|
|
|
display_dpi = 300,
|
|
|
|
}
|
|
|
|
|
2019-09-18 13:21:04 +00:00
|
|
|
-- PocketBook InkPad 3 Pro
|
|
|
|
local PocketBook740_2 = PocketBook:new{
|
|
|
|
model = "PBInkPad3Pro",
|
|
|
|
isAlwaysPortrait = yes,
|
|
|
|
display_dpi = 300,
|
|
|
|
}
|
|
|
|
|
2020-02-22 08:09:18 +00:00
|
|
|
-- PocketBook InkPad X
|
|
|
|
local PocketBook1040 = PocketBook:new{
|
|
|
|
model = "PB1040",
|
|
|
|
isAlwaysPortrait = yes,
|
|
|
|
display_dpi = 227,
|
|
|
|
}
|
|
|
|
|
2019-01-13 23:49:29 +00:00
|
|
|
-- PocketBook Sense
|
2018-11-23 12:33:43 +00:00
|
|
|
local PocketBook630 = PocketBook:new{
|
2019-01-13 23:49:29 +00:00
|
|
|
model = "PBSense",
|
2018-11-23 12:33:43 +00:00
|
|
|
display_dpi = 212,
|
|
|
|
}
|
|
|
|
|
2019-01-05 08:02:45 +00:00
|
|
|
-- PocketBook Aqua 2
|
|
|
|
local PocketBook641 = PocketBook:new{
|
2019-01-13 23:49:29 +00:00
|
|
|
model = "PBAqua2",
|
2019-01-05 08:02:45 +00:00
|
|
|
display_dpi = 212,
|
|
|
|
}
|
|
|
|
|
2018-09-30 19:37:14 +00:00
|
|
|
-- PocketBook Color Lux
|
|
|
|
local PocketBookColorLux = PocketBook:new{
|
2019-01-13 23:49:29 +00:00
|
|
|
model = "PBColorLux",
|
2018-09-30 19:37:14 +00:00
|
|
|
hasColorScreen = yes,
|
|
|
|
has3BytesWideFrameBuffer = yes,
|
2019-05-02 02:27:48 +00:00
|
|
|
canUseCBB = no, -- 24bpp
|
2018-09-30 19:37:14 +00:00
|
|
|
}
|
|
|
|
|
2017-10-22 16:08:53 +00:00
|
|
|
logger.info('SoftwareVersion: ', PocketBook:getSoftwareVersion())
|
|
|
|
|
|
|
|
local codename = PocketBook:getDeviceModel()
|
|
|
|
|
2019-07-15 12:39:37 +00:00
|
|
|
if codename == "PocketBook 622" then
|
|
|
|
return PocketBook622
|
|
|
|
elseif codename == "PocketBook 623" then
|
2019-01-13 11:34:53 +00:00
|
|
|
return PocketBook623
|
|
|
|
elseif codename == "PocketBook 624" then
|
|
|
|
return PocketBook624
|
|
|
|
elseif codename == "PB625" then
|
|
|
|
return PocketBook625
|
2019-08-16 20:59:36 +00:00
|
|
|
elseif codename == "PB626" or codename == "PB626(2)-TL3" or
|
|
|
|
codename == "PocketBook 626" then
|
2019-01-13 11:34:53 +00:00
|
|
|
return PocketBook626
|
2018-11-26 14:19:00 +00:00
|
|
|
elseif codename == "PB627" then
|
|
|
|
return PocketBook627
|
2019-01-13 11:34:53 +00:00
|
|
|
elseif codename == "PocketBook 630" then
|
|
|
|
return PocketBook630
|
2017-10-22 16:08:53 +00:00
|
|
|
elseif codename == "PB631" then
|
|
|
|
return PocketBook631
|
2018-12-25 23:56:02 +00:00
|
|
|
elseif codename == "PB632" then
|
|
|
|
return PocketBook632
|
2019-01-05 08:02:45 +00:00
|
|
|
elseif codename == "PB641" then
|
|
|
|
return PocketBook641
|
2018-04-04 16:26:44 +00:00
|
|
|
elseif codename == "PB740" then
|
|
|
|
return PocketBook740
|
2019-09-18 13:21:04 +00:00
|
|
|
elseif codename == "PB740-2" then
|
|
|
|
return PocketBook740_2
|
2020-02-22 08:09:18 +00:00
|
|
|
elseif codename == "PB1040" then
|
|
|
|
return PocketBook1040
|
2019-01-13 11:34:53 +00:00
|
|
|
elseif codename == "PocketBook 840" then
|
|
|
|
return PocketBook840
|
2018-09-30 19:37:14 +00:00
|
|
|
elseif codename == "PocketBook Color Lux" then
|
|
|
|
return PocketBookColorLux
|
2017-10-22 16:08:53 +00:00
|
|
|
else
|
|
|
|
error("unrecognized PocketBook model " .. codename)
|
|
|
|
end
|