Change util.isEmulated to boolean and fix frontlight

Device:hasFrontlight always returned a true-like value because util.isEmulated was an integer.
Fixed this, also, used a polymorphic object design to reduce FrontLight code, and
adapted BaseFrontLight for the emulator.
pull/236/head
Paulo Matias 11 years ago
parent 945c4b3470
commit d7b747d6dd

@ -8,7 +8,10 @@ Device = {
frontlight = nil,
}
BaseFrontLight = {}
BaseFrontLight = {
min = 1, max = 10,
intensity = nil,
}
KindleFrontLight = {
min = 0, max = 24,
@ -26,7 +29,7 @@ KoboFrontLight = {
function Device:getModel()
if self.model then return self.model end
if util.isEmulated()==1 then
if util.isEmulated() then
self.model = "Emulator"
return self.model
end
@ -184,18 +187,23 @@ function Device:getFrontlight()
self.frontlight = KindleFrontLight
elseif self:isKobo() then
self.frontlight = KoboFrontLight
else -- emulated FrontLight
self.frontlight = BaseFrontLight
end
if self.frontlight ~= nil then
self.frontlight:init()
end
self.frontlight:init()
end
return self.frontlight
end
function BaseFrontLight:intensityCheckBounds(intensity)
function BaseFrontLight:init() end
function BaseFrontLight:toggle() end
function BaseFrontLight:setIntensityHW() end
function BaseFrontLight:setIntensity(intensity)
intensity = intensity < self.min and self.min or intensity
intensity = intensity > self.max and self.max or intensity
self.intensity = intensity
self:setIntensityHW()
end
function KindleFrontLight:init()
@ -217,11 +225,10 @@ function KindleFrontLight:toggle()
end
end
KindleFrontLight.intensityCheckBounds = BaseFrontLight.intensityCheckBounds
KindleFrontLight.setIntensity = BaseFrontLight.setIntensity
function KindleFrontLight:setIntensity(intensity)
function KindleFrontLight:setIntensityHW()
if self.lipc_handle ~= nil then
self:intensityCheckBounds(intensity)
self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", self.intensity)
end
end
@ -236,11 +243,10 @@ function KoboFrontLight:toggle()
end
end
KoboFrontLight.intensityCheckBounds = BaseFrontLight.intensityCheckBounds
KoboFrontLight.setIntensity = BaseFrontLight.setIntensity
function KoboFrontLight:setIntensity(intensity)
function KoboFrontLight:setIntensityHW()
if self.fl ~= nil then
self:intensityCheckBounds(intensity)
self.fl:setBrightness(self.intensity)
end
end

@ -270,7 +270,7 @@ function Input:init()
self.event_map[10020] = "Charging"
self.event_map[10021] = "NotCharging"
if util.isEmulated() == 1 then
if util.isEmulated() then
self:initKeyMap()
os.remove("/tmp/emu_event")
os.execute("mkfifo /tmp/emu_event")

@ -1 +1 @@
Subproject commit cc5b399fb29e2a08105dcad38c5e6833225fcf9c
Subproject commit bc556f656b0a0f3ca211d7000ea99ec04d947494

@ -24,7 +24,7 @@ function exitReader()
input.closeAll()
if util.isEmulated() == 0 then
if not util.isEmulated() then
if Device:isKindle3() or (Device:getModel() == "KindleDXG") then
-- send double menu key press events to trigger screen refresh
os.execute("echo 'send 139' > /proc/keypad;echo 'send 139' > /proc/keypad")

Loading…
Cancel
Save