upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions

API for the Serial Camera. More...

Detailed Description

The driver was tested with the Serial Camera. There is no protocol documentation currently available, so this module was developed based completely on the Seeed Studio* Arduino* sketch.

It is connected via a UART at 115,200 baud.

scam.jpg
// Instantiate a Serial Camera on UART 0
upm::SCAM camera(0);
// make sure port is initialized properly. 115200 baud is the default.
if (!camera.setupTty()) {
cerr << "Failed to setup tty port parameters" << endl;
return 1;
}
if (camera.init())
cout << "Initialized..." << endl;
else
cout << "init() failed" << endl;
if (camera.preCapture())
cout << "preCapture succeeded..." << endl;
else
cout << "preCapture failed." << endl;
if (camera.doCapture())
cout << "doCapture succeeded..." << endl;
else
cout << "doCapture failed." << endl;
cout << "Image size is " << camera.getImageSize() << " bytes" << endl;
if (camera.getImageSize() > 0) {
cout << "Storing image.jpg..." << endl;
if (camera.storeImage("image.jpg"))
cout << "storeImage succeeded..." << endl;
else
cout << "storeImage failed." << endl;
}

Public Types

enum  PIC_FORMATS_T { FORMAT_VGA = 7, FORMAT_CIF = 5, FORMAT_OCIF = 3 }
 

Public Member Functions

 SCAM (int uart, uint8_t camAddr=SCAM_DEFAULT_CAMERA_ADDR)
 
 ~SCAM ()
 
bool dataAvailable (unsigned int millis)
 
int readData (uint8_t *buffer, int len)
 
int writeData (uint8_t *buffer, int len)
 
bool setupTty (speed_t baud=B115200)
 
void drainInput ()
 
bool init ()
 
bool preCapture (PIC_FORMATS_T fmt=FORMAT_VGA)
 
bool doCapture ()
 
bool storeImage (const char *fname)
 
int getImageSize ()
 

Static Public Attributes

static const unsigned int MAX_PKT_LEN = 128
 

Protected Member Functions

int ttyFd ()
 

Constructor & Destructor Documentation

SCAM ( int  uart,
uint8_t  camAddr = SCAM_DEFAULT_CAMERA_ADDR 
)

Serial Camera constructor

Parameters
uartDefault UART to use (0 or 1)
camAddr3-bit address identifier of the camera; default is 0
~SCAM ( )

SCAM destructor

Member Function Documentation

bool dataAvailable ( unsigned int  millis)

Checks to see if there is data available for reading

Parameters
millisNumber of milliseconds to wait; 0 means no waiting.
Returns
True if there is data available for reading
int readData ( uint8_t *  buffer,
int  len 
)

Reads any available data into a user-supplied buffer. Note: the call blocks until data is available to be read. Use dataAvailable() to determine whether there is data available beforehand, to avoid blocking.

Parameters
bufferBuffer to hold the data read
lenLength of the buffer
Returns
Number of bytes read
int writeData ( uint8_t *  buffer,
int  len 
)

Writes the data in the buffer to the device

Parameters
bufferBuffer to hold the data read
lenLength of the buffer
Returns
Number of bytes written
bool setupTty ( speed_t  baud = B115200)

Sets up proper tty I/O modes and the baud rate. For this device, the default baud rate is 9,600 (B9600).

Parameters
baudDesired baud rate
Returns
True if successful
void drainInput ( )

Reads serial input and discards until no more characters are available

bool init ( )

Initializes the camera

bool preCapture ( PIC_FORMATS_T  fmt = FORMAT_VGA)

Tells the camera to prepare for a capture

Parameters
fmtOne of the PIC_FORMATS_T values
bool doCapture ( )

Starts the capture

Returns
True if successful
bool storeImage ( const char *  fname)

Stores the captured image in a file

Parameters
fnameName of the file to write
Returns
True if successful

let the games begin...

int getImageSize ( )
inline

Returns the picture length. Note: this is only valid after doCapture() has run successfully.

Returns
Image length

The documentation for this class was generated from the following files: