meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
maemo:python_and_n900 [2011/08/09 13:04]
japskua [Using Location API]
maemo:python_and_n900 [2011/08/11 09:56] (current)
japskua [Using Microphone]
Line 71: Line 71:
     sound = player.Load("button-4.wav")     sound = player.Load("button-4.wav")
     # Play the file     # Play the file
-    Player.play(sound)+    player.Play(sound)
 </file> </file>
  
Line 93: Line 93:
 <code shell> <code shell>
 sudo gainroot sudo gainroot
-apt-get install gstreamer0.10-alsa gstreamer0.10-flac+apt-get install gstreamer0.10-alsa gstreamer0.10-flac gstreamer0.10-plugins-good-extra
 </code> </code>
  
Line 132: Line 132:
 @email: japskua@gmail.com @email: japskua@gmail.com
  
-@requires: gstreamer0.10-alsa, gstreamer0.10-flac+@requires: gstreamer0.10-alsa, gstreamer0.10-flac, gstreamer0.10-plugins-good-extra
 """ """
  
Line 199: Line 199:
 ===== Using Camera ===== ===== Using Camera =====
  
-Camera stuff here+This code uses the N900's camera to take picture. It is not very sophisticated, as the back camera does not use flash (at least with the current implementation). Also, not that the Python does not really support taking pictures, thus requiring user to take pics by calling gstreamer through command line. This is an evil hack and will steal your soul. **You can only use this as a super user** Which gives me SUPER POWERS!! MUAHAHHAAHAHAA!!! 
  
 +so please, before running any camera python apps (at least based on my code) make sure you do
 +
 +<code shell>
 +sudo gainroot
 +python camera.py
 +
 +(or in scratchbox)
 +
 +fakeroot
 +python2.5 camera.py
 +</code>
 +
 +<file python camera.py>
 +"""
 +August 9, 2011
 +
 +@author: Janne Parkkila
 +@email: japskua@gmail.com
 +
 +@summary: This file contains code for taking pictures with the front or the back
 +          camera of the nokia N900. The file provides python access to the camera
 +          but really just uses command line to take picture.
 +
 +@note: PyMaemo has no possiblity to capture pictures, thus this gstreamer capture is used
 +       via command line. This requires super user rights, so if you are using this file
 +       you can only take pictures with as a sudoer.
 +
 +       ALSO! MAKE SURE THE CAMERA LID IS OPEN WHEN TAKING THE PICTURE!!! :-P
 +"""
 +import sys
 +import gst
 +import os
 +
 +
 +class Camera(object):
 +    """
 +    @summmary: This is the camera object that is capable of capturing pictures
 +               with either the front or the back camera of the device
 +    """
 +    back = None
 +    front = None
 +
 +    def __init__(self):
 +        """
 +        @summary: The Constructor
 +        """
 +        self.back = "gst-launch v4l2src device=/dev/video0 num-buffers=1 ! ffmpegcolorspace ! jpegenc ! filesink location="
 +        self.front = "gst-launch v4l2src device=/dev/video1 num-buffers=1 ! ffmpegcolorspace ! jpegenc ! filesink location="
 +
 +    def TakePicture(self, camera, filename):
 +        """
 +        @summary: The function for taking pictures with the camera
 +        @param camera: The camera to be taken pictures with
 +        @type camera: String, either "FRONT" or "BACK"
 +        @param filename: The path to the file where to save the taken picture,
 +                         without the filetype suffix.
 +        @type filename: String
 +        """
 +        photo = None
 +
 +        if camera == "FRONT":
 +            photo = self.front + filename + ".jpg"
 +        elif camera == "BACK":
 +            photo = self.back + filename + ".jpg"
 +        else:
 +            print "Error, camera should be either FRONT or BACK"
 +        
 +        os.system(photo)
 +
 +
 +
 +# If this program is executed as itself
 +if __name__ == "__main__":
 +    camera = Camera()
 +    camera.TakePicture("FRONT", "frontcam")
 +    camera.TakePicture("BACK", "backcam")
 +</file>
 ===== Bluetooth ===== ===== Bluetooth =====