kobo(fix): prevent usb plug events from interrupting sleep

pull/2245/head
Qingping Hou 8 years ago
parent ca93494783
commit 902403bf0a

@ -265,6 +265,10 @@ function Input:handleKeyBoardEv(ev)
return return
end end
if type(keycode) == "function" then
return keycode(ev)
end
-- take device rotation into account -- take device rotation into account
if self.rotation_map[self.device.screen:getRotationMode()][keycode] then if self.rotation_map[self.device.screen:getRotationMode()][keycode] then
keycode = self.rotation_map[self.device.screen:getRotationMode()][keycode] keycode = self.rotation_map[self.device.screen:getRotationMode()][keycode]
@ -275,15 +279,6 @@ function Input:handleKeyBoardEv(ev)
return keycode return keycode
end end
-- Kobo sleep cover
if keycode == "Power_SleepCover" then
if ev.value == EVENT_VALUE_KEY_PRESS then
return "SleepCoverClosed"
else
return "SleepCoverOpened"
end
end
if keycode == "Power" then if keycode == "Power" then
-- Kobo generates Power keycode only, we need to decide whether it's -- Kobo generates Power keycode only, we need to decide whether it's
-- power-on or power-off ourselves. -- power-on or power-off ourselves.
@ -300,10 +295,6 @@ function Input:handleKeyBoardEv(ev)
end end
end end
if ev.value == EVENT_VALUE_KEY_RELEASE and keycode == "Light" then
return keycode
end
-- handle modifier keys -- handle modifier keys
if self.modifiers[keycode] ~= nil then if self.modifiers[keycode] ~= nil then
if ev.value == EVENT_VALUE_KEY_PRESS then if ev.value == EVENT_VALUE_KEY_PRESS then
@ -538,6 +529,14 @@ function Input:cleanAbsxy()
self:setCurrentMtSlot("abs_y", nil) self:setCurrentMtSlot("abs_y", nil)
end end
function Input:isEvKeyPress(ev)
return ev.value == EVENT_VALUE_KEY_PRESS
end
function Input:isEvKeyRelease(ev)
return ev.value == EVENT_VALUE_KEY_RELEASE
end
-- main event handling: -- main event handling:

@ -118,8 +118,25 @@ function Kobo:init()
self.input = require("device/input"):new{ self.input = require("device/input"):new{
device = self, device = self,
event_map = { event_map = {
[59] = "Power_SleepCover", [59] = function(ev)
[90] = "Light", if self.input:isEvKeyPress(ev) then
return "SleepCoverClosed"
else
return "SleepCoverOpened"
end
end,
[90] = function(ev)
if self.input:isEvKeyRelease(ev) then
return "Light"
end
end,
[330] = function(ev)
if self.input:isEvKeyPress(ev) then
return "USBPlugIn"
else
return "USBPlugOut"
end
end,
[102] = "Home", [102] = "Home",
[116] = "Power", [116] = "Power",
} }
@ -338,7 +355,7 @@ elseif codename == "alyssum" then
elseif codename == "pika" then elseif codename == "pika" then
return KoboPika return KoboPika
elseif codename == "daylight" then elseif codename == "daylight" then
return KoboDaylight return KoboDaylight
else else
error("unrecognized Kobo model "..codename) error("unrecognized Kobo model "..codename)
end end

@ -108,6 +108,12 @@ function UIManager:init()
self.event_handlers["Light"] = function() self.event_handlers["Light"] = function()
Device:getPowerDevice():toggleFrontlight() Device:getPowerDevice():toggleFrontlight()
end end
self.event_handlers["USBPlugIn"] = function()
if Device.screen_saver_mode then
self.event_handlers["Suspend"]()
end
end
self.event_handlers["USBPlugOut"] = self.event_handlers["USBPlugIn"]
self.event_handlers["__default__"] = function(input_event) self.event_handlers["__default__"] = function(input_event)
if Device.screen_saver_mode then if Device.screen_saver_mode then
-- Suspension in Kobo can be interrupted by screen updates. We -- Suspension in Kobo can be interrupted by screen updates. We

Loading…
Cancel
Save