From 77e5eb5b8a3726278a5f9951c3a8b5631adabde1 Mon Sep 17 00:00:00 2001
From: "Michael D. M. Dryden" <mdryden@chem.utoronto.ca>
Date: Thu, 15 Oct 2015 16:44:48 -0400
Subject: [PATCH] Implements light sensor check for CA. Needs new parameter for
 CA in dstat-interface.

---
 DSTAT/src/experiment.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/DSTAT/src/experiment.c b/DSTAT/src/experiment.c
index ad3341c..efeaa07 100644
--- a/DSTAT/src/experiment.c
+++ b/DSTAT/src/experiment.c
@@ -16,6 +16,8 @@
  */
 
 #include "experiment.h"
+#include "settings.h"
+#include "tcs.h"
 #include "config/conf_board.h"
 
 //Public variable definitions
@@ -105,7 +107,7 @@ void experiment_handler(char command){
             
         case 'R': //CA - steps, step_dac[], step_seconds[]
             scanf("%hhu",&p5); //get number of steps
-            printf("#Steps: %u\n\r", p5);
+            printf("#INFO: Steps: %u\n\r", p5);
             
             //allocate arrays for steps
             uint16_t * step_dac = malloc(p5*sizeof(uint16_t));
@@ -121,12 +123,26 @@ void experiment_handler(char command){
             
             for (i=0; i<p5; i++){
                 scanf("%u", &step_dac[i]); // get voltage steps (dac units)
-                printf("#DAC: %u\n\r", step_dac[i]);
+                printf("#INFO: DAC: %u\n\r", step_dac[i]);
             }
             
             for (i=0; i<p5; i++){
                 scanf("%u", &step_seconds[i]); //get step durations (seconds)
-                printf("#Time: %u\n\r", step_seconds[i]);
+                printf("#INFO: Time: %u\n\r", step_seconds[i]);
+            }
+            
+            scanf("%hhu", &o1);
+            printf("#INFO: TCS_check: %hhu\n\r", o1);
+            if (o1 > 0) {
+                if (settings.settings.tcs_enabled > 0) {
+                    uint16_t tcs_data[4] = {0,0,0,0};
+                    tcs_readvalues(tcs_data);
+                    
+                    if (tcs_data[0] > settings.settings.tcs_clear_threshold) {
+                        printf("#ERR: Ambient light exceeds threshold %u\n\r", tcs_data[0]);
+                        return;
+                    }
+                }
             }
             
             ca_experiment(p5, step_dac, step_seconds);
-- 
GitLab