diff options
author | Nick Van Doorn <vandoorn.nick@gmail.com> | 2017-12-13 20:56:16 -0800 |
---|---|---|
committer | Nick Van Doorn <vandoorn.nick@gmail.com> | 2017-12-13 20:56:16 -0800 |
commit | 9fae3935776721d401890df2dd2b21abd086c202 (patch) | |
tree | 4e483e5732155cce8275fde2c4e528965a2d6eb4 /example.c | |
parent | cf8b04744d6a56fb4859dc7a5dc56295577ce7d9 (diff) |
Add example app
Diffstat (limited to 'example.c')
-rw-r--r-- | example.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/example.c b/example.c new file mode 100644 index 0000000..3436dab --- /dev/null +++ b/example.c @@ -0,0 +1,36 @@ +#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"); +}
\ No newline at end of file |