@ -29,17 +29,22 @@ end
-- If we start with the light off (fl_intensity is fl_min), ensure a toggle will set it to the lowest "on" step,
-- 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 setIntensityHW).
-- and that we update fl_intensity (by using setIntensity and not setIntensityHW).
function KindlePowerD : turnOnFrontlightHW ( )
function KindlePowerD : turnOnFrontlightHW ( done_callback )
self : setIntensity ( self.fl_intensity == self.fl_min and self.fl_min + 1 or self.fl_intensity )
self : setIntensity ( self.fl_intensity == self.fl_min and self.fl_min + 1 or self.fl_intensity )
return false
end
end
-- Which means we need to get rid of the insane fl_intensity == fl_min shortcut in turnOnFrontlight, too...
-- 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.
-- That dates back to #2941, and I have no idea what it's supposed to help with.
function BasePowerD: turnOnFrontlight ( )
function KindlePowerD: turnOnFrontlight ( done_callback )
if not self.device : hasFrontlight ( ) then return end
if not self.device : hasFrontlight ( ) then return end
if self : isFrontlightOn ( ) then return false end
if self : isFrontlightOn ( ) then return false end
self : turnOnFrontlightHW ( )
local cb_handled = self : turnOnFrontlightHW ( done_callback )
self.is_fl_on = true
self.is_fl_on = true
self : stateChanged ( )
self : stateChanged ( )
if not cb_handled and done_callback then
done_callback ( )
end
return true
return true
end
end
@ -79,6 +84,14 @@ function KindlePowerD:frontlightIntensityHW()
end
end
end
end
-- Make sure isFrontlightOn reflects the actual HW state,
-- as self.fl_intensity is kept as-is when toggling the light off,
-- in order to be able to toggle it back on at the right intensity.
function KindlePowerD : isFrontlightOnHW ( )
local hw_intensity = self : frontlightIntensityHW ( )
return hw_intensity > self.fl_min
end
function KindlePowerD : setIntensityHW ( intensity )
function KindlePowerD : setIntensityHW ( intensity )
-- Handle the synthetic step switcheroo on ! canTurnFrontlightOff devices...
-- Handle the synthetic step switcheroo on ! canTurnFrontlightOff devices...
local turn_it_off = false
local turn_it_off = false
@ -108,6 +121,9 @@ function KindlePowerD:setIntensityHW(intensity)
ffiUtil.writeToSysfs ( intensity , self.warmth_intensity_file )
ffiUtil.writeToSysfs ( intensity , self.warmth_intensity_file )
end
end
end
end
-- The state might have changed, make sure we don't break isFrontlightOn
self : _decideFrontlightState ( )
end
end
function KindlePowerD : frontlightWarmthHW ( )
function KindlePowerD : frontlightWarmthHW ( )
@ -182,22 +198,6 @@ function KindlePowerD:_readFLIntensity()
return self : read_int_file ( self.fl_intensity_file )
return self : read_int_file ( self.fl_intensity_file )
end
end
function KindlePowerD : afterResume ( )
if not self.device : hasFrontlight ( ) then
return
end
if self : isFrontlightOn ( ) then
-- The Kindle framework should turn the front light back on automatically.
-- The following statement ensures consistency of intensity, but should basically always be redundant,
-- since we set intensity via lipc and not sysfs ;).
-- NOTE: This is race-y, and we want to *lose* the race, hence the use of the scheduler (c.f., #4392)
UIManager : tickAfterNext ( function ( ) self : turnOnFrontlightHW ( ) end )
else
-- But in the off case, we *do* use sysfs, so this one actually matters.
UIManager : tickAfterNext ( function ( ) self : turnOffFrontlightHW ( ) end )
end
end
function KindlePowerD : toggleSuspend ( )
function KindlePowerD : toggleSuspend ( )
if self.lipc_handle then
if self.lipc_handle then
self.lipc_handle : set_int_property ( " com.lab126.powerd " , " powerButton " , 1 )
self.lipc_handle : set_int_property ( " com.lab126.powerd " , " powerButton " , 1 )
@ -293,6 +293,20 @@ function KindlePowerD:afterResume()
-- Restore user input and emit the Resume event.
-- Restore user input and emit the Resume event.
self.device : _afterResume ( )
self.device : _afterResume ( )
if not self.device : hasFrontlight ( ) then
return
end
if self : isFrontlightOn ( ) then
-- The Kindle framework should turn the front light back on automatically.
-- The following statement ensures consistency of intensity, but should basically always be redundant,
-- since we set intensity via lipc and not sysfs ;).
-- NOTE: This is race-y, and we want to *lose* the race, hence the use of the scheduler (c.f., #4392)
UIManager : tickAfterNext ( function ( ) self : turnOnFrontlightHW ( ) end )
else
-- But in the off case, we *do* use sysfs, so this one actually matters.
UIManager : tickAfterNext ( function ( ) self : turnOffFrontlightHW ( ) end )
end
end
end
function KindlePowerD : UIManagerReadyHW ( uimgr )
function KindlePowerD : UIManagerReadyHW ( uimgr )