danger.system
Class CameraDevice

java.lang.Object
  extended by danger.system.CameraDevice


public final class CameraDevice
extends Object

Class for communicating with a camera plugged into the device


Method Summary
 byte[] capture()
          Deprecated. As of release 3.0, replaced by capture(Bitmap)
 Bitmap capture(Bitmap frame)
          Grab a Capture frame at the previously selected Capture resolution.
 boolean generatePreviewImage(Bitmap dst, Bitmap src, int degrees)
          Quickly generates a preview image of the captured data.
 int getCaptureColorSpace()
          Return the colorspace currently selected for Capture.
 int getCaptureHeight()
          Deprecated. As of release 3.0, replaced by sendCommand(String)
 int getCaptureWidth()
          Deprecated. As of release 3.0, replaced by sendCommand(String)
 int getPreviewColorSpace()
          Return the colorspace currently selected for Preview.
 int getPreviewHeight()
          Deprecated. As of release 3.0, replaced by sendCommand(String)
 int getPreviewWidth()
          Deprecated. As of release 3.0, replaced by sendCommand(String)
 int[][] getSupportedResolutions()
          Deprecated. As of release 3.0, replaced by sendCommand(String)
static CameraDevice getSystemCamera()
          Access method for getting a handle to the camera device.
 void powerOff()
          Turn the camera device OFF.
 void powerOn()
          Turn the camera device ON.
 int preview(Bitmap b)
          Grab a Preview frame at the previously selected Preview resolution.
 String sendCommand(String command)
          Camera control/status interface.
 void setCaptureResolution(int width, int height)
          Deprecated. As of release 3.0, replaced by sendCommand(String)
 void setFlashOnCapture(boolean flash)
          Deprecated. As of release 3.0, replaced by sendCommand(String)
 void setLightCondition(boolean lowLight)
          Deprecated. As of release 3.0, replaced by sendCommand(String)
 void setPreviewResolution(int width, int height)
          Deprecated. As of release 3.0, replaced by sendCommand(String)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSystemCamera

public static CameraDevice getSystemCamera()
Access method for getting a handle to the camera device.

Currently, there is only ever one CameraDevice. You cannot create your own instance of this class.

If there is ever a device with more than one camera, we will need to extend this.

Returns:
System camera device.

powerOn

public final void powerOn()
Turn the camera device ON. This must be done first. Please only turn the camera on when you are actually using it to conserve battery life.


powerOff

public final void powerOff()
Turn the camera device OFF. This must be done last. Please turn the camera off when you are not using it to conserve battery life.


getSupportedResolutions

public final int[][] getSupportedResolutions()
Deprecated. As of release 3.0, replaced by sendCommand(String)

Return a list of supported resolutions.

Returns:
List of width,height pairs for supported resolutions.

getPreviewColorSpace

public final int getPreviewColorSpace()
Return the colorspace currently selected for Preview.

Returns:
The Preview colorspace.

getPreviewWidth

public final int getPreviewWidth()
Deprecated. As of release 3.0, replaced by sendCommand(String)

Return the width currently selected for Preview.

Returns:
The Preview width.

getPreviewHeight

public final int getPreviewHeight()
Deprecated. As of release 3.0, replaced by sendCommand(String)

Return the height currently selected for Preview.

Returns:
The Preview height.

getCaptureColorSpace

public final int getCaptureColorSpace()
Return the colorspace currently selected for Capture.

Returns:
The Capture colorspace.

getCaptureWidth

public final int getCaptureWidth()
Deprecated. As of release 3.0, replaced by sendCommand(String)

Return the width currently selected for Capture.

Returns:
The Capture width.

getCaptureHeight

public final int getCaptureHeight()
Deprecated. As of release 3.0, replaced by sendCommand(String)

Return the height currently selected for Capture.

Returns:
The Capture height.

setLightCondition

public final void setLightCondition(boolean lowLight)
Deprecated. As of release 3.0, replaced by sendCommand(String)

Select whether the camera is in low-light mode or normal mode.

Parameters:
lowLight - If True, use low-light mode. If False, use normal mode.

setFlashOnCapture

public final void setFlashOnCapture(boolean flash)
Deprecated. As of release 3.0, replaced by sendCommand(String)

Select whether the camera flash is enabled.

Note that the flash can only be enabled or disabled. The new sendCommand(String) API adds support for auto flash mode.

Parameters:
flash - If True, enable the flash. If False, disable the flash.

setPreviewResolution

public final void setPreviewResolution(int width,
                                       int height)
Deprecated. As of release 3.0, replaced by sendCommand(String)

Select the Preview resolution.

Note that no return value is provided to let you know if it succeeded.

Parameters:
width - Desired preview width.
height - Desired preview height.

setCaptureResolution

public final void setCaptureResolution(int width,
                                       int height)
Deprecated. As of release 3.0, replaced by sendCommand(String)

Select the Capture resolution.

Note that no return value is provided to let you know if it succeeded.

Parameters:
width - Desired Capture width.
height - Desired Capture height.

sendCommand

public final String sendCommand(String command)
Camera control/status interface. Commands and Status requests are passed as Strings with this format:

token,arg1,arg2,...argn

Responses depend on command/status request, but the default is:

ok

Status requests use the same token as the corresponding command, but prepended with a ? character.

Supported command/status requests:

        ?resavail                    Query available resolutions (returns list)
        resprev,width,height         Set Preview resolution
        ?resprev                     Query Preview resolution
        rescap,width,height          Set Capture resolution
        ?rescap                      Query Capture resolution
        lowlight,on/off              Set lowlight mode on or off
        ?lowlight                    Query lowlight mode
        gain,auto/0-maxgain          Set gain
        ?gain                        Query gain
        ?maxgain                     Query max allowed gain setting
        exposure,auto/0-maxexposure  Set exposure
        ?exposure                    Query exposure
        ?maxexposure                 Query max allowed exposure setting
        flash,auto/on/off            Set flash mode
        ?flash                       Query flash mode
        ?lightlevel                  Query current light level
        ?maxlightlevel               Query max possible light level
        ?sensorname                  Query the camera model
        bandingfilter,50/60          Set the banding filter for 50Hz or 60Hz mode
        ?bandingfilter               Query the banding filter setting
        noisefilter,on/off           Turn the noise filter (sharpness) on or off
        ?noisefilter                 Query the noise filter (sharpness) setting
        

Parameters:
command - Command/Status request string to process.
Returns:
Result of requested Command/Status request.

preview

public final int preview(Bitmap b)
Grab a Preview frame at the previously selected Preview resolution. The selected light mode is honored.

Parameters:
b - Bitmap with the same size and colorspace as the Preview size and colorspace.
Returns:
Error code. 0=no error, 1=size or colorspace mismatch, other=some other error.

capture

public final Bitmap capture(Bitmap frame)
Grab a Capture frame at the previously selected Capture resolution. The selected light mode is honored. If the flash is enabled, the flash is fired. If the flash is in auto mode, the camera driver decides whether or not to fire the flash based on the scene light level.

Parameters:
frame - Bitmap with the same size and colorspace as the Capture size and colorspace.
Returns:
Bitmap on success, null if there was an error (either with the provided bitmap or the capture).

capture

public final byte[] capture()
Deprecated. As of release 3.0, replaced by capture(Bitmap)

Grab a Capture frame at the previously selected Capture resolution. The selected light mode is honored. If the flash is enabled, the flash is fired. If the flash is in auto mode, the camera driver decides whether or not to fire the flash based on the scene light level.

Deprecated because of performance/user-experience issues with this method's simplistic approach to buffer allocation and JPEG encoding.

Returns:
Byte array containing JPEG data.

generatePreviewImage

public final boolean generatePreviewImage(Bitmap dst,
                                          Bitmap src,
                                          int degrees)
Quickly generates a preview image of the captured data. Scaling, rotation and colorspace conversion are supported. A NullPointerException is thrown if either the destination or source bitmap is null.

Parameters:
dst - Destination bitmap for preview image, cannot be null.
src - Source bitmap for preview image, cannot be null.
degrees - Number of degrees to rotate preview. Can be positive or negative. Specify 0 for no rotation.
Returns:
Returns true if preview image was generated, false otherwise.