screensaver and usbplugin events support

pull/2/merge
Qingping Hou 12 years ago
parent 47ec493da1
commit 271701edfe

@ -1,4 +1,9 @@
function util.isKindle4()
Device = {
screen_saver_mode = false,
charging_mode = false,
}
function Device:isKindle4()
re_val = os.execute("cat /proc/cpuinfo | grep MX50")
if re_val == 0 then
return true
@ -7,7 +12,7 @@ function util.isKindle4()
end
end
function util.isKindle3()
function Device:isKindle3()
re_val = os.execute("cat /proc/cpuinfo | grep MX35")
if re_val == 0 then
return true
@ -16,7 +21,7 @@ function util.isKindle3()
end
end
function util.isKindle2()
function Device:isKindle2()
re_val = os.execute("cat /proc/cpuinfo | grep MX3")
if re_val == 0 then
return true
@ -24,3 +29,64 @@ function util.isKindle2()
return false
end
end
function Device:intoScreenSaver()
--os.execute("echo 'screensaver in' >> /mnt/us/event_test.txt")
if self.charging_mode == false and self.screen_saver_mode == false then
Screen:saveCurrentBB()
msg = InfoMessage:new{"Going into screensaver... "}
UIManager:show(msg)
Screen.kpv_rotation_mode = Screen.cur_rotation_mode
Screen.fb:setOrientation(Screen.native_rotation_mode)
util.sleep(1)
os.execute("killall -cont cvm")
self.screen_saver_mode = true
UIManager:close(msg)
end
end
function Device:outofScreenSaver()
--os.execute("echo 'screensaver out' >> /mnt/us/event_test.txt")
if self.screen_saver_mode == true and self.charging_mode == false then
util.usleep(1500000)
os.execute("killall -stop cvm")
Screen.fb:setOrientation(Screen.kpv_rotation_mode)
Screen:restoreFromSavedBB()
Screen.fb:refresh(0)
end
self.screen_saver_mode = false
end
function Device:usbPlugIn()
--os.execute("echo 'usb in' >> /mnt/us/event_test.txt")
if self.charging_mode == false and self.screen_saver_mode == false then
Screen:saveCurrentBB()
Screen.kpv_rotation_mode = Screen.cur_rotation_mode
Screen.fb:setOrientation(Screen.native_rotation_mode)
msg = InfoMessage:new{"Going into USB mode... "}
UIManager:show(msg)
util.sleep(1)
UIManager:close(msg)
os.execute("killall -cont cvm")
end
self.charging_mode = true
end
function Device:usbPlugOut()
--os.execute("echo 'usb out' >> /mnt/us/event_test.txt")
if self.charging_mode == true and self.screen_saver_mode == false then
util.usleep(1500000)
os.execute("killall -stop cvm")
Screen.fb:setOrientation(Screen.kpv_rotation_mode)
Screen:restoreFromSavedBB()
Screen.fb:refresh(0)
end
--@TODO signal filemanager for file changes 13.06 2012 (houqp)
--FileChooser:setPath(FileChooser.path)
--FileChooser.pagedirty = true
self.charging_mode = false
end

@ -139,6 +139,11 @@ Input = {
[191] = "RPgFwd", -- K[3] & k[4]
[193] = "LPgFwd", -- K[3] only
[194] = "Press", -- K[3] & k[4]
[10000] = "IntoSS", -- go into screen saver
[10001] = "OutOfSS", -- go out of screen saver
[10020] = "Charging",
[10021] = "NotCharging",
},
sdl_event_map = {
[10] = "1", [11] = "2", [12] = "3", [13] = "4", [14] = "5", [15] = "6", [16] = "7", [17] = "8", [18] = "9", [19] = "0",
@ -232,12 +237,12 @@ function Input:init()
local f=lfs.attributes("/dev/input/event2")
if f then
input.open("/dev/input/event2")
if util.isKindle3() then
if Device:isKindle3() then
print("Auto-detected Kindle 3")
end
end
if util.isKindle4() then
if Device:isKindle4() then
print("Auto-detected Kindle 4")
self:adjustKindle4EventMap()
end
@ -283,6 +288,20 @@ function Input:waitEvent(timeout_us, timeout_s)
keycode = self.rotation_map[self.rotation][keycode]
end
if keycode == "IntoSS" then
Device:intoScreenSaver()
return
elseif keycode == "OutOfSS" then
Device:outofScreenSaver()
return
elseif keycode == "Charging" then
Device:usbPlugIn()
return
elseif keycode == "NotCharging" then
Device:usbPlugOut()
return
end
-- handle modifier keys
if self.modifiers[keycode] ~= nil then
if ev.value == EVENT_VALUE_KEY_PRESS then

@ -94,7 +94,7 @@ function Screen:setRotationMode(mode)
end
function Screen:saveCurrentBB()
local width, height = self:getWidth(), self.getHeight()
local width, height = self:getWidth(), self:getHeight()
if not self.saved_bb then
self.saved_bb = Blitbuffer.new(width, height)
@ -103,7 +103,7 @@ function Screen:saveCurrentBB()
self.saved_bb:free()
self.saved_bb = Blitbuffer.new(width, height)
end
self.saved_bb:blitFullFrom(fb.bb)
self.saved_bb:blitFullFrom(self.fb.bb)
end
function Screen:restoreFromSavedBB()

Loading…
Cancel
Save