From 1d594c0adce7d98c6d85dcd7518493628c27ec75 Mon Sep 17 00:00:00 2001
From: Shahrul Kamil bin Hassan <shahrulkamil98@g.ucla.edu>
Date: Thu, 30 Sep 2021 18:42:12 +0000
Subject: [PATCH] Upload New File

---
 Code/Main Feather Code/Camera.cpp | 130 ++++++++++++++++++++++++++++++
 1 file changed, 130 insertions(+)
 create mode 100644 Code/Main Feather Code/Camera.cpp

diff --git a/Code/Main Feather Code/Camera.cpp b/Code/Main Feather Code/Camera.cpp
new file mode 100644
index 0000000..269337e
--- /dev/null
+++ b/Code/Main Feather Code/Camera.cpp	
@@ -0,0 +1,130 @@
+#include "Camera.h"
+#include <Wire.h>
+#include <Arduino.h>
+#include <openmvrpc.h>
+
+Camera::Camera(openmv::rpc_i2c_master *intface){
+  interface = intface;
+}
+
+void Camera::exe_face_detection(){
+    struct { uint16_t x, y, w, h; } face_detection_result;
+    if (interface->call_no_args(F("face_detection"), &face_detection_result, sizeof(face_detection_result))) {
+        Serial.print(F("Largest Face Detected [x="));
+        Serial.print(face_detection_result.x);
+        Serial.print(F(", y="));
+        Serial.print(face_detection_result.y);
+        Serial.print(F(", w="));
+        Serial.print(face_detection_result.w);
+        Serial.print(F(", h="));
+        Serial.print(face_detection_result.h);
+        Serial.println(F("]"));
+    }
+}
+  
+void Camera::exe_person_detection(){
+    char buff[32 + 1] = {}; // null terminator
+    if (interface->call_no_args(F("person_detection"), buff, sizeof(buff) - 1)) {
+        Serial.println(buff);
+    }
+}
+
+void Camera::exe_qrcode_detection(){
+    char buff[128 + 1] = {}; // null terminator
+    if (interface->call_no_args(F("qrcode_detection"), buff, sizeof(buff) - 1)) {
+        Serial.print("qrdetected: ");
+        Serial.println(buff);
+    }
+}
+
+bool Camera::exe_apriltag_detection(int ID,int *x_temp,int *y_temp,int *angle_temp){
+    struct { uint16_t cx, cy, rot; } result;
+    if (interface->call(F("apriltags"), &ID, sizeof(ID), &result, sizeof(result))) {
+    }
+    if (result.cx == 0 && result.cy == 0 && result.rot == 0){
+      return false;
+    } else {
+      *x_temp = result.cx;
+      *y_temp = result.cy;
+      *angle_temp = result.rot;
+      return true;
+    }
+}
+
+void Camera::exe_datamatrix_detection(){
+    char buff[128 + 1] = {}; // null terminator
+    if (interface->call_no_args(F("datamatrix_detection"), buff, sizeof(buff) - 1)) {
+        Serial.println(buff);
+    }
+}
+
+void Camera::exe_barcode_detection(){
+    char buff[128 + 1] = {}; // null terminator
+    if (interface->call_no_args(F("barcode_detection"), buff, sizeof(buff) - 1)) {
+        Serial.println(buff);
+    }
+}
+  
+bool Camera::exe_color_detection(int8_t l_min, int8_t l_max, int8_t a_min, int8_t a_max, int8_t b_min, int8_t b_max){
+    int8_t color_thresholds[6] = {l_min, l_max, a_min, a_max, b_min, b_max};
+    short buff[128 + 1] = {};
+    if (interface->call(F("color_detection"), color_thresholds, sizeof(color_thresholds), buff, sizeof(buff)-1)) {
+          int i = 0;
+          while (buff[i] != '\0' && i<100) {
+            Serial.print(buff[i]);
+            i++;  
+          }
+          Serial.println("");
+    }
+    if (buff[0] == 0){ //no blob detected
+      return false;
+    } else {
+      return true;
+    }
+}
+
+bool Camera::exe_color_detection_biggestblob(int8_t l_min, int8_t l_max, int8_t a_min, int8_t a_max, int8_t b_min, int8_t b_max, int& x, int&y){
+  int8_t color_thresholds[6] = {l_min, l_max, a_min, a_max, b_min, b_max};
+  struct { uint16_t cx, cy; } color_detection_result;
+  if (interface->call(F("color_detection_single"), color_thresholds, sizeof(color_thresholds), &color_detection_result, sizeof(color_detection_result))) {
+    
+  }
+  x = color_detection_result.cx;
+  y = color_detection_result.cy;
+  if (x == 0 && y == 0){
+    return false;
+  } else {
+    return true;
+  }
+}
+
+void Camera::exe_led_detection(){
+      //int8_t color_thresholds[6] = {l_min, l_max, a_min, a_max, b_min, b_max};
+    int8_t color_thresholds[6] = {26, 100, -108, -9, 0, -42};
+    //struct { uint16_t cx, cy; } color_detection_result;
+    short buff[128 + 1] = {};
+    if (interface->call(F("LED_detection"), color_thresholds, sizeof(color_thresholds), buff, sizeof(buff)-1)) {
+          int i = 0;
+          Serial.println("LED detected");
+          while (buff[i] != '\0' && i<100) {
+            Serial.print(buff[i]);
+            i++;  
+          }
+          Serial.println("");
+    }
+}
+
+void Camera::exe_jpeg_snapshot(){
+  
+    short buff[128 + 1] = {};
+    Serial.println("looking for image");
+    if (interface->call_no_args(F("jpeg_snapshot"), buff, sizeof(buff)-1)) {
+          Serial.println("Got JPEG");
+          int i = 0;
+          while (buff[i] != '\0') {
+            Serial.print(buff[i]);
+            i++;  
+          }
+          Serial.println("");
+    }
+}
-- 
GitLab