abc

Dependencies:   mbed-rtos mbed pixy pixy_test

Fork of aUtO_volume_v4 by ese519

Files at this revision

API Documentation at this revision

Comitter:
jfields
Date:
Fri Dec 11 06:55:12 2015 +0000
Parent:
6:75156f40a227
Commit message:
abc

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 75156f40a227 -r 309840290ee8 main.cpp
--- a/main.cpp	Thu Dec 10 04:53:50 2015 +0000
+++ b/main.cpp	Fri Dec 11 06:55:12 2015 +0000
@@ -19,12 +19,15 @@
 // global vars
 int num_readings = 0;
 int total_y = 0;
+int numOverflows = 0;
+float total_UO = 0.0;
 float result_level = 0.0; // mL
 float result_hourly = 0.0; // mL/hr
 float prev_level = 0.0;
 
 int gotFirstReading = 0;
 int isDraining = 0;
+int gotFirstHourly = 0;
 
 // funcs and threads
 void get_volume(int i);
@@ -52,7 +55,7 @@
     
     // start hourly thread
     rate_thread = new RtosTimer(get_hourly, osTimerPeriodic, (void *)0);
-    rate_thread->start(10000);
+    rate_thread->start(15000);
 
     while (1) {
        
@@ -71,21 +74,33 @@
         check_overflow();
         
         // adjust rate
-        if (!isDraining) adjustRate();
+        //if (!isDraining) adjustRate();
     }
 }
 
 void adjustRate() {
-
+    
+    if (gotFirstHourly) {
+        if (result_hourly < 60.0) {
+            
+        }
+        else if (result_hourly < 120.0) {
+        
+        }
+        else {
+            
+        }
+    }
 }
 
 void check_overflow() {
-    if (result_level >= 30.0) { //led1 = 1;
+    if (result_level >= 30.0 && !isDraining) { //led1 = 1;
         pin1 = 0;
         pin2 = 1;
         isDraining = 1;
+        numOverflows++;
     }
-    if (result_level < 2.0) {
+    if (result_level < 4.0) {
         pin2 = 0;
         pin1 = 1;
         isDraining = 0;
@@ -95,9 +110,14 @@
 void get_hourly(void const *args) {
     pc.printf("calc'ing hourly...%f %f\r\n", result_level, prev_level);
     if (!isDraining && gotFirstReading) {
-        result_hourly = (result_level-prev_level)*6.0;
-        prev_level = result_level;
+        float temp = (result_level-prev_level)*4.0;
+        if (temp >= 0) {
+            result_hourly = temp;
+            prev_level = result_level;
+            gotFirstHourly = 1;
+        }
     }
+    if (isDraining) gotFirstReading = 0;
 }
 
 void get_volume(int y) {
@@ -111,7 +131,7 @@
         float average_y = (float)total_y/num_readings;
         result_level = -0.2642*average_y + 38.453;
         
-        if (!gotFirstReading) {
+        if (!gotFirstReading && !isDraining) {
             gotFirstReading = 1;
             prev_level = result_level;
         }
@@ -121,8 +141,8 @@
         pc.printf("%.2f %.2f\r\n", result_level, result_hourly);
         
         // to bluetooth
-        //blue.printf("y = %d, num_readings = %d, average = %.2f, mL = %.2f\r\n", y, num_readings, average_y, result);
-        blue.printf("%.2f %.2f\r\n", result_level, result_hourly);
+        if (!isDraining) total_UO = result_level+(float)numOverflows*26.0;
+        blue.printf("%.2f %.2f\r\n", total_UO, result_hourly);
 
         // reset vars
         num_readings = 0;