Hello World example program for the OV528 Camera Module

Dependencies:   CameraOV528

Files at this revision

API Documentation at this revision

Comitter:
jplunkett
Date:
Fri Jul 07 20:10:15 2017 +0000
Child:
1:67a9d5cee87c
Commit message:
OV528 Example init

Changed in this revision

CameraOV528.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
sd-driver.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CameraOV528.lib	Fri Jul 07 20:10:15 2017 +0000
@@ -0,0 +1,1 @@
+https://github.com/sarahmarshy/CameraOV528/#a29e2ff9a23d6811456f276c61ad2db4687ab696
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jul 07 20:10:15 2017 +0000
@@ -0,0 +1,83 @@
+#include "mbed.h"
+#include "CameraOV528.h"
+#include "FATFileSystem.h"
+#include "SDBlockDevice.h"
+#include <stdio.h>
+
+CameraOV528 camera(D1, D0);// DX, RX
+SDBlockDevice bd(PTE3, PTE1, PTE2, PTE4); // MOSI, MISO, SCLK, CS
+FATFileSystem fs("fs");
+DigitalOut led(LED_GREEN);
+DigitalIn btn(SW2);
+int picture_count;
+
+int format_fs(){
+    int error = 0;
+    printf("Welcome to the filesystem example.\r\n"
+           "Formatting a FAT, RAM-backed filesystem. ");
+    error = FATFileSystem::format(&bd);
+    if (error)
+      printf("Failure. %d\r\n", error);
+    else
+      printf("done.\r\n");
+    return error;
+}
+
+int mount_fs() {
+    printf("Mounting the filesystem on \"/fs\". ");
+    int error = fs.mount(&bd);
+    if (error)
+      printf("Failure. %d\r\n", error);
+    else
+      printf("done.\r\n");
+    return error;
+}
+
+void init_fs() {
+    if (mount_fs()) {
+        format_fs();
+        mount_fs();
+    }
+}
+
+void blink() {
+    led = !led;
+}
+
+void take_and_store_photo() {
+    blink();
+
+    if(camera.take_picture() == 0) {
+        printf("Picture taken.\r\n");
+
+        uint32_t size = camera.get_picture_size();
+        uint8_t* data_buff = (uint8_t*)malloc(size);
+        uint32_t bytes_read = camera.read_picture_data(data_buff, size);
+        char filename[30];
+        sprintf(filename, "/fs/img%d.jpg", picture_count++);
+
+        printf("Opening a new file, %s.\r\n", filename);
+
+        FILE* fd = fopen(filename, "wb");
+        fwrite(data_buff, sizeof(uint8_t), bytes_read, fd);
+        fclose(fd);
+
+        printf("Picture saved.\r\n\n");
+
+        free(data_buff);
+    }
+    else {
+        printf("Failed to take photo.\r\n\n");
+    }
+}
+
+int main() {
+    picture_count = 0;
+    init_fs();
+    camera.powerup();
+    while (true) {
+      if (!btn.read()) {
+        take_and_store_photo();
+      }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Fri Jul 07 20:10:15 2017 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#8828635da469162cf2854b5287561c663fb96e72
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sd-driver.lib	Fri Jul 07 20:10:15 2017 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/sd-driver/#29861960ca60298e884e86b89e878b1371209e0b