forked from koreader/koreader
/
device.lua
312 lines (279 loc) · 8.3 KB
/
device.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
local Generic = require("device/generic/device") -- <= look at this file!
local logger = require("logger")
local ffi = require("ffi")
local inkview = ffi.load("inkview")
-- luacheck: push
-- luacheck: ignore
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
local EVT_FOREGROUND = 151
local EVT_BACKGROUND = 152
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
local KEY_COVEROPEN = 0x02
local KEY_COVERCLOSE = 0x03
-- luacheck: pop
ffi.cdef[[
char *GetSoftwareVersion(void);
char *GetDeviceModel(void);
]]
local function yes() return true end
local function no() return false end
local function pocketbookEnableWifi(toggle)
os.execute("/ebrmain/bin/netagent " .. (toggle == 1 and "connect" or "disconnect"))
end
local PocketBook = Generic:new{
model = "PocketBook",
isPocketBook = yes,
isInBackGround = false,
hasOTAUpdates = yes,
}
function PocketBook:init()
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"
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
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
require("ui/uimanager"):broadcastEvent(
require("ui/event"):new("Close"))
end
end)
-- 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
os.remove(self.emu_events_dev)
os.execute("mkfifo " .. self.emu_events_dev)
self.input.open(self.emu_events_dev, 1)
Generic.init(self)
end
function PocketBook:supportsScreensaver() return true end
function PocketBook:setDateTime(year, month, day, hour, min, sec)
if hour == nil or min == nil then return true end
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
os.execute('hwclock -u -w')
return true
else
return false
end
end
function PocketBook:initNetworkManager(NetworkMgr)
NetworkMgr.turnOnWifi = function()
pocketbookEnableWifi(1)
end
NetworkMgr.turnOffWifi = function()
pocketbookEnableWifi(0)
end
end
function PocketBook:getSoftwareVersion()
return ffi.string(inkview.GetSoftwareVersion())
end
function PocketBook:getDeviceModel()
return ffi.string(inkview.GetDeviceModel())
end
-- PocketBook InkPad
local PocketBook840 = PocketBook:new{
model = "PBInkPad",
isTouchDevice = yes,
hasKeys = yes,
hasFrontlight = yes,
display_dpi = 250,
emu_events_dev = "/var/dev/shm/emu_events",
}
-- PocketBook Lux 4
local PocketBook627 = PocketBook:new{
model = "PBLux4",
isTouchDevice = yes,
hasKeys = yes,
hasFrontlight = yes,
display_dpi = 212,
emu_events_dev = "/var/dev/shm/emu_events",
}
-- PocketBook Touch HD
local PocketBook631 = PocketBook:new{
model = "PBTouchHD",
isTouchDevice = yes,
hasKeys = yes,
hasFrontlight = yes,
display_dpi = 300,
emu_events_dev = "/dev/shm/emu_events",
}
-- PocketBook Touch HD Plus
local PocketBook632 = PocketBook:new{
model = "PBTouchHDPlus",
isTouchDevice = yes,
hasKeys = yes,
hasFrontlight = yes,
display_dpi = 300,
isAlwaysPortrait = yes,
emu_events_dev = "/dev/shm/emu_events",
}
-- PocketBook Lux 3
local PocketBook626 = PocketBook:new{
model = "PBLux3",
isTouchDevice = yes,
hasKeys = yes,
hasFrontlight = yes,
display_dpi = 212,
emu_events_dev = "/var/dev/shm/emu_events",
}
-- PocketBook Basic Touch
local PocketBook624 = PocketBook:new{
model = "PBBasicTouch",
isTouchDevice = yes,
hasKeys = yes,
hasFrontlight = no,
display_dpi = 166,
emu_events_dev = "/var/dev/shm/emu_events",
}
-- PocketBook Basic Touch 2
local PocketBook625 = PocketBook:new{
model = "PBBasicTouch2",
isTouchDevice = yes,
hasKeys = yes,
hasFrontlight = no,
display_dpi = 166,
emu_events_dev = "/var/dev/shm/emu_events",
}
-- PocketBook Touch Lux
local PocketBook623 = PocketBook:new{
model = "PBTouchLux",
isTouchDevice = yes,
hasKeys = yes,
hasFrontlight = yes,
display_dpi = 212,
emu_events_dev = "/var/dev/shm/emu_events",
}
-- PocketBook InkPad 3
local PocketBook740 = PocketBook:new{
model = "PBInkPad3",
isTouchDevice = yes,
hasKeys = yes,
hasFrontlight = yes,
isAlwaysPortrait = yes,
display_dpi = 300,
emu_events_dev = "/var/dev/shm/emu_events",
}
-- PocketBook Sense
local PocketBook630 = PocketBook:new{
model = "PBSense",
isTouchDevice = yes,
hasKeys = yes,
hasFrontlight = yes,
display_dpi = 212,
emu_events_dev = "/dev/shm/emu_events",
}
-- PocketBook Aqua 2
local PocketBook641 = PocketBook:new{
model = "PBAqua2",
isTouchDevice = yes,
hasKeys = yes,
hasFrontlight = yes,
display_dpi = 212,
emu_events_dev = "/var/dev/shm/emu_events",
}
-- PocketBook Color Lux
local PocketBookColorLux = PocketBook:new{
model = "PBColorLux",
isTouchDevice = yes,
hasKeys = yes,
hasFrontlight = yes,
hasColorScreen = yes,
has3BytesWideFrameBuffer = yes,
isAlwaysPortrait = no,
emu_events_dev = "/var/dev/shm/emu_events",
}
logger.info('SoftwareVersion: ', PocketBook:getSoftwareVersion())
local codename = PocketBook:getDeviceModel()
if codename == "PocketBook 623" then
return PocketBook623
elseif codename == "PocketBook 624" then
return PocketBook624
elseif codename == "PB625" then
return PocketBook625
elseif codename == "PB626" or codename == "PocketBook 626" then
return PocketBook626
elseif codename == "PB627" then
return PocketBook627
elseif codename == "PocketBook 630" then
return PocketBook630
elseif codename == "PB631" then
return PocketBook631
elseif codename == "PB632" then
return PocketBook632
elseif codename == "PB641" then
return PocketBook641
elseif codename == "PB740" then
return PocketBook740
elseif codename == "PocketBook 840" then
return PocketBook840
elseif codename == "PocketBook Color Lux" then
return PocketBookColorLux
else
error("unrecognized PocketBook model " .. codename)
end