2014-10-30 18:42:18 +00:00
|
|
|
local Generic = require("device/generic/device")
|
|
|
|
local util = require("ffi/util")
|
2016-12-29 08:10:38 +00:00
|
|
|
local logger = require("logger")
|
2014-10-30 18:42:18 +00:00
|
|
|
|
|
|
|
local function yes() return true end
|
2015-09-27 01:25:47 +00:00
|
|
|
local function no() return false end
|
2014-10-30 18:42:18 +00:00
|
|
|
|
|
|
|
local Device = Generic:new{
|
2015-10-03 06:18:47 +00:00
|
|
|
model = "SDL",
|
|
|
|
isSDL = yes,
|
2014-10-30 18:42:18 +00:00
|
|
|
hasKeyboard = yes,
|
|
|
|
hasKeys = yes,
|
2015-09-27 01:05:37 +00:00
|
|
|
hasDPad = yes,
|
2014-10-30 18:42:18 +00:00
|
|
|
hasFrontlight = yes,
|
|
|
|
isTouchDevice = yes,
|
2015-09-27 01:25:47 +00:00
|
|
|
needsScreenRefreshAfterResume = no,
|
2014-10-30 18:42:18 +00:00
|
|
|
}
|
|
|
|
|
2016-01-31 22:56:05 +00:00
|
|
|
if os.getenv("DISABLE_TOUCH") == "1" then
|
|
|
|
Device.isTouchDevice = no
|
|
|
|
end
|
|
|
|
|
2014-10-30 18:42:18 +00:00
|
|
|
function Device:init()
|
2014-11-27 10:15:44 +00:00
|
|
|
-- allows to set a viewport via environment variable
|
|
|
|
-- syntax is Lua table syntax, e.g. EMULATE_READER_VIEWPORT="{x=10,w=550,y=5,h=790}"
|
|
|
|
local viewport = os.getenv("EMULATE_READER_VIEWPORT")
|
|
|
|
if viewport then
|
|
|
|
self.viewport = require("ui/geometry"):new(loadstring("return " .. viewport)())
|
|
|
|
end
|
2014-11-27 15:33:48 +00:00
|
|
|
local portrait = os.getenv("EMULATE_READER_FORCE_PORTRAIT")
|
|
|
|
if portrait then
|
|
|
|
self.isAlwaysPortrait = yes
|
|
|
|
end
|
2014-11-27 10:15:44 +00:00
|
|
|
|
2014-11-20 19:24:02 +00:00
|
|
|
if util.haveSDL2() then
|
2016-12-29 08:10:38 +00:00
|
|
|
self.screen = require("ffi/framebuffer_SDL2_0"):new{device = self, debug = logger.dbg}
|
2014-11-20 19:24:02 +00:00
|
|
|
self.input = require("device/input"):new{
|
|
|
|
device = self,
|
2015-10-03 06:18:47 +00:00
|
|
|
event_map = require("device/sdl/event_map_sdl2"),
|
2014-11-20 19:24:02 +00:00
|
|
|
}
|
|
|
|
else
|
2016-12-29 08:10:38 +00:00
|
|
|
self.screen = require("ffi/framebuffer_SDL1_2"):new{device = self, debug = logger.dbg}
|
2014-11-20 19:24:02 +00:00
|
|
|
self.input = require("device/input"):new{
|
|
|
|
device = self,
|
2015-10-03 06:18:47 +00:00
|
|
|
event_map = require("device/sdl/event_map_sdl"),
|
2014-11-20 19:24:02 +00:00
|
|
|
}
|
|
|
|
end
|
2014-10-30 18:42:18 +00:00
|
|
|
|
2016-01-31 22:56:05 +00:00
|
|
|
self.keyboard_layout = require("device/sdl/keyboard_layout")
|
|
|
|
|
2014-11-27 15:33:48 +00:00
|
|
|
if portrait then
|
|
|
|
self.input:registerEventAdjustHook(self.input.adjustTouchSwitchXY)
|
|
|
|
self.input:registerEventAdjustHook(
|
|
|
|
self.input.adjustTouchMirrorX,
|
|
|
|
self.screen:getScreenWidth()
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2014-10-30 18:42:18 +00:00
|
|
|
Generic.init(self)
|
|
|
|
end
|
|
|
|
|
2017-08-15 17:54:02 +00:00
|
|
|
function Device:setTime(hour, min)
|
|
|
|
if hour == nil or min == nil then return true end
|
|
|
|
if os.execute(string.format("date -s '%d:%d'", hour, min)) == 0 then
|
|
|
|
os.execute('hwclock -u -w')
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-23 17:04:11 +00:00
|
|
|
function Device:simulateSuspend()
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local _ = require("gettext")
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = _("Suspend")
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function Device:simulateResume()
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local _ = require("gettext")
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = _("Resume")
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2014-10-30 18:42:18 +00:00
|
|
|
return Device
|