bool CameraC329::getPicture(PictureType pictureType, void (*callback)(uint32_t pictureSize, uint16_t packetSize, uint32_t packetStartPosition, byte* packet)) { uint32_t pictureSize = 0; setOutputCommand(CMD_GETPICTURE, pictureType, 0, 0, 0); sendCommand(); if (!waitForACK(RESPONSE_DELAY, CMD_GETPICTURE)) return false; if (!(waitForResponse(RESPONSE_DELAY) && inputCommand[3] == CMD_DATA)) return false; pictureSize = inputCommand[7] << 8; pictureSize |= inputCommand[6] << 8; pictureSize |= inputCommand[5]; uint32_t bytePosition = 0; uint8_t package[DEFAULT_PACKAGE_SIZE]; while (bytePosition < pictureSize) { if (!waitForResponse(RESPONSE_DELAY, package, DEFAULT_PACKAGE_SIZE)) return false; callback(pictureSize, min(DEFAULT_PACKAGE_SIZE, pictureSize - bytePosition), bytePosition, package); bytePosition += DEFAULT_PACKAGE_SIZE; } return true; }
/** * Power off the camera. The camera will be unusable after calling this method * until a successful re-synchronization. * * @return True if successful, false otherwise */ bool CameraC329::powerOff() { setOutputCommand(CMD_POWEROFF, 0, 0, 0, 0); sendCommand(); if (waitForACK(RESPONSE_DELAY, CMD_POWEROFF)) return true; return false; }
/** * Resets the camera. * * @param resetType The type of reset to perform (ether a "soft" reset which * resets only the camera's internal state machine) or a "hard" reset. * * @return True if successful, false otherwise. */ bool CameraC329::reset(ResetType resetType) { setOutputCommand(CMD_RESET, resetType, 0, 0, 0xFF); sendCommand(); if (waitForACK(RESPONSE_DELAY, CMD_RESET)) return true; return false; }
/** * Takes a snapshot with the camera and stores it in the camera's internal * data buffer. Once a snapshot has been taken, use getPicture to retrieve * the photo data. * * @param pictureType The picture type to take. Should be a value from the * PictureType enumeration. * * @return True if successful, false otherwise */ bool CameraC329::takeSnapshot(PictureType pictureType) { setOutputCommand(CMD_SNAPSHOT, pictureType, 0, 0, 0); sendCommand(); if (waitForACK(RESPONSE_DELAY, CMD_SNAPSHOT)) return true; return false; }
/** * Set the quality level for compressed (JPEG) images. * * @param qualityLevel The desired quality level. Should be a value from the * QualityLevel enumeration. */ bool CameraC329::setQuality(QualityLevel qualityLevel) { setOutputCommand(CMD_QUALITY, qualityLevel, 0, 0, 0); sendCommand(); if (waitForACK(RESPONSE_DELAY, CMD_QUALITY)) return true; return false; }
/** * Sets the light frequency setting. * * @param frequencyType The frequency type to use. This should be a * value from the FrequencyType enumeration. * * @return True if successful, false otherwise */ bool CameraC328R::setLightFrequency( FrequencyType frequencyType ) { createCommand( CMD_LIGHTFREQ, (byte)frequencyType, 0, 0, 0 ); sendCommand(); if( waitForACK( RESPONSE_DELAY, CMD_LIGHTFREQ ) ) { return true; } return false; }
/** * Sets up the camera's initial image size and color type. You will * want to call this method after synchronization to set up your photo * parameters before taking a snapshot. * * @param colorType The color type setting for all photos. This should * be a value from the ColorType enumeration. * @param previewResolution The resolution to use for preview images. * This should be a value from the PreviewResolution enumeration. * @param jpegResolution The resolution to use for JPEG photos. This * should be a value from the JPEGResolution enumeration. * * @return True if successful, false otherwise. */ bool CameraC328R::initial( ColorType colorType, PreviewResolution previewResolution, JPEGResolution jpegResolution ) { createCommand( CMD_INITIAL, 0, colorType, previewResolution, jpegResolution ); sendCommand(); if( waitForACK( RESPONSE_DELAY, CMD_INITIAL ) ) { return true; } return false; }
/** * Sets the camera's initial baud rate, color type, and image sizes. Call this * method after synchronization to set up appropriate parameters before * taking a snapshot. * * @param baudRate The baud rate to use for future camera communication * @param colorType The color type * @param previewResolution The preview resolution * @param jpegResolution The JPEG resolution * * @return True if successful, false otherwise */ bool CameraC329::initialize(BaudRate baudRate, ColorType colorType, PreviewResolution previewResolution, JPEGResolution jpegResolution) { setOutputCommand(CMD_INITIAL, baudRate, colorType, previewResolution, jpegResolution); sendCommand(); if (waitForACK(RESPONSE_DELAY, CMD_INITIAL)) return true; return false; }
/** * Performs synchronization with the camera. Synchronization will be attempted * up to MAX_SYNC_ATTEMPTS. Before you can do anything with the camera, you * must synchronize! Call this method first. * * @return True if successful, false otherwise */ bool CameraC328R::sync() { uint8_t attempts = 0; bool success; // Create the sync command createCommand( CMD_SYNC, 0, 0, 0, 0 ); while( attempts < MAX_SYNC_ATTEMPTS ) { // Send a SYNC command sendCommand(); // Wait for ACK response success = waitForACK( SYNC_RESPONSE_DELAY, CMD_SYNC ); // Make sure it is an ACK if( success ) { // Now wait for a SYNC success = waitForResponse( RESPONSE_DELAY ); if( success && _receive_cmd[1] == CMD_SYNC ) { // All good, flush the buffer _serialPort.flush(); //serial_flush(); // Now send an ACK createCommand( CMD_ACK, CMD_SYNC, 0, 0, 0 ); sendCommand(); return true; } } attempts++; } return false; }
/** * Synchronize with the camera. Synchronization will be attempted up to * MAX_SYNC_ATTEMPTS. You must synchronize with the camera before you can * call other methods. * * @return True if successful, false otherwise. */ bool CameraC329::sync() { uint8_t syncAttempts = 0; bool success = false; setOutputCommand(CMD_SYNC, 0, 0, 0, 0); while (syncAttempts < MAX_SYNC_ATTEMPTS) { sendCommand(); // Wait for ACK response success = waitForACK(RESPONSE_DELAY, CMD_SYNC); // Make sure it is an ACK if (success) { // Now wait for SYNC from camera success = waitForResponse(RESPONSE_DELAY); if (success && inputCommand[3] == CMD_SYNC) { // All is good, flush the buffer Serial.flush(); // Send ACK setOutputCommand(CMD_ACK, CMD_SYNC, 0, 0, 0); sendCommand(); return true; } } syncAttempts++; } return false; }