Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
JPEGCamera.h@4:1354e56c7dd3, 2019-11-20 (annotated)
- Committer:
 - YUPPY
 - Date:
 - Wed Nov 20 08:06:46 2019 +0000
 - Revision:
 - 4:1354e56c7dd3
 
class_before_loading;
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| YUPPY | 4:1354e56c7dd3 | 1 | |
| YUPPY | 4:1354e56c7dd3 | 2 | /* Arduino JPEGCamera Library | 
| YUPPY | 4:1354e56c7dd3 | 3 | * Copyright 2010 SparkFun Electronics | 
| YUPPY | 4:1354e56c7dd3 | 4 | * Written by Ryan Owens | 
| YUPPY | 4:1354e56c7dd3 | 5 | * Modified by arms22 | 
| YUPPY | 4:1354e56c7dd3 | 6 | * Ported to mbed by yamaguch | 
| YUPPY | 4:1354e56c7dd3 | 7 | */ | 
| YUPPY | 4:1354e56c7dd3 | 8 | |
| YUPPY | 4:1354e56c7dd3 | 9 | #ifndef JPEG_CAMERA_H | 
| YUPPY | 4:1354e56c7dd3 | 10 | #define JPEG_CAMERA_H | 
| YUPPY | 4:1354e56c7dd3 | 11 | |
| YUPPY | 4:1354e56c7dd3 | 12 | #include "mbed.h" | 
| YUPPY | 4:1354e56c7dd3 | 13 | |
| YUPPY | 4:1354e56c7dd3 | 14 | /** | 
| YUPPY | 4:1354e56c7dd3 | 15 | * Interface for LinkSprite JPEG Camera module LS-Y201 | 
| YUPPY | 4:1354e56c7dd3 | 16 | */ | 
| YUPPY | 4:1354e56c7dd3 | 17 | class JPEGCamera : public Serial { | 
| YUPPY | 4:1354e56c7dd3 | 18 | public: | 
| YUPPY | 4:1354e56c7dd3 | 19 | /***/ | 
| YUPPY | 4:1354e56c7dd3 | 20 | enum PictureSize { | 
| YUPPY | 4:1354e56c7dd3 | 21 | SIZE160x120 = 0x22, | 
| YUPPY | 4:1354e56c7dd3 | 22 | SIZE320x240 = 0x11, | 
| YUPPY | 4:1354e56c7dd3 | 23 | SIZE640x480 = 0x00, | 
| YUPPY | 4:1354e56c7dd3 | 24 | }; | 
| YUPPY | 4:1354e56c7dd3 | 25 | |
| YUPPY | 4:1354e56c7dd3 | 26 | /** | 
| YUPPY | 4:1354e56c7dd3 | 27 | * Create JPEG Camera | 
| YUPPY | 4:1354e56c7dd3 | 28 | * | 
| YUPPY | 4:1354e56c7dd3 | 29 | * @param tx tx pin | 
| YUPPY | 4:1354e56c7dd3 | 30 | * @param rx rx pin | 
| YUPPY | 4:1354e56c7dd3 | 31 | */ | 
| YUPPY | 4:1354e56c7dd3 | 32 | JPEGCamera(PinName tx, PinName rx); | 
| YUPPY | 4:1354e56c7dd3 | 33 | |
| YUPPY | 4:1354e56c7dd3 | 34 | /** | 
| YUPPY | 4:1354e56c7dd3 | 35 | * Set picture size | 
| YUPPY | 4:1354e56c7dd3 | 36 | * | 
| YUPPY | 4:1354e56c7dd3 | 37 | * @param size picture size (available sizes are SIZE160x120, SIZE320x240, SIZE640x480) | 
| YUPPY | 4:1354e56c7dd3 | 38 | * @param doReset flag to perform reset operation after changing size | 
| YUPPY | 4:1354e56c7dd3 | 39 | * | 
| YUPPY | 4:1354e56c7dd3 | 40 | * @returns true if succeeded, false otherwise | 
| YUPPY | 4:1354e56c7dd3 | 41 | */ | 
| YUPPY | 4:1354e56c7dd3 | 42 | bool setPictureSize(JPEGCamera::PictureSize size, bool doReset = true); | 
| YUPPY | 4:1354e56c7dd3 | 43 | |
| YUPPY | 4:1354e56c7dd3 | 44 | /** | 
| YUPPY | 4:1354e56c7dd3 | 45 | * Return whether camera is ready or not | 
| YUPPY | 4:1354e56c7dd3 | 46 | * | 
| YUPPY | 4:1354e56c7dd3 | 47 | * @returns true if ready, false otherwise | 
| YUPPY | 4:1354e56c7dd3 | 48 | */ | 
| YUPPY | 4:1354e56c7dd3 | 49 | bool isReady(); | 
| YUPPY | 4:1354e56c7dd3 | 50 | |
| YUPPY | 4:1354e56c7dd3 | 51 | /** | 
| YUPPY | 4:1354e56c7dd3 | 52 | * Return whether camera is processing the taken picture or not | 
| YUPPY | 4:1354e56c7dd3 | 53 | * | 
| YUPPY | 4:1354e56c7dd3 | 54 | * @returns true if the camera is in processing, false otherwise | 
| YUPPY | 4:1354e56c7dd3 | 55 | */ | 
| YUPPY | 4:1354e56c7dd3 | 56 | bool isProcessing(); | 
| YUPPY | 4:1354e56c7dd3 | 57 | |
| YUPPY | 4:1354e56c7dd3 | 58 | /** | 
| YUPPY | 4:1354e56c7dd3 | 59 | * Take a picture | 
| YUPPY | 4:1354e56c7dd3 | 60 | * | 
| YUPPY | 4:1354e56c7dd3 | 61 | * @param filename filename to store the picture data | 
| YUPPY | 4:1354e56c7dd3 | 62 | * @returns true if succeeded, false otherwise | 
| YUPPY | 4:1354e56c7dd3 | 63 | */ | 
| YUPPY | 4:1354e56c7dd3 | 64 | bool takePicture(char *filename); | 
| YUPPY | 4:1354e56c7dd3 | 65 | /** | 
| YUPPY | 4:1354e56c7dd3 | 66 | * Process picture (writing the file) | 
| YUPPY | 4:1354e56c7dd3 | 67 | * | 
| YUPPY | 4:1354e56c7dd3 | 68 | * @returns true if no error in processing, false otherwise | 
| YUPPY | 4:1354e56c7dd3 | 69 | */ | 
| YUPPY | 4:1354e56c7dd3 | 70 | bool processPicture(); | 
| YUPPY | 4:1354e56c7dd3 | 71 | |
| YUPPY | 4:1354e56c7dd3 | 72 | /** | 
| YUPPY | 4:1354e56c7dd3 | 73 | * Perform reset oepration (it takes 4 seconds) | 
| YUPPY | 4:1354e56c7dd3 | 74 | * | 
| YUPPY | 4:1354e56c7dd3 | 75 | * @returns true if succeeded, false otherwise | 
| YUPPY | 4:1354e56c7dd3 | 76 | */ | 
| YUPPY | 4:1354e56c7dd3 | 77 | bool reset(); | 
| YUPPY | 4:1354e56c7dd3 | 78 | |
| YUPPY | 4:1354e56c7dd3 | 79 | /** | 
| YUPPY | 4:1354e56c7dd3 | 80 | * Send a picture command to the camera module | 
| YUPPY | 4:1354e56c7dd3 | 81 | * | 
| YUPPY | 4:1354e56c7dd3 | 82 | * @returns true if succeeded, false otherwise | 
| YUPPY | 4:1354e56c7dd3 | 83 | */ | 
| YUPPY | 4:1354e56c7dd3 | 84 | bool takePicture(void); | 
| YUPPY | 4:1354e56c7dd3 | 85 | |
| YUPPY | 4:1354e56c7dd3 | 86 | /** | 
| YUPPY | 4:1354e56c7dd3 | 87 | * Send a stop pictures command to the camera module | 
| YUPPY | 4:1354e56c7dd3 | 88 | * | 
| YUPPY | 4:1354e56c7dd3 | 89 | * @returns true if succeeded, false otherwise | 
| YUPPY | 4:1354e56c7dd3 | 90 | */ | 
| YUPPY | 4:1354e56c7dd3 | 91 | bool stopPictures(void); | 
| YUPPY | 4:1354e56c7dd3 | 92 | |
| YUPPY | 4:1354e56c7dd3 | 93 | /** | 
| YUPPY | 4:1354e56c7dd3 | 94 | * Get the picture image size | 
| YUPPY | 4:1354e56c7dd3 | 95 | * | 
| YUPPY | 4:1354e56c7dd3 | 96 | * @returns the actual image size in bytes | 
| YUPPY | 4:1354e56c7dd3 | 97 | */ | 
| YUPPY | 4:1354e56c7dd3 | 98 | int getImageSize(); | 
| YUPPY | 4:1354e56c7dd3 | 99 | |
| YUPPY | 4:1354e56c7dd3 | 100 | /** | 
| YUPPY | 4:1354e56c7dd3 | 101 | * Read the picture data to the buffer | 
| YUPPY | 4:1354e56c7dd3 | 102 | * | 
| YUPPY | 4:1354e56c7dd3 | 103 | * @param dataBuf data buffer address to store the received data | 
| YUPPY | 4:1354e56c7dd3 | 104 | * @param size data size to read | 
| YUPPY | 4:1354e56c7dd3 | 105 | * @param address the address of the picture data to read | 
| YUPPY | 4:1354e56c7dd3 | 106 | * | 
| YUPPY | 4:1354e56c7dd3 | 107 | * @returns the size of the data read | 
| YUPPY | 4:1354e56c7dd3 | 108 | */ | 
| YUPPY | 4:1354e56c7dd3 | 109 | int readData(char *dataBuf, int size, int address); | 
| YUPPY | 4:1354e56c7dd3 | 110 | |
| YUPPY | 4:1354e56c7dd3 | 111 | //private: | 
| YUPPY | 4:1354e56c7dd3 | 112 | Timer timer; | 
| YUPPY | 4:1354e56c7dd3 | 113 | FILE *fp; | 
| YUPPY | 4:1354e56c7dd3 | 114 | int imageSize; | 
| YUPPY | 4:1354e56c7dd3 | 115 | int address; | 
| YUPPY | 4:1354e56c7dd3 | 116 | enum State {UNKNOWN, READY, PROCESSING, ERROR = -1} state; | 
| YUPPY | 4:1354e56c7dd3 | 117 | |
| YUPPY | 4:1354e56c7dd3 | 118 | int sendReceive(char *buf, int sendSize, int receiveSize); | 
| YUPPY | 4:1354e56c7dd3 | 119 | int receive(char *buf, int size, int timeout); | 
| YUPPY | 4:1354e56c7dd3 | 120 | }; | 
| YUPPY | 4:1354e56c7dd3 | 121 | |
| YUPPY | 4:1354e56c7dd3 | 122 | #endif |