@ -12,14 +12,58 @@ function KindlePowerD:init()
if haslipc and lipc then
self.lipc_handle = lipc.init ( " com.github.koreader.kindlepowerd " )
end
-- On devices where lipc step 0 is *not* off, we add a synthetic fl level where 0 *is* off,
-- which allows us to keep being able to use said step 0 as the first "on" step.
if not self.device : canTurnFrontlightOff ( ) then
self.fl_max = self.fl_max + 1
end
end
-- If we start with the light off (fl_intensity is fl_min), ensure a toggle will set it to the lowest "on" step,
-- and that we update fl_intensity (by using setIntensity and not _setIntensity).
function KindlePowerD : turnOnFrontlightHW ( )
self : setIntensity ( self.fl_intensity == self.fl_min and self.fl_min + 1 or self.fl_intensity )
end
-- Which means we need to get rid of the insane fl_intensity == fl_min shortcut in turnOnFrontlight, too...
-- That dates back to #2941, and I have no idea what it's supposed to help with.
function BasePowerD : turnOnFrontlight ( )
if not self.device : hasFrontlight ( ) then return end
if self : isFrontlightOn ( ) then return false end
self : turnOnFrontlightHW ( )
self.is_fl_on = true
return true
end
function KindlePowerD : frontlightIntensityHW ( )
if not self.device : hasFrontlight ( ) then return 0 end
-- Kindle stock software does not use intensity file directly, so we need to read from its
-- lipc property first.
-- Kindle stock software does not use intensity file directly, so go through lipc to keep us in sync.
if self.lipc_handle ~= nil then
return self.lipc_handle : get_int_property ( " com.lab126.powerd " , " flIntensity " )
-- Handle the step 0 switcheroo on ! canTurnFrontlightOff devices...
if self.device : canTurnFrontlightOff ( ) then
return self.lipc_handle : get_int_property ( " com.lab126.powerd " , " flIntensity " )
else
local lipc_fl_intensity = self.lipc_handle : get_int_property ( " com.lab126.powerd " , " flIntensity " )
-- NOTE: If lipc returns 0, compare against what the kernel says,
-- to avoid breaking on/off detection on devices where lipc 0 doesn't actually turn it off (<= PW3),
-- c.f., #5986
if lipc_fl_intensity == self.fl_min then
local sysfs_fl_intensity = self : _readFLIntensity ( )
if sysfs_fl_intensity ~= self.fl_min then
-- Return something potentially slightly off (as we can't be sure of the sysfs -> lipc mapping),
-- but, more importantly, something that's not fl_min (0), so we properly detect the light as on,
-- and update fl_intensity accordingly.
-- That's only tripped if it was set to fl_min from the stock UI,
-- as we ourselves *do* really turn it off when we do that.
return self.fl_min + 1
else
return self.fl_min
end
else
-- We've added a synthetic step...
return lipc_fl_intensity + 1
end
end
else
-- NOTE: This fallback is of dubious use, as it will NOT match our expected [fl_min..fl_max] range,
-- each model has a specific curve.
@ -28,6 +72,16 @@ function KindlePowerD:frontlightIntensityHW()
end
function KindlePowerD : setIntensityHW ( intensity )
-- Handle the synthetic step switcheroo on ! canTurnFrontlightOff devices...
local turn_it_off = false
if not self.device : canTurnFrontlightOff ( ) then
if intensity > 0 then
intensity = intensity - 1
else
-- And if we *really* requested 0, turn it off manually.
turn_it_off = true
end
end
-- NOTE: This means we *require* a working lipc handle to set the FL:
-- it knows what the UI values should map to for the specific hardware much better than us.
if self.lipc_handle ~= nil then
@ -35,9 +89,9 @@ function KindlePowerD:setIntensityHW(intensity)
self.lipc_handle : set_int_property (
" com.lab126.powerd " , " flIntensity " , intensity )
end
if intensity == 0 then
if turn_it_off then
-- NOTE: when intensity is 0, we want to *really* kill the light, so do it manually
-- (asking lipc to set it to 0 would in fact set it to 1 on most Kindles).
-- (asking lipc to set it to 0 would in fact set it to > 0 on ! canTurnFrontlightOff Kindles).
-- We do *both* to make the fl restore on resume less jarring on devices where lipc 0 != off.
os.execute ( " echo -n " .. intensity .. " > " .. self.fl_intensity_file )
end