Vishal Rai / JPEGCamera

Fork of JPEGCamera by Hiroshi Yamaguchi

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers JPEGCamera.h Source File

JPEGCamera.h

00001 /* Arduino JPEGCamera Library
00002  * Copyright 2010 SparkFun Electronics
00003  * Written by Ryan Owens
00004  * Modified by arms22
00005  * Ported to mbed by yamaguch
00006  */
00007 
00008 #ifndef JPEG_CAMERA_H
00009 #define JPEG_CAMERA_H
00010 
00011 #include "mbed.h"
00012 
00013 /**
00014  * Interface for LinkSprite JPEG Camera module LS-Y201
00015  */
00016 class JPEGCamera : public Serial {
00017 public:
00018     /***/
00019     enum PictureSize {
00020         SIZE160x120 = 0x22,
00021         SIZE320x240 = 0x11,
00022         SIZE640x480 = 0x00,
00023     };
00024 
00025     /**
00026      * Create JPEG Camera
00027      *
00028      * @param tx tx pin
00029      * @param rx rx pin
00030      */
00031     JPEGCamera(PinName tx, PinName rx);
00032 
00033     /**
00034      * Set picture size
00035      *
00036      * @param size picture size (available sizes are SIZE160x120, SIZE320x240, SIZE640x480)
00037      * @param doReset flag to perform reset operation after changing size
00038      *
00039      * @returns true if succeeded, false otherwise
00040      */
00041     bool setPictureSize(JPEGCamera::PictureSize size, bool doReset = true);
00042 
00043     /**
00044      * Return whether camera is ready or not
00045      *
00046      * @returns true if ready, false otherwise
00047      */
00048     bool isReady();
00049 
00050     /**
00051      * Return whether camera is processing the taken picture or not
00052      *
00053      * @returns true if the camera is in processing, false otherwise
00054      */
00055     bool isProcessing();
00056 
00057     /**
00058      * Take a picture
00059      *
00060      * @param filename filename to store the picture data
00061      * @returns true if succeeded, false otherwise
00062      */
00063     bool takePicture(char *filename);
00064     /**
00065      * Process picture (writing the file)
00066      *
00067      * @returns true if no error in processing, false otherwise
00068      */
00069     bool processPicture();
00070     bool processPicture_ref();
00071     /**
00072      * Perform reset oepration (it takes 4 seconds)
00073      *
00074      * @returns true if succeeded, false otherwise
00075      */
00076     bool reset();
00077 
00078     /**
00079      * Send a picture command to the camera module
00080      *
00081      *  @returns true if succeeded, false otherwise
00082      */
00083     bool takePicture(void);
00084 
00085     /**
00086      * Send a stop pictures command to the camera module
00087      *
00088      *  @returns true if succeeded, false otherwise
00089      */
00090     bool stopPictures(void);
00091 
00092     /**
00093      * Get the picture image size
00094      *
00095      * @returns the actual image size in bytes
00096      */
00097     int getImageSize();
00098 
00099     /**
00100      * Read the picture data to the buffer
00101      *
00102      * @param dataBuf data buffer address to store the received data
00103      * @param size data size to read
00104      * @param address the address of the picture data to read
00105      *
00106      * @returns the size of the data read
00107      */
00108     int readData(char *dataBuf, int size, int address);
00109     
00110     //return the current value of imageSize
00111     int getSizeOfimage(void);
00112 //private:
00113     Timer timer;
00114     FILE *fp, *ir;
00115     int def;
00116     int imageSize;
00117     int address;
00118     enum State {UNKNOWN, READY, PROCESSING, ERROR = -1} state;
00119     
00120     int sendReceive(char *buf, int sendSize, int receiveSize);
00121     int receive(char *buf, int size, int timeout);
00122 };
00123 
00124 #endif