From 5921b19512fab1531c0687a1a1593efaedc33b78 Mon Sep 17 00:00:00 2001 From: Nick Van Doorn Date: Wed, 13 Dec 2017 21:01:48 -0800 Subject: Update readme for 1.0.0 with sample code --- README.md | 140 ++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 91 insertions(+), 49 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index e8f2918..c2b1c5a 100644 --- a/README.md +++ b/README.md @@ -18,61 +18,100 @@ products from Adafruit! Original code written by Limor Fried/Ladyada for Adafruit Industries. BSD license, all text above must be included in any redistribution -## Project Status +## Releases -Still incomplete and not functional. We are currently experiencing some issues reading a complete image off the camera after taking a photo. The code is currently riddled with debug log statements but these will be cleaned up prior to release `1.0.0` +### 1.0.0 +Released on December 16, 2017 -## Usage on Other Platforms -The Legato serial API [`le_tty`](http://legato.io/legato-docs/latest/le__tty_8h.html) returns a file descriptor used to read and write. The file descriptor in the `Camera` struct can be replaced with any other file descriptor serial interface. +View the full details here [here](https://github.com/brnkl/VC0706-cam-lib-legato/releases/tag/1.0.0) -## API +## Example Usage ```c -// File descriptor helpers -LE_SHARED le_result_t fd_openCam (int *fd); -LE_SHARED void fd_closeCam (int fd); -LE_SHARED le_result_t fd_resetCamTty (int *fd); -ssize_t fd_getByte (int fd, uint8_t *data); -ssize_t fd_dataAvail (int fd, int *data); - -// Camera communication functions -void sendCommand (Camera *cam, uint8_t cmd, uint8_t args[], uint8_t nArgs); -bool runCommand (Camera *cam, uint8_t cmd, uint8_t args[], uint8_t nArgs, uint8_t respLen, bool flushFlag); -bool runCommandFlush (Camera *cam, uint8_t cmd, uint8_t args[], uint8_t nArgs, uint8_t respLen); -uint8_t readResponse (Camera *cam, uint8_t nBytes, uint8_t timeout); -bool verifyResponse (Camera *cam, uint8_t cmd); - -// High level commands to be called by -// another component that requires this one -LE_SHARED void printBuffer (Camera *cam); -LE_SHARED bool cameraFrameBuffCtrl (Camera *cam, uint8_t cmd); -LE_SHARED bool takePicture (Camera *cam); -LE_SHARED bool reset (Camera *cam); -LE_SHARED bool TVon (Camera *cam); -LE_SHARED bool TVOff (Camera *cam); -LE_SHARED uint8_t* readPicture (Camera *cam, uint8_t n); -LE_SHARED bool resumeVideo (Camera *cam); -LE_SHARED uint32_t frameLength (Camera *cam); -LE_SHARED char* getVersion (Camera *cam); -LE_SHARED uint8_t available (Camera *cam); -LE_SHARED uint8_t getDownsize (Camera *cam); -LE_SHARED bool setDownsize(Camera *cam, uint8_t newSize); -LE_SHARED uint8_t getImageSize (Camera *cam); -LE_SHARED bool setImageSize (Camera *cam, uint8_t x); -LE_SHARED bool getMotionDetect (Camera *cam); -LE_SHARED uint8_t getMotionStatus(Camera *cam, uint8_t x); -LE_SHARED bool motionDetected (Camera *cam); -LE_SHARED bool setMotionDetect (Camera *cam, bool flag); -LE_SHARED bool setMotionStatus (Camera *cam, uint8_t x, uint8_t d1, uint8_t d2); -LE_SHARED uint8_t getCompression (Camera *cam); -LE_SHARED bool setCompression(Camera *cam, uint8_t c); -LE_SHARED bool getPTZ(Camera *cam, uint16_t *w, uint16_t *h, uint16_t *wz, uint16_t *hz, uint16_t *pan, uint16_t *tilt); -LE_SHARED bool setPTZ(Camera *cam, uint16_t wz, uint16_t hz, uint16_t pan, uint16_t tilt); +#include "legato.h" +#include "interfaces.h" +#include "camera.h" + +#define RETRY_WAIT_SEC 60 + +bool takePhoto (Camera *cam, char *dirPath) { + cam->fd = fd_openCam(); + bool resetSucess = cam_reset(cam); + LE_INFO("Camera reset %s", resetSucess ? "succeeded" : "failed"); + LE_DEBUG("Taking photo..."); + bool snapshotSuccess = cam_snapshotToFile(cam, dirPath, VC0706_640x480); + LE_INFO("Snapshot %s", snapshotSuccess ? "succeeded" : "failed"); + fd_closeCam(cam->fd); + return resetSucess && snapshotSuccess; +} + +void photoLoop (Camera *cam, int intervalMintues, char *dirPath) { + LE_INFO("Taking photos every %d minutes and storing them in %s", intervalMintues, dirPath); + while (true) { + bool success = takePhoto(cam, dirPath); + int sleepDur = success ? intervalMintues * 60 : RETRY_WAIT_SEC; + if (success) LE_INFO("Taking next photo in %d minutes", intervalMintues); + else LE_INFO("Retrying after %d seconds", RETRY_WAIT_SEC); + sleep(sleepDur); + } +} + +COMPONENT_INIT { + Camera cam = { + .serialNum = 0x00, + .bufferLen = 0, + .frameptr = 0, + }; + photoLoop(&cam, 10, "/home/root/sd"); +} +``` +## API +```c // File stream functions for reading photos -uint8_t getImageBlockSize (int jpgLen); -bool readImageBlock (Camera *cam, FILE *filePtr); -bool readImageToFile (Camera *cam, char *path); -LE_SHARED bool snapshotToFile (Camera *cam, char *path, uint8_t imgSize); +LE_SHARED bool cam_snapshotToFile (Camera *cam, char *path,uint8_t imgSize); +bool cam_readImageToFile (Camera *cam, char *path); +bool cam_readImageBlock (Camera *cam, FILE *filePtr); +uint8_t cam_getImageBlockSize (int jpgLen); + +// Higher level commands +LE_SHARED bool cam_setPTZ (Camera *cam, uint16_t wz, uint16_t hz, uint16_t pan, uint16_t tilt); +LE_SHARED bool cam_getPTZ (Camera *cam, uint16_t *w, uint16_t *h, uint16_t *wz, uint16_t *hz, uint16_t *pan, uint16_t *tilt); +LE_SHARED bool cam_setCompression (Camera *cam, uint8_t c); +LE_SHARED uint8_t cam_getCompression (Camera *cam); +LE_SHARED bool cam_setMotionStatus (Camera *cam, uint8_t x, uint8_t d1, uint8_t d2); +LE_SHARED bool cam_setMotionDetect (Camera *cam, bool flag); +LE_SHARED bool cam_motionDetected (Camera *cam); +LE_SHARED uint8_t cam_getMotionStatus (Camera *cam, uint8_t x); +LE_SHARED bool cam_getMotionDetect (Camera *cam); +LE_SHARED bool cam_setImageSize (Camera *cam,uint8_t x); +LE_SHARED uint8_t cam_getImageSize (Camera *cam); +LE_SHARED bool cam_setDownsize (Camera *cam, uint8_t newSize); +LE_SHARED uint8_t cam_getDownsize (Camera *cam); +LE_SHARED uint8_t cam_available (Camera *cam); +LE_SHARED char *cam_getVersion (Camera *cam); +LE_SHARED uint32_t cam_frameLength (Camera *cam); +LE_SHARED bool cam_resumeVideo (Camera *cam); +LE_SHARED uint8_t *cam_readPicture (Camera *cam, uint8_t n); +LE_SHARED bool cam_tvOff (Camera *cam); +LE_SHARED bool cam_tvOn(Camera *cam); +LE_SHARED bool cam_reset(Camera *cam); +LE_SHARED bool cam_takePicture(Camera *cam); +LE_SHARED bool cam_frameBuffCtrl(Camera *cam, uint8_t cmd); + +// Low level camera commands +bool cam_runCommandFlush (Camera *cam, uint8_t cmd, uint8_t args[], uint8_t nArgs, uint8_t respLen); +bool cam_verifyResponse (Camera *cam, uint8_t cmd); +uint8_t cam_readResponse (Camera *cam, uint8_t nBytes, uint8_t timeout); +bool cam_runCommand (Camera *cam, uint8_t cmd, uint8_t args[], uint8_t nArgs, uint8_t respLen, bool flushFlag); +void cam_sendCommand (Camera *cam, uint8_t cmd, uint8_t args[], uint8_t nArgs); + +// Serial/file descriptor helpers +int fd_dataAvail (int fd, int *data); +ssize_t fd_getByte (int fd, uint8_t *data); +LE_SHARED int fd_closeCam (int fd); +LE_SHARED int fd_openCam (); +int fd_openSerial (const char *device, int baud); +speed_t fd_convertBaud (int baud); ``` ## Typedefs @@ -87,3 +126,6 @@ typedef struct { uint16_t frameptr; } Camera; ``` + +## Usage on Other Platforms +This code is highly decoupled from Legato with the exception of `LE_INFO` and `LE_DEBUG` log statements. In future releases this could be made more portable with pre-processor directives to redefine these macros. \ No newline at end of file -- cgit v1.2.3