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


Field Summary
static boolean POWER_OFF
          Use with setPowerState(boolean) to turn the camera device off.
static boolean POWER_ON
          Use with setPowerState(boolean) to turn the camera device on.
static int SET_POWER_ERROR_CAMERA_ALREADY_ON
          Returned by setPowerState(boolean) if the camera was sent a command to power on when it was already on.
static int SET_POWER_ERROR_HARDWARE_FAILURE
          Returned by setPowerState(boolean) if the camera could not be powered on due to a hardware failure.
static int SET_POWER_SUCCESS
          Returned by setPowerState(boolean) if the camera was succesfully powered on.
 
Method Summary
 Bitmap capture(Bitmap frame)
          Grab a Capture frame at the previously selected Capture resolution.
 boolean generatePreviewImage(Bitmap dst, Bitmap src, int degrees)
          Deprecated. use preview(Bitmap) instead
 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()
          Deprecated. Use setPowerState(boolean) instead.
 void powerOn()
          Deprecated. Use setPowerState(boolean) instead.
 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)
 int setPowerState(boolean newState)
          Set the power state of the camera device.
 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
 

Field Detail

POWER_ON

public static final boolean POWER_ON
Use with setPowerState(boolean) to turn the camera device on.

Since:
4.5
See Also:
Constant Field Values

POWER_OFF

public static final boolean POWER_OFF
Use with setPowerState(boolean) to turn the camera device off.

Since:
4.5
See Also:
Constant Field Values

SET_POWER_SUCCESS

public static final int SET_POWER_SUCCESS
Returned by setPowerState(boolean) if the camera was succesfully powered on.

Since:
4.5
See Also:
Constant Field Values

SET_POWER_ERROR_HARDWARE_FAILURE

public static final int SET_POWER_ERROR_HARDWARE_FAILURE
Returned by setPowerState(boolean) if the camera could not be powered on due to a hardware failure.

Since:
4.5
See Also:
Constant Field Values

SET_POWER_ERROR_CAMERA_ALREADY_ON

public static final int SET_POWER_ERROR_CAMERA_ALREADY_ON
Returned by setPowerState(boolean) if the camera was sent a command to power on when it was already on.

Since:
4.5
See Also:
Constant Field Values
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()
Deprecated. Use setPowerState(boolean) instead.

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()
Deprecated. Use setPowerState(boolean) instead.

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.


setPowerState

public final int setPowerState(boolean newState)
Set the power state of the camera device. POWER_ON must be done first. Please only turn the camera on when you are actually using it to conserve battery life. POWER_OFF must be done last. Please turn the camera off when you are not using it to conserve battery life.

Turning on the camera when it is already on is harmless and will not reset any camera device settings.

Returns:
SET_POWER_SUCCESS if successful, SET_POWER_ERROR_HARDWARE_FAILURE if the camera could not be turned on, or SET_POWER_ERROR_CAMERA_ALREADY_ON if the camera was already on.
Since:
4.5

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).

generatePreviewImage

public final boolean generatePreviewImage(Bitmap dst,
                                          Bitmap src,
                                          int degrees)
Deprecated. use preview(Bitmap) instead