From 33b54f55742618f83005be89730edc53bb80f084 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 24 Dec 2023 17:15:30 +0100 Subject: [PATCH] Kindle: Add a hasLightSensor devcap, and use it in the AutoFrontlight plugin (#11255) Add the Scribe to the list while we're there --- frontend/device/kindle/device.lua | 7 +++++++ plugins/autofrontlight.koplugin/main.lua | 6 +----- spec/unit/autofrontlight_spec.lua | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/device/kindle/device.lua b/frontend/device/kindle/device.lua index 7ce1a1b7e..e107ea25f 100644 --- a/frontend/device/kindle/device.lua +++ b/frontend/device/kindle/device.lua @@ -160,6 +160,8 @@ local Kindle = Generic:extend{ isNightModeChallenged = no, -- NOTE: While this ought to behave on Zelda/Rex, turns out, nope, it really doesn't work on *any* of 'em :/ (c.f., ko#5884). canHWDither = no, + -- Device has an Ambient Light Sensor + hasLightSensor = no, -- The time the device went into suspend suspend_time = 0, framework_lipc_handle = frameworkStopped(), @@ -508,6 +510,7 @@ local KindleVoyage = Kindle:extend{ isTouchDevice = yes, hasFrontlight = yes, canTurnFrontlightOff = no, + hasLightSensor = yes, hasKeys = yes, display_dpi = 300, touch_dev = "/dev/input/event1", @@ -526,6 +529,7 @@ local KindleOasis = Kindle:extend{ model = "KindleOasis", isTouchDevice = yes, hasFrontlight = yes, + hasLightSensor = yes, hasKeys = yes, hasGSensor = yes, display_dpi = 300, @@ -543,6 +547,7 @@ local KindleOasis2 = Kindle:extend{ isZelda = yes, isTouchDevice = yes, hasFrontlight = yes, + hasLightSensor = yes, hasKeys = yes, hasGSensor = yes, display_dpi = 300, @@ -556,6 +561,7 @@ local KindleOasis3 = Kindle:extend{ hasFrontlight = yes, hasNaturalLight = yes, hasNaturalLightMixer = yes, + hasLightSensor = yes, hasKeys = yes, hasGSensor = yes, display_dpi = 300, @@ -629,6 +635,7 @@ local KindleScribe = Kindle:extend{ -- but the mix is device-specific, we don't have access to the LUT for the mix powerd is using, -- and the widget is designed for the Kobo Aura One anyway, so, hahaha, nope. hasNaturalLightMixer = yes, + hasLightSensor = yes, hasGSensor = yes, display_dpi = 300, touch_dev = "/dev/input/by-path/platform-1001e000.i2c-event", diff --git a/plugins/autofrontlight.koplugin/main.lua b/plugins/autofrontlight.koplugin/main.lua index a0187394c..278a8b4a5 100644 --- a/plugins/autofrontlight.koplugin/main.lua +++ b/plugins/autofrontlight.koplugin/main.lua @@ -1,10 +1,6 @@ local Device = require("device") -if not Device:isKindle() or - (Device.model ~= "KindleVoyage" and - Device.model ~= "KindleOasis" and - Device.model ~= "KindleOasis2" and - Device.model ~= "KindleOasis3") then +if not (Device:isKindle() and Device:hasLightSensor()) then return { disabled = true, } end diff --git a/spec/unit/autofrontlight_spec.lua b/spec/unit/autofrontlight_spec.lua index 3ee300832..a59594b10 100644 --- a/spec/unit/autofrontlight_spec.lua +++ b/spec/unit/autofrontlight_spec.lua @@ -32,6 +32,7 @@ describe("AutoFrontlight widget tests", function() Device.model = "KindleVoyage" Device.brightness = 0 Device.hasFrontlight = function() return true end + Device.hasLightSensor = function() return true end Device.powerd = PowerD:new{ device = Device, }