[Kobo, Mk. 7] Enable the power LED when charging (#6810)

reviewable/pr6813/r1
NiLuJe 4 years ago committed by GitHub
parent b40331085a
commit dda905271d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -56,6 +56,7 @@ local Device = {
canToggleGSensor = no,
isGSensorLocked = no,
canToggleMassStorage = no,
canToggleChargingLED = no,
canUseWAL = yes, -- requires mmap'ed I/O on the target FS
canRestart = yes,
canSuspend = yes,
@ -412,6 +413,9 @@ function Device:lockGSensor(toggle)
end
end
-- Device specific method for toggling the charging LED
function Device:toggleChargingLED(toggle) end
--[[
prepare for application shutdown
--]]

@ -189,6 +189,7 @@ local KoboPika = Kobo:new{
-- Kobo Clara HD:
local KoboNova = Kobo:new{
model = "Kobo_nova",
canToggleChargingLED = yes,
hasFrontlight = yes,
touch_snow_protocol = true,
display_dpi = 300,
@ -213,6 +214,7 @@ local KoboNova = Kobo:new{
-- There's also a CM_ROTARY_ENABLE command, but which seems to do as much nothing as the STATUS one...
local KoboFrost = Kobo:new{
model = "Kobo_frost",
canToggleChargingLED = yes,
hasFrontlight = yes,
hasKeys = yes,
hasGSensor = yes,
@ -236,6 +238,7 @@ local KoboFrost = Kobo:new{
-- NOTE: Assume the same quirks as the Forma apply.
local KoboStorm = Kobo:new{
model = "Kobo_storm",
canToggleChargingLED = yes,
hasFrontlight = yes,
hasKeys = yes,
hasGSensor = yes,
@ -259,6 +262,7 @@ local KoboStorm = Kobo:new{
--- @fixme: Untested, assume it's Clara-ish for now.
local KoboLuna = Kobo:new{
model = "Kobo_luna",
canToggleChargingLED = yes,
hasFrontlight = yes,
touch_snow_protocol = true,
display_dpi = 212,
@ -338,6 +342,12 @@ function Kobo:init()
self:initEventAdjustHooks()
end
end
-- We have no way of querying the current state of the charging LED, so, our only sane choices are:
-- * Do nothing
-- * Turn it off on startup
-- I've chosen the latter, as I find it vaguely saner, more useful, and it matches Nickel's behavior (I think).
self:toggleChargingLED(false)
end
function Kobo:setDateTime(year, month, day, hour, min, sec)
@ -740,6 +750,62 @@ function Kobo:toggleGSensor(toggle)
end
end
function Kobo:toggleChargingLED(toggle)
if not self:canToggleChargingLED() then
return
end
-- We have no way of querying the current state from the HW!
if toggle == nil then
return
end
-- NOTE: While most/all Kobos actually have a charging LED, and it can usually be fiddled with in a similar fashion,
-- we've seen *extremely* weird behavior in the past when playing with it on older devices (c.f., #5479).
-- In fact, Nickel itself doesn't provide this feature on said older devices
-- (when it does, it's an option in the Energy saving settings),
-- which is why we also limit ourselves to "true" Mk. 7 devices.
local f = io.open("/sys/devices/platform/ntx_led/lit", "w")
if not f then
logger.err("cannot open /sys/devices/platform/ntx_led/lit for writing!")
return false
end
-- c.f., strace -fittvyy -e trace=ioctl,file,signal,ipc,desc -s 256 -o /tmp/nickel.log -p $(pidof -s nickel) &
-- This was observed on a Forma, so I'm mildly hopeful that it's safe on other Mk. 7 devices ;).
if toggle == true then
-- NOTE: Technically, Nickel forces a toggle off before that, too.
-- But since we do that on startup, it shouldn't be necessary here...
f:write("ch 4")
f:flush()
f:write("cur 1")
f:flush()
f:write("dc 63")
f:flush()
else
f:write("ch 3")
f:flush()
f:write("cur 1")
f:flush()
f:write("dc 0")
f:flush()
f:write("ch 4")
f:flush()
f:write("cur 1")
f:flush()
f:write("dc 0")
f:flush()
f:write("ch 5")
f:flush()
f:write("cur 1")
f:flush()
f:write("dc 0")
f:flush()
end
io.close(f)
end
-------------- device probe ------------
local codename = Kobo:getCodeName()

@ -48,6 +48,19 @@ if Device:canToggleMassStorage() then
common_settings.mass_storage_actions = MassStorage:getActionsMenuTable()
end
if Device:canToggleChargingLED() then
-- Charging LED settings
common_settings.charging_led = {
text = _("Turn on the power LED when charging"),
checked_func = function()
return G_reader_settings:nilOrTrue("enable_charging_led")
end,
callback = function()
G_reader_settings:flipNilOrTrue("enable_charging_led")
end
}
end
-- Associate OS level file extensions (must be off by default, because we're not associated initially)
if Device:canAssociateFileExtensions() then
common_settings.file_ext_assoc = {

@ -41,12 +41,13 @@ local order = {
"keyboard_layout",
"time",
"battery",
"charging_led", -- if Device:canToggleChargingLED()
"autostandby",
"autosuspend",
"autoshutdown",
"ignore_sleepcover",
"ignore_open_sleepcover",
"mass_storage_settings",
"mass_storage_settings", -- if Device:canToggleMassStorage()
"file_ext_assoc",
"screenshot",
},

@ -62,12 +62,13 @@ local order = {
"keyboard_layout",
"time",
"battery",
"charging_led", -- if Device:canToggleChargingLED()
"autostandby",
"autosuspend",
"autoshutdown",
"ignore_sleepcover",
"ignore_open_sleepcover",
"mass_storage_settings",
"mass_storage_settings", -- if Device:canToggleMassStorage()
"file_ext_assoc",
"screenshot",
},

@ -1312,10 +1312,16 @@ function UIManager:_afterResume()
end
function UIManager:_beforeCharging()
if G_reader_settings:nilOrTrue("enable_charging_led") then
Device:toggleChargingLED(true)
end
self:broadcastEvent(Event:new("Charging"))
end
function UIManager:_afterNotCharging()
if G_reader_settings:nilOrTrue("enable_charging_led") then
Device:toggleChargingLED(false)
end
self:broadcastEvent(Event:new("NotCharging"))
end

Loading…
Cancel
Save