How to watch camera events on Maemo or MeeGo using Python?

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.

This article provides a code snippet showing how to watch for camera events using Python on the Maemo platform.

Article Metadata
Created: hozano (29 Aug 2008)
Last edited: lpvalente (21 Apr 2013)

The N800 and N810 devices have a integrated camera that sends signals according to her events. These signals are sent to dbus, and can be watched by applications that watch it. For instance, the Maemo camera application displays a mirrored image ever that the camera is rotated to back, watching the "camera_turned_out/in" signals.

In this case, four camera signals can be watched:

  1. camera_out: when the camera is pulled-out
  2. camera_in: when the camera is pulled-in
  3. camera_turned_out: when the camera is targeted to back
  4. camera_turned_in: when the camera is targeted to front

The simple python example below shows how to watch the camera signals.

# function called when Maemo camera is closed    
def camera_out_cb(*args):
print "-- *camera out signal* received --"
# function called when Maemo camera is opened
def camera_in_cb(*args):
print "-- *camera in signal* received --"
# function called when Maemo camera is turned out
def camera_turned_out_cb(*args):
print "-- *camera turned out signal* received --"
# function called when Maemo camera is turned in
def camera_turned_in_cb(*args):
print "-- *camera turned in signal* received --"
# setting dbus main loop (dbus requires a main loop)
import dbus
from dbus.mainloop.glib import DBusGMainLoop
# getting bus
bus = dbus.SystemBus()
# Connecting the camera signals to callback functions
bus.add_signal_receiver(camera_out_cb, dbus_interface="com.nokia.ke_recv.camera_out")
bus.add_signal_receiver(camera_in_cb, dbus_interface="com.nokia.ke_recv.camera_in")
bus.add_signal_receiver(camera_turned_out_cb, dbus_interface="com.nokia.ke_recv.camera_turned_out")
bus.add_signal_receiver(camera_turned_in_cb, dbus_interface="com.nokia.ke_recv.camera_turned_in")
# Running the main loop
import gobject
loop = gobject.MainLoop()
This page was last modified on 21 April 2013, at 01:32.
29 page views in the last 30 days.