diff options
author | Nick Van Doorn <vandoorn.nick@gmail.com> | 2017-11-05 19:08:04 -0800 |
---|---|---|
committer | Nick Van Doorn <vandoorn.nick@gmail.com> | 2017-11-05 19:08:04 -0800 |
commit | 79ba4c7d55a64e55514724514595af4c0e0cf924 (patch) | |
tree | 2e5d6e64aba864ac16741e14fde1dc946ce8e5b5 | |
parent | 9828d1d383996199297d875fc6d7941530b6bd5c (diff) |
Implement method to write snapshot to file
Mostly lifted from here https://github.com/adafruit/Adafruit-VC0706-Serial-Camera-Library/tree/master/examples/Snapshot
-rw-r--r-- | camera.c | 35 | ||||
-rw-r--r-- | camera.h | 2 |
2 files changed, 36 insertions, 1 deletions
@@ -252,3 +252,38 @@ bool setPTZ(Camera *cam, uint16_t wz, uint16_t hz, uint16_t pan, uint16_t tilt) }; return !runCommand(cam, VC0706_SET_ZOOM, args, 5); } + +bool snapshotToFile (Camera *cam, char *path, byte imgSize) { + setImageSize(cam, imgSize); + LE_INFO("Taking photo..."); + bool photoTaken = takePicture(cam); + if (photoTaken) { + LE_INFO("Photo taken"); + char writePath[100]; + // e.g /mnt/sd/<timestamp>.jpg + sprintf(writePath, "%s/%d.jpg", path, (int)time(0)); + LE_INFO("Opening file pointer for path %s", writePath); + FILE *filePtr = fopen(writePath, "w"); + if (filePtr != NULL) { + LE_INFO("Got valid file pointer"); + int jpgLen = frameLength(cam); + while (jpgLen > 0) { + byte *buff; + uint8_t bytesToRead = 32 < jpgLen ? jpgLen : 32; + buff = readPicture(cam, bytesToRead); + fwrite(buff, sizeof(*buff), bytesToRead, filePtr); + jpgLen -= bytesToRead; + } + fclose(filePtr); + return true; + } + else { + LE_ERROR("Invalid file pointer for %s", writePath); + return false; + } + } + else { + LE_ERROR("Failed to take photo"); + return false; + } +} @@ -83,4 +83,4 @@ byte getCompression (Camera *cam); bool setCompression(Camera *cam, byte c); bool getPTZ(Camera *cam, uint16_t *w, uint16_t *h, uint16_t *wz, uint16_t *hz, uint16_t *pan, uint16_t *tilt); bool setPTZ(Camera *cam, uint16_t wz, uint16_t hz, uint16_t pan, uint16_t tilt); -size_t camToFile (Camera *cam, char *path); +bool snapshotToFile (Camera *cam, char *path, byte imgSize); |