Skip to content

Commit

Permalink
Kobo: Unbreak frontlight toggle for some specific values
Browse files Browse the repository at this point in the history
Because of floating point computery math stuff.

Regression since koreader#9609
c.f., koreader#9609 (comment)
  • Loading branch information
NiLuJe committed Oct 23, 2022
1 parent ee35257 commit c96bbde
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions frontend/device/kobo/powerd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,12 @@ function KoboPowerD:turnOffFrontlightHW()
return
end
ffiUtil.runInSubProcess(function()
for i = 1,5 do
self:setIntensityHW(math.floor(self.fl_intensity - ((self.fl_intensity * (1/5)) * i)))
for i = 1, 5 do
-- NOTE: Do *not* switch to (self.fl_intensity * (1/5)) here, it may lead to rounding errors,
-- which is problematic paired w/ math.floor because it doesn't round towards zero,
-- which means we may end up passing -1 to setIntensityHW, which will fail,
-- because we're bypassing the clamping usually done by setIntensity...
self:setIntensityHW(math.floor(self.fl_intensity - (self.fl_intensity / 5 * i)))
--- @note: Newer devices appear to block slightly longer on FL ioctls/sysfs, so only sleep on older devices,
--- otherwise we get a jump and not a ramp ;).
if not self.device:hasNaturalLight() then
Expand Down Expand Up @@ -335,8 +339,8 @@ function KoboPowerD:turnOnFrontlightHW()
return
end
ffiUtil.runInSubProcess(function()
for i = 1,5 do
self:setIntensityHW(math.ceil(self.fl_min + ((self.fl_intensity * (1/5)) * i)))
for i = 1, 5 do
self:setIntensityHW(math.ceil(self.fl_min + (self.fl_intensity / 5 * i)))
--- @note: Newer devices appear to block slightly longer on FL ioctls/sysfs, so only sleep on older devices,
--- otherwise we get a jump and not a ramp ;).
if not self.device:hasNaturalLight() then
Expand Down

0 comments on commit c96bbde

Please sign in to comment.