mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
reMarkable: Make sleep/waking up w/o launcher work and properly exit when KO_DONT_GRAB_INPUT is set (#13795)
This commit is contained in:
@@ -353,4 +353,8 @@ function BasePowerD:getBatterySymbol(is_charged, is_charging, capacity)
|
||||
end
|
||||
end
|
||||
|
||||
function BasePowerD:hasHallSensor()
|
||||
return false
|
||||
end
|
||||
|
||||
return BasePowerD
|
||||
|
||||
@@ -58,6 +58,7 @@ local Remarkable = Generic:extend{
|
||||
-- Despite the SoC supporting it, it's finicky in practice (#6772)
|
||||
canHWInvert = no,
|
||||
home_dir = "/home/root",
|
||||
input_hall = nil,
|
||||
}
|
||||
|
||||
local Remarkable1 = Remarkable:extend{
|
||||
@@ -122,6 +123,7 @@ local RemarkablePaperPro = Remarkable:extend{
|
||||
input_wacom = "/dev/input/event2",
|
||||
input_ts = "/dev/input/event3",
|
||||
input_buttons = "/dev/input/event0",
|
||||
input_hall = "/dev/input/event1",
|
||||
battery_path = "/sys/class/power_supply/max1726x_battery/capacity",
|
||||
status_path = "/sys/class/power_supply/max1726x_battery/status",
|
||||
canSuspend = no, -- Suspend and Standby should be handled by xochitl with KO_DONT_GRAB_INPUT=1 set, otherwise bad things will happen
|
||||
@@ -186,17 +188,28 @@ function Remarkable:init()
|
||||
device = self,
|
||||
capacity_file = self.battery_path,
|
||||
status_file = self.status_path,
|
||||
hall_file = isRmPaperPro and "/sys/class/input/input1/inhibited" or nil,
|
||||
}
|
||||
|
||||
local event_map = dofile("frontend/device/remarkable/event_map.lua")
|
||||
-- If we are launched while Oxide is running, remove Power from the event map
|
||||
if oxide_running then
|
||||
event_map[116] = nil
|
||||
event_map[143] = nil
|
||||
end
|
||||
|
||||
self.input = require("device/input"):new{
|
||||
device = self,
|
||||
event_map = dofile("frontend/device/remarkable/event_map.lua"),
|
||||
event_map_adapter = {
|
||||
SleepCover = function(ev)
|
||||
if ev.value == 1 then
|
||||
return "Suspend"
|
||||
else
|
||||
return "Resume"
|
||||
end
|
||||
end,
|
||||
},
|
||||
wacom_protocol = true,
|
||||
}
|
||||
|
||||
@@ -225,6 +238,19 @@ function Remarkable:init()
|
||||
self.input:open(self.input_ts) -- Touchscreen
|
||||
self.input:open(self.input_buttons) -- Buttons
|
||||
|
||||
if self.input_hall ~= nil then
|
||||
self.input:open(self.input_hall) -- Hall sensor
|
||||
local hallSensorMangling = function(this, ev)
|
||||
if ev.type == C.EV_SW then
|
||||
if ev.code == 0 then
|
||||
ev.type = C.EV_KEY
|
||||
ev.code = 20001
|
||||
end
|
||||
end
|
||||
end
|
||||
self.input:registerEventAdjustHook(hallSensorMangling)
|
||||
end
|
||||
|
||||
local scalex = screen_width / self.mt_width
|
||||
local scaley = screen_height / self.mt_height
|
||||
|
||||
@@ -267,6 +293,18 @@ function Remarkable:init()
|
||||
PluginShare.pause_auto_suspend = true
|
||||
end
|
||||
|
||||
if isRmPaperPro then
|
||||
-- disable autosuspend of xochitl
|
||||
os.execute("cp -a ~/.config/remarkable/xochitl.conf ~/.config/remarkable/xochitl.conf.bak")
|
||||
os.execute("sed -ri 's/IdleSuspendDelay=[0-9]+/IdleSuspendDelay=0/' ~/.config/remarkable/xochitl.conf")
|
||||
end
|
||||
|
||||
if self.powerd:hasHallSensor() then
|
||||
if G_reader_settings:has("remarkable_hall_effect_sensor_enabled") then
|
||||
self.powerd:onToggleHallSensor(G_reader_settings:readSetting("remarkable_hall_effect_sensor_enabled"))
|
||||
end
|
||||
end
|
||||
|
||||
Generic.init(self)
|
||||
end
|
||||
|
||||
@@ -303,6 +341,16 @@ function Remarkable:initNetworkManager(NetworkMgr)
|
||||
NetworkMgr.isConnected = NetworkMgr.ifHasAnAddress
|
||||
end
|
||||
|
||||
function Remarkable:exit()
|
||||
if isRmPaperPro then
|
||||
os.execute("mv -f ~/.config/remarkable/xochitl.conf.bak ~/.config/remarkable/xochitl.conf")
|
||||
if os.getenv("KO_DONT_GRAB_INPUT") == "1" then
|
||||
os.execute("~/xovi/start")
|
||||
end
|
||||
end
|
||||
Generic.exit(self)
|
||||
end
|
||||
|
||||
function Remarkable:setDateTime(year, month, day, hour, min, sec)
|
||||
if hour == nil or min == nil then return true end
|
||||
local command
|
||||
@@ -319,18 +367,33 @@ function Remarkable:saveSettings()
|
||||
end
|
||||
|
||||
function Remarkable:resume()
|
||||
if isRmPaperPro then
|
||||
os.execute("csl wifi -p on")
|
||||
else
|
||||
os.execute("./enable-wifi.sh")
|
||||
end
|
||||
end
|
||||
|
||||
function Remarkable:suspend()
|
||||
os.execute("./disable-wifi.sh")
|
||||
if isRmPaperPro then
|
||||
os.execute("csl wifi -p off")
|
||||
else
|
||||
os.execute("./disable-wifi.sh")
|
||||
end
|
||||
os.execute("systemctl suspend")
|
||||
end
|
||||
|
||||
function Remarkable:powerOff()
|
||||
if isRmPaperPro then
|
||||
os.execute("mv -f ~/.config/remarkable/xochitl.conf.bak ~/.config/remarkable/xochitl.conf")
|
||||
end
|
||||
os.execute("systemctl poweroff")
|
||||
end
|
||||
|
||||
function Remarkable:reboot()
|
||||
if isRmPaperPro then
|
||||
os.execute("mv -f ~/.config/remarkable/xochitl.conf.bak ~/.config/remarkable/xochitl.conf")
|
||||
end
|
||||
os.execute("systemctl reboot")
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
return {
|
||||
[20001] = "SleepCover",
|
||||
[102] = "Home",
|
||||
[105] = "LPgBack",
|
||||
[106] = "RPgFwd",
|
||||
[116] = "Power",
|
||||
[143] = "Resume",
|
||||
}
|
||||
-- TODO libremarkable has 143 as "wakeup" - don't know what that corresponds to?
|
||||
-- 116 is issued when the device gets to sleep, 143 when it wakes up.
|
||||
|
||||
@@ -74,6 +74,28 @@ function Remarkable_PowerD:isChargingHW()
|
||||
return self:read_str_file(self.status_file) == "Charging"
|
||||
end
|
||||
|
||||
function Remarkable_PowerD:hasHallSensor()
|
||||
return self.hall_file ~= nil
|
||||
end
|
||||
|
||||
function Remarkable_PowerD:isHallSensorEnabled()
|
||||
local int = self:read_int_file(self.hall_file)
|
||||
return int == 0
|
||||
end
|
||||
|
||||
function Remarkable_PowerD:onToggleHallSensor(toggle)
|
||||
if toggle == nil then
|
||||
-- Flip it
|
||||
toggle = self:isHallSensorEnabled() and 1 or 0
|
||||
else
|
||||
-- Honor the requested state
|
||||
toggle = toggle and 1 or 0
|
||||
end
|
||||
ffiUtil.writeToSysfs(toggle, self.hall_file)
|
||||
|
||||
G_reader_settings:saveSetting("remarkable_hall_effect_sensor_enabled", toggle == 0 and true or false)
|
||||
end
|
||||
|
||||
function Remarkable_PowerD:beforeSuspend()
|
||||
-- Inhibit user input and emit the Suspend event.
|
||||
self.device:_beforeSuspend()
|
||||
|
||||
@@ -239,9 +239,9 @@ if Device:isKobo() then
|
||||
}
|
||||
end
|
||||
|
||||
if Device:isKindle() and PowerD:hasHallSensor() then
|
||||
if PowerD:hasHallSensor() then
|
||||
common_settings.cover_events = {
|
||||
text = _("Disable Kindle cover events"),
|
||||
text = _("Disable cover events"),
|
||||
help_text = _([[Toggle the Hall effect sensor.
|
||||
This is used to detect if the cover is closed, which will automatically sleep and wake the device. If there is no cover present the sensor may cause spurious wakeups when located next to a magnetic source.]]),
|
||||
keep_menu_open = true,
|
||||
|
||||
Reference in New Issue
Block a user