Bluetooth JPEG camera library with test program build over the the original library for LS-Y201 LinkSprite JPEG Camera
Dependents: JPEGCameraTest JPEGCamera_SIM808_STM32F401RE JPEGCamera_SIM808_MPU9150_STM32F401RE
JPEGCamera.h@0:4df5706ea8d9, 2014-10-13 (annotated)
- Committer:
- thesane
- Date:
- Mon Oct 13 20:54:24 2014 +0000
- Revision:
- 0:4df5706ea8d9
modify JPEG camera to send image over serial port/bluetooth module instead of writing it to USB drive
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thesane | 0:4df5706ea8d9 | 1 | /* Arduino JPEGCamera Library |
thesane | 0:4df5706ea8d9 | 2 | * Copyright 2010 SparkFun Electronics |
thesane | 0:4df5706ea8d9 | 3 | * Written by Ryan Owens |
thesane | 0:4df5706ea8d9 | 4 | * Modified by arms22 |
thesane | 0:4df5706ea8d9 | 5 | * Ported to mbed by yamaguch |
thesane | 0:4df5706ea8d9 | 6 | * Modified by thesane |
thesane | 0:4df5706ea8d9 | 7 | */ |
thesane | 0:4df5706ea8d9 | 8 | |
thesane | 0:4df5706ea8d9 | 9 | #ifndef JPEG_CAMERA_H |
thesane | 0:4df5706ea8d9 | 10 | #define JPEG_CAMERA_H |
thesane | 0:4df5706ea8d9 | 11 | |
thesane | 0:4df5706ea8d9 | 12 | #include "mbed.h" |
thesane | 0:4df5706ea8d9 | 13 | |
thesane | 0:4df5706ea8d9 | 14 | /** |
thesane | 0:4df5706ea8d9 | 15 | * Interface for LinkSprite JPEG Camera module LS-Y201 |
thesane | 0:4df5706ea8d9 | 16 | */ |
thesane | 0:4df5706ea8d9 | 17 | class JPEGCamera : public Serial { |
thesane | 0:4df5706ea8d9 | 18 | public: |
thesane | 0:4df5706ea8d9 | 19 | /***/ |
thesane | 0:4df5706ea8d9 | 20 | enum PictureSize { |
thesane | 0:4df5706ea8d9 | 21 | SIZE160x120 = 0x22, |
thesane | 0:4df5706ea8d9 | 22 | SIZE320x240 = 0x11, |
thesane | 0:4df5706ea8d9 | 23 | SIZE640x480 = 0x00, |
thesane | 0:4df5706ea8d9 | 24 | }; |
thesane | 0:4df5706ea8d9 | 25 | |
thesane | 0:4df5706ea8d9 | 26 | /** |
thesane | 0:4df5706ea8d9 | 27 | * Create JPEG Camera |
thesane | 0:4df5706ea8d9 | 28 | * |
thesane | 0:4df5706ea8d9 | 29 | * @param tx tx pin |
thesane | 0:4df5706ea8d9 | 30 | * @param rx rx pin |
thesane | 0:4df5706ea8d9 | 31 | */ |
thesane | 0:4df5706ea8d9 | 32 | JPEGCamera(PinName tx, PinName rx); |
thesane | 0:4df5706ea8d9 | 33 | |
thesane | 0:4df5706ea8d9 | 34 | /** |
thesane | 0:4df5706ea8d9 | 35 | * Set picture size |
thesane | 0:4df5706ea8d9 | 36 | * |
thesane | 0:4df5706ea8d9 | 37 | * @param size picture size (available sizes are SIZE160x120, SIZE320x240, SIZE640x480) |
thesane | 0:4df5706ea8d9 | 38 | * @param doReset flag to perform reset operation after changing size |
thesane | 0:4df5706ea8d9 | 39 | * |
thesane | 0:4df5706ea8d9 | 40 | * @returns true if succeeded, false otherwise |
thesane | 0:4df5706ea8d9 | 41 | */ |
thesane | 0:4df5706ea8d9 | 42 | bool setPictureSize(JPEGCamera::PictureSize size, bool doReset = true); |
thesane | 0:4df5706ea8d9 | 43 | |
thesane | 0:4df5706ea8d9 | 44 | /** |
thesane | 0:4df5706ea8d9 | 45 | * Return whether camera is ready or not |
thesane | 0:4df5706ea8d9 | 46 | * |
thesane | 0:4df5706ea8d9 | 47 | * @returns true if ready, false otherwise |
thesane | 0:4df5706ea8d9 | 48 | */ |
thesane | 0:4df5706ea8d9 | 49 | bool isReady(); |
thesane | 0:4df5706ea8d9 | 50 | |
thesane | 0:4df5706ea8d9 | 51 | /** |
thesane | 0:4df5706ea8d9 | 52 | * Return whether camera is processing the taken picture or not |
thesane | 0:4df5706ea8d9 | 53 | * |
thesane | 0:4df5706ea8d9 | 54 | * @returns true if the camera is in processing, false otherwise |
thesane | 0:4df5706ea8d9 | 55 | */ |
thesane | 0:4df5706ea8d9 | 56 | bool isProcessing(); |
thesane | 0:4df5706ea8d9 | 57 | |
thesane | 0:4df5706ea8d9 | 58 | /** |
thesane | 0:4df5706ea8d9 | 59 | * Take a picture |
thesane | 0:4df5706ea8d9 | 60 | * |
thesane | 0:4df5706ea8d9 | 61 | * @param filename filename to store the picture data |
thesane | 0:4df5706ea8d9 | 62 | * @returns true if succeeded, false otherwise |
thesane | 0:4df5706ea8d9 | 63 | */ |
thesane | 0:4df5706ea8d9 | 64 | bool takePicture(); |
thesane | 0:4df5706ea8d9 | 65 | /** |
thesane | 0:4df5706ea8d9 | 66 | * Process picture (writing the file) |
thesane | 0:4df5706ea8d9 | 67 | * |
thesane | 0:4df5706ea8d9 | 68 | * @param address of serial port used to transmit the image |
thesane | 0:4df5706ea8d9 | 69 | * @returns true if no error in processing, false otherwise |
thesane | 0:4df5706ea8d9 | 70 | */ |
thesane | 0:4df5706ea8d9 | 71 | bool processPicture(Serial &control); |
thesane | 0:4df5706ea8d9 | 72 | |
thesane | 0:4df5706ea8d9 | 73 | /** |
thesane | 0:4df5706ea8d9 | 74 | * Perform reset oepration (it takes 4 seconds) |
thesane | 0:4df5706ea8d9 | 75 | * |
thesane | 0:4df5706ea8d9 | 76 | * @returns true if succeeded, false otherwise |
thesane | 0:4df5706ea8d9 | 77 | */ |
thesane | 0:4df5706ea8d9 | 78 | bool reset(); |
thesane | 0:4df5706ea8d9 | 79 | |
thesane | 0:4df5706ea8d9 | 80 | /** |
thesane | 0:4df5706ea8d9 | 81 | * Send a picture command to the camera module |
thesane | 0:4df5706ea8d9 | 82 | * |
thesane | 0:4df5706ea8d9 | 83 | * @returns true if succeeded, false otherwise |
thesane | 0:4df5706ea8d9 | 84 | */ |
thesane | 0:4df5706ea8d9 | 85 | bool takePicture_int(void); |
thesane | 0:4df5706ea8d9 | 86 | |
thesane | 0:4df5706ea8d9 | 87 | /** |
thesane | 0:4df5706ea8d9 | 88 | * Send a stop pictures command to the camera module |
thesane | 0:4df5706ea8d9 | 89 | * |
thesane | 0:4df5706ea8d9 | 90 | * @returns true if succeeded, false otherwise |
thesane | 0:4df5706ea8d9 | 91 | */ |
thesane | 0:4df5706ea8d9 | 92 | bool stopPictures(void); |
thesane | 0:4df5706ea8d9 | 93 | |
thesane | 0:4df5706ea8d9 | 94 | /** |
thesane | 0:4df5706ea8d9 | 95 | * Get the picture image size |
thesane | 0:4df5706ea8d9 | 96 | * |
thesane | 0:4df5706ea8d9 | 97 | * @returns the actual image size in bytes |
thesane | 0:4df5706ea8d9 | 98 | */ |
thesane | 0:4df5706ea8d9 | 99 | int getImageSize(); |
thesane | 0:4df5706ea8d9 | 100 | |
thesane | 0:4df5706ea8d9 | 101 | /** |
thesane | 0:4df5706ea8d9 | 102 | * Read the picture data to the buffer |
thesane | 0:4df5706ea8d9 | 103 | * |
thesane | 0:4df5706ea8d9 | 104 | * @param dataBuf data buffer address to store the received data |
thesane | 0:4df5706ea8d9 | 105 | * @param size data size to read |
thesane | 0:4df5706ea8d9 | 106 | * @param address the address of the picture data to read |
thesane | 0:4df5706ea8d9 | 107 | * |
thesane | 0:4df5706ea8d9 | 108 | * @returns the size of the data read |
thesane | 0:4df5706ea8d9 | 109 | */ |
thesane | 0:4df5706ea8d9 | 110 | int readData(char *dataBuf, int size, int address); |
thesane | 0:4df5706ea8d9 | 111 | |
thesane | 0:4df5706ea8d9 | 112 | //private: |
thesane | 0:4df5706ea8d9 | 113 | Timer timer; |
thesane | 0:4df5706ea8d9 | 114 | FILE *fp; |
thesane | 0:4df5706ea8d9 | 115 | int imageSize; |
thesane | 0:4df5706ea8d9 | 116 | int address; |
thesane | 0:4df5706ea8d9 | 117 | enum State {UNKNOWN, READY, PROCESSING, ERROR = -1} state; |
thesane | 0:4df5706ea8d9 | 118 | |
thesane | 0:4df5706ea8d9 | 119 | int sendReceive(char *buf, int sendSize, int receiveSize); |
thesane | 0:4df5706ea8d9 | 120 | int receive(char *buf, int size, int timeout); |
thesane | 0:4df5706ea8d9 | 121 | }; |
thesane | 0:4df5706ea8d9 | 122 | |
thesane | 0:4df5706ea8d9 | 123 | #endif |