this will take a image from C328 serial camera and store those images in mbed flash as html and this html page is uploaded into the server at ip:192.168.1.2
CameraC328.h@0:e1a0471e5ffb, 2010-12-15 (annotated)
- Committer:
- mitesh2patel
- Date:
- Wed Dec 15 15:01:56 2010 +0000
- Revision:
- 0:e1a0471e5ffb
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mitesh2patel | 0:e1a0471e5ffb | 1 | /** |
mitesh2patel | 0:e1a0471e5ffb | 2 | * C328-7640 device driver class (Version 0.0.6) |
mitesh2patel | 0:e1a0471e5ffb | 3 | * Reference documents: C328-7640 User Manual v3.0 2004.8.19 |
mitesh2patel | 0:e1a0471e5ffb | 4 | * |
mitesh2patel | 0:e1a0471e5ffb | 5 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
mitesh2patel | 0:e1a0471e5ffb | 6 | * http://shinta.main.jp/ |
mitesh2patel | 0:e1a0471e5ffb | 7 | */ |
mitesh2patel | 0:e1a0471e5ffb | 8 | |
mitesh2patel | 0:e1a0471e5ffb | 9 | #include "mbed.h" |
mitesh2patel | 0:e1a0471e5ffb | 10 | #include "SerialBuffered.h" |
mitesh2patel | 0:e1a0471e5ffb | 11 | |
mitesh2patel | 0:e1a0471e5ffb | 12 | #ifndef _CAMERA_C328_H_ |
mitesh2patel | 0:e1a0471e5ffb | 13 | #define _CAMERA_C328_H_ |
mitesh2patel | 0:e1a0471e5ffb | 14 | |
mitesh2patel | 0:e1a0471e5ffb | 15 | /* |
mitesh2patel | 0:e1a0471e5ffb | 16 | * Class: CameraC328 |
mitesh2patel | 0:e1a0471e5ffb | 17 | */ |
mitesh2patel | 0:e1a0471e5ffb | 18 | class CameraC328 { |
mitesh2patel | 0:e1a0471e5ffb | 19 | public: |
mitesh2patel | 0:e1a0471e5ffb | 20 | |
mitesh2patel | 0:e1a0471e5ffb | 21 | /** |
mitesh2patel | 0:e1a0471e5ffb | 22 | * Color type. |
mitesh2patel | 0:e1a0471e5ffb | 23 | */ |
mitesh2patel | 0:e1a0471e5ffb | 24 | enum ColorType { |
mitesh2patel | 0:e1a0471e5ffb | 25 | GrayScale2bit = 0x01, // 2bit for Y only |
mitesh2patel | 0:e1a0471e5ffb | 26 | GrayScale4bit = 0x02, // 4bit for Y only |
mitesh2patel | 0:e1a0471e5ffb | 27 | GrayScale8bit = 0x03, // 8bit for Y only |
mitesh2patel | 0:e1a0471e5ffb | 28 | Color12bit = 0x05, // 444 (RGB) |
mitesh2patel | 0:e1a0471e5ffb | 29 | Color16bit = 0x06, // 565 (RGB) |
mitesh2patel | 0:e1a0471e5ffb | 30 | Jpeg = 0x07 |
mitesh2patel | 0:e1a0471e5ffb | 31 | }; |
mitesh2patel | 0:e1a0471e5ffb | 32 | |
mitesh2patel | 0:e1a0471e5ffb | 33 | /** |
mitesh2patel | 0:e1a0471e5ffb | 34 | * Raw resolution. |
mitesh2patel | 0:e1a0471e5ffb | 35 | */ |
mitesh2patel | 0:e1a0471e5ffb | 36 | enum RawResolution { |
mitesh2patel | 0:e1a0471e5ffb | 37 | RawResolution80x60 = 0x01, |
mitesh2patel | 0:e1a0471e5ffb | 38 | RawResolution160x120 = 0x03 |
mitesh2patel | 0:e1a0471e5ffb | 39 | }; |
mitesh2patel | 0:e1a0471e5ffb | 40 | |
mitesh2patel | 0:e1a0471e5ffb | 41 | /** |
mitesh2patel | 0:e1a0471e5ffb | 42 | * JPEG resolution. |
mitesh2patel | 0:e1a0471e5ffb | 43 | */ |
mitesh2patel | 0:e1a0471e5ffb | 44 | enum JpegResolution { |
mitesh2patel | 0:e1a0471e5ffb | 45 | JpegResolution80x64 = 0x01, |
mitesh2patel | 0:e1a0471e5ffb | 46 | JpegResolution160x128 = 0x03, |
mitesh2patel | 0:e1a0471e5ffb | 47 | JpegResolution320x240 = 0x05, |
mitesh2patel | 0:e1a0471e5ffb | 48 | JpegResolution640x480 = 0x07 |
mitesh2patel | 0:e1a0471e5ffb | 49 | }; |
mitesh2patel | 0:e1a0471e5ffb | 50 | |
mitesh2patel | 0:e1a0471e5ffb | 51 | /** |
mitesh2patel | 0:e1a0471e5ffb | 52 | * Error number. |
mitesh2patel | 0:e1a0471e5ffb | 53 | */ |
mitesh2patel | 0:e1a0471e5ffb | 54 | enum ErrorNumber { |
mitesh2patel | 0:e1a0471e5ffb | 55 | NoError = 0x00, |
mitesh2patel | 0:e1a0471e5ffb | 56 | PictureTypeError = 0x01, |
mitesh2patel | 0:e1a0471e5ffb | 57 | PictureUpScale = 0x02, |
mitesh2patel | 0:e1a0471e5ffb | 58 | PictureScaleError = 0x03, |
mitesh2patel | 0:e1a0471e5ffb | 59 | UnexpectedReply = 0x04, |
mitesh2patel | 0:e1a0471e5ffb | 60 | SendPictureTimeout = 0x05, |
mitesh2patel | 0:e1a0471e5ffb | 61 | UnexpectedCommand = 0x06, |
mitesh2patel | 0:e1a0471e5ffb | 62 | SramJpegTypeError = 0x07, |
mitesh2patel | 0:e1a0471e5ffb | 63 | SramJpegSizeError = 0x08, |
mitesh2patel | 0:e1a0471e5ffb | 64 | PictureFormatError = 0x09, |
mitesh2patel | 0:e1a0471e5ffb | 65 | PictureSizeError = 0x0a, |
mitesh2patel | 0:e1a0471e5ffb | 66 | ParameterError = 0x0b, |
mitesh2patel | 0:e1a0471e5ffb | 67 | SendRegisterTimeout = 0x0c, |
mitesh2patel | 0:e1a0471e5ffb | 68 | CommandIdError = 0x0d, |
mitesh2patel | 0:e1a0471e5ffb | 69 | PictureNotReady = 0x0f, |
mitesh2patel | 0:e1a0471e5ffb | 70 | TransferPackageNumberError = 0x10, |
mitesh2patel | 0:e1a0471e5ffb | 71 | SetTransferPackageSizeWrong = 0x11, |
mitesh2patel | 0:e1a0471e5ffb | 72 | CommandHeaderError = 0xf0, |
mitesh2patel | 0:e1a0471e5ffb | 73 | CommandLengthError = 0xf1, |
mitesh2patel | 0:e1a0471e5ffb | 74 | SendPictureError = 0xf5, |
mitesh2patel | 0:e1a0471e5ffb | 75 | SendCommandError = 0xff |
mitesh2patel | 0:e1a0471e5ffb | 76 | }; |
mitesh2patel | 0:e1a0471e5ffb | 77 | |
mitesh2patel | 0:e1a0471e5ffb | 78 | /** |
mitesh2patel | 0:e1a0471e5ffb | 79 | * Picture type. |
mitesh2patel | 0:e1a0471e5ffb | 80 | */ |
mitesh2patel | 0:e1a0471e5ffb | 81 | enum PictureType { |
mitesh2patel | 0:e1a0471e5ffb | 82 | SnapshotPicture = 0x01, |
mitesh2patel | 0:e1a0471e5ffb | 83 | PreviewPicture = 0x02, |
mitesh2patel | 0:e1a0471e5ffb | 84 | JpegPreviewPicture = 0x05 |
mitesh2patel | 0:e1a0471e5ffb | 85 | }; |
mitesh2patel | 0:e1a0471e5ffb | 86 | |
mitesh2patel | 0:e1a0471e5ffb | 87 | /** |
mitesh2patel | 0:e1a0471e5ffb | 88 | * Snapshot type. |
mitesh2patel | 0:e1a0471e5ffb | 89 | */ |
mitesh2patel | 0:e1a0471e5ffb | 90 | enum SnapshotType { |
mitesh2patel | 0:e1a0471e5ffb | 91 | CompressedPicture = 0x00, |
mitesh2patel | 0:e1a0471e5ffb | 92 | UncompressedPicture = 0x01 |
mitesh2patel | 0:e1a0471e5ffb | 93 | }; |
mitesh2patel | 0:e1a0471e5ffb | 94 | |
mitesh2patel | 0:e1a0471e5ffb | 95 | /** |
mitesh2patel | 0:e1a0471e5ffb | 96 | * Baud rate. |
mitesh2patel | 0:e1a0471e5ffb | 97 | */ |
mitesh2patel | 0:e1a0471e5ffb | 98 | enum Baud { |
mitesh2patel | 0:e1a0471e5ffb | 99 | Baud7200 = 7200, |
mitesh2patel | 0:e1a0471e5ffb | 100 | Baud9600 = 9600, |
mitesh2patel | 0:e1a0471e5ffb | 101 | Baud14400 = 14400, |
mitesh2patel | 0:e1a0471e5ffb | 102 | Baud19200 = 19200, // Default. |
mitesh2patel | 0:e1a0471e5ffb | 103 | Baud28800 = 28800, |
mitesh2patel | 0:e1a0471e5ffb | 104 | Baud38400 = 38400, |
mitesh2patel | 0:e1a0471e5ffb | 105 | Baud57600 = 57600, |
mitesh2patel | 0:e1a0471e5ffb | 106 | Baud115200 = 115200 |
mitesh2patel | 0:e1a0471e5ffb | 107 | }; |
mitesh2patel | 0:e1a0471e5ffb | 108 | |
mitesh2patel | 0:e1a0471e5ffb | 109 | /** |
mitesh2patel | 0:e1a0471e5ffb | 110 | * Reset type. |
mitesh2patel | 0:e1a0471e5ffb | 111 | */ |
mitesh2patel | 0:e1a0471e5ffb | 112 | enum ResetType { |
mitesh2patel | 0:e1a0471e5ffb | 113 | ResetWholeSystem = 0x00, |
mitesh2patel | 0:e1a0471e5ffb | 114 | ResetStateMachines = 0x01 |
mitesh2patel | 0:e1a0471e5ffb | 115 | }; |
mitesh2patel | 0:e1a0471e5ffb | 116 | |
mitesh2patel | 0:e1a0471e5ffb | 117 | /** |
mitesh2patel | 0:e1a0471e5ffb | 118 | * Data type. |
mitesh2patel | 0:e1a0471e5ffb | 119 | */ |
mitesh2patel | 0:e1a0471e5ffb | 120 | enum DataType { |
mitesh2patel | 0:e1a0471e5ffb | 121 | DataTypeSnapshotPicture = 0x01, |
mitesh2patel | 0:e1a0471e5ffb | 122 | DataTypePreviewPicture = 0x02, |
mitesh2patel | 0:e1a0471e5ffb | 123 | DataTypeJpegPreviewPicture = 0x05 |
mitesh2patel | 0:e1a0471e5ffb | 124 | }; |
mitesh2patel | 0:e1a0471e5ffb | 125 | |
mitesh2patel | 0:e1a0471e5ffb | 126 | /** |
mitesh2patel | 0:e1a0471e5ffb | 127 | * Constructor. |
mitesh2patel | 0:e1a0471e5ffb | 128 | * |
mitesh2patel | 0:e1a0471e5ffb | 129 | * @param tx A pin for transmit. |
mitesh2patel | 0:e1a0471e5ffb | 130 | * @param rx A pin for receive. |
mitesh2patel | 0:e1a0471e5ffb | 131 | * @param baud Baud rate. (Default is Baud19200.) |
mitesh2patel | 0:e1a0471e5ffb | 132 | */ |
mitesh2patel | 0:e1a0471e5ffb | 133 | CameraC328(PinName tx, PinName rx, Baud baud = Baud115200); |
mitesh2patel | 0:e1a0471e5ffb | 134 | |
mitesh2patel | 0:e1a0471e5ffb | 135 | /** |
mitesh2patel | 0:e1a0471e5ffb | 136 | * Destructor. |
mitesh2patel | 0:e1a0471e5ffb | 137 | */ |
mitesh2patel | 0:e1a0471e5ffb | 138 | ~CameraC328(); |
mitesh2patel | 0:e1a0471e5ffb | 139 | |
mitesh2patel | 0:e1a0471e5ffb | 140 | /** |
mitesh2patel | 0:e1a0471e5ffb | 141 | * Make a sync. for baud rate. |
mitesh2patel | 0:e1a0471e5ffb | 142 | */ |
mitesh2patel | 0:e1a0471e5ffb | 143 | ErrorNumber sync(); |
mitesh2patel | 0:e1a0471e5ffb | 144 | |
mitesh2patel | 0:e1a0471e5ffb | 145 | /** |
mitesh2patel | 0:e1a0471e5ffb | 146 | * Initialize. |
mitesh2patel | 0:e1a0471e5ffb | 147 | * |
mitesh2patel | 0:e1a0471e5ffb | 148 | * @param ct Color type. |
mitesh2patel | 0:e1a0471e5ffb | 149 | * @param rr Raw resolution. |
mitesh2patel | 0:e1a0471e5ffb | 150 | * @param jr JPEG resolution. |
mitesh2patel | 0:e1a0471e5ffb | 151 | */ |
mitesh2patel | 0:e1a0471e5ffb | 152 | ErrorNumber init(ColorType ct, RawResolution rr, JpegResolution jr); |
mitesh2patel | 0:e1a0471e5ffb | 153 | |
mitesh2patel | 0:e1a0471e5ffb | 154 | /** |
mitesh2patel | 0:e1a0471e5ffb | 155 | * Get uncompressed snapshot picture. |
mitesh2patel | 0:e1a0471e5ffb | 156 | * |
mitesh2patel | 0:e1a0471e5ffb | 157 | * @param func A pointer to a callback function. |
mitesh2patel | 0:e1a0471e5ffb | 158 | * Please do NOT block this callback function. |
mitesh2patel | 0:e1a0471e5ffb | 159 | * Because the camera module transmit image datas continuously. |
mitesh2patel | 0:e1a0471e5ffb | 160 | * @return Status of the error. |
mitesh2patel | 0:e1a0471e5ffb | 161 | */ |
mitesh2patel | 0:e1a0471e5ffb | 162 | ErrorNumber getUncompressedSnapshotPicture(void(*func)(size_t done, size_t total, char c)); |
mitesh2patel | 0:e1a0471e5ffb | 163 | |
mitesh2patel | 0:e1a0471e5ffb | 164 | /** |
mitesh2patel | 0:e1a0471e5ffb | 165 | * Get uncompressed preview picture. |
mitesh2patel | 0:e1a0471e5ffb | 166 | * |
mitesh2patel | 0:e1a0471e5ffb | 167 | * @param func A pointer to a callback function. |
mitesh2patel | 0:e1a0471e5ffb | 168 | * Please do NOT block this callback function. |
mitesh2patel | 0:e1a0471e5ffb | 169 | * Because the camera module transmit image datas continuously. |
mitesh2patel | 0:e1a0471e5ffb | 170 | * @return Status of the error. |
mitesh2patel | 0:e1a0471e5ffb | 171 | */ |
mitesh2patel | 0:e1a0471e5ffb | 172 | ErrorNumber getUncompressedPreviewPicture(void(*func)(size_t done, size_t total, char c)); |
mitesh2patel | 0:e1a0471e5ffb | 173 | |
mitesh2patel | 0:e1a0471e5ffb | 174 | /** |
mitesh2patel | 0:e1a0471e5ffb | 175 | * Get JPEG snapshot picture. |
mitesh2patel | 0:e1a0471e5ffb | 176 | * |
mitesh2patel | 0:e1a0471e5ffb | 177 | * @param func A pointer to a callback function. |
mitesh2patel | 0:e1a0471e5ffb | 178 | * You can block this function until saving the image datas. |
mitesh2patel | 0:e1a0471e5ffb | 179 | * @return Status of the error. |
mitesh2patel | 0:e1a0471e5ffb | 180 | */ |
mitesh2patel | 0:e1a0471e5ffb | 181 | ErrorNumber getJpegSnapshotPicture(void(*func)(char *buf, size_t siz)); |
mitesh2patel | 0:e1a0471e5ffb | 182 | |
mitesh2patel | 0:e1a0471e5ffb | 183 | /** |
mitesh2patel | 0:e1a0471e5ffb | 184 | * Get JPEG preview picture. |
mitesh2patel | 0:e1a0471e5ffb | 185 | * |
mitesh2patel | 0:e1a0471e5ffb | 186 | * @param func A pointer to a callback function. |
mitesh2patel | 0:e1a0471e5ffb | 187 | * You can block this function until saving the image datas. |
mitesh2patel | 0:e1a0471e5ffb | 188 | * @return Status of the error. |
mitesh2patel | 0:e1a0471e5ffb | 189 | */ |
mitesh2patel | 0:e1a0471e5ffb | 190 | ErrorNumber getJpegPreviewPicture(void(*func)(char *buf, size_t siz)); |
mitesh2patel | 0:e1a0471e5ffb | 191 | |
mitesh2patel | 0:e1a0471e5ffb | 192 | private: |
mitesh2patel | 0:e1a0471e5ffb | 193 | SerialBuffered serial; |
mitesh2patel | 0:e1a0471e5ffb | 194 | static const int COMMAND_LENGTH = 6; |
mitesh2patel | 0:e1a0471e5ffb | 195 | static const int SYNCMAX = 60; |
mitesh2patel | 0:e1a0471e5ffb | 196 | static const int packageSize = 512; |
mitesh2patel | 0:e1a0471e5ffb | 197 | |
mitesh2patel | 0:e1a0471e5ffb | 198 | ErrorNumber sendInitial(ColorType ct, RawResolution rr, JpegResolution jr); |
mitesh2patel | 0:e1a0471e5ffb | 199 | ErrorNumber sendGetPicture(PictureType pt); |
mitesh2patel | 0:e1a0471e5ffb | 200 | ErrorNumber sendSnapshot(SnapshotType st, uint16_t skipFrames); |
mitesh2patel | 0:e1a0471e5ffb | 201 | ErrorNumber sendSetPackageSize(uint16_t packageSize); |
mitesh2patel | 0:e1a0471e5ffb | 202 | ErrorNumber sendSetBaudrate(Baud baud); |
mitesh2patel | 0:e1a0471e5ffb | 203 | ErrorNumber sendReset(ResetType rt, bool specialReset); |
mitesh2patel | 0:e1a0471e5ffb | 204 | ErrorNumber sendPowerOff(); |
mitesh2patel | 0:e1a0471e5ffb | 205 | ErrorNumber recvData(DataType *dt, uint32_t *length); |
mitesh2patel | 0:e1a0471e5ffb | 206 | ErrorNumber sendSync(); |
mitesh2patel | 0:e1a0471e5ffb | 207 | ErrorNumber recvSync(); |
mitesh2patel | 0:e1a0471e5ffb | 208 | ErrorNumber sendAck(uint8_t commandId, uint16_t packageId); |
mitesh2patel | 0:e1a0471e5ffb | 209 | ErrorNumber recvAckOrNck(); |
mitesh2patel | 0:e1a0471e5ffb | 210 | |
mitesh2patel | 0:e1a0471e5ffb | 211 | bool sendBytes(char *buf, size_t len, int timeout_us = 20000); |
mitesh2patel | 0:e1a0471e5ffb | 212 | bool recvBytes(char *buf, size_t len, int timeout_us = 20000); |
mitesh2patel | 0:e1a0471e5ffb | 213 | bool waitRecv(); |
mitesh2patel | 0:e1a0471e5ffb | 214 | bool waitIdle(); |
mitesh2patel | 0:e1a0471e5ffb | 215 | }; |
mitesh2patel | 0:e1a0471e5ffb | 216 | |
mitesh2patel | 0:e1a0471e5ffb | 217 | #endif |