LEX_Threaded_Programming

Dependencies:   Heater_V2 MODSERIAL Nanopb FastPWM ADS8568_ADC

Revision:
4:63d7f2a0dec6
Parent:
2:b27d8f9a6e49
Child:
5:702b32ead94e
diff -r da59d44aa8df -r 63d7f2a0dec6 main.cpp
--- a/main.cpp	Tue Aug 27 15:06:39 2019 +0000
+++ b/main.cpp	Wed Aug 28 15:38:19 2019 +0000
@@ -10,18 +10,16 @@
 #include <vector>
 #include <iterator>
 
-
-#define ALL_CH              15     //value of convst bus to read all chanels simultaneosly
 Heater * heater;
-float r_gradient;
-int curr_time;
+float r_gradient; //setpoint setting
+int curr_time; //FIXME: make local
 
 MODSERIAL pc(PA_9, PA_10, 512); //mcu TX, RX, 512 byte TX and RX buffers
 ADS8568_ADC adc(PB_15, PB_14, PB_13, PB_12, PC_15, PC_0, PC_1, PC_2, PC_3);
 I2C i2c(PB_7, PB_8);            //SDA, SCL
 Timer timer;
 DigitalIn adc_busy(PA_8);                   //Busy interrupt sig#
-int i;
+int i; //FIXME: separate i for every time it's used
 
 //Heater Control
 FastPWM drive_1(PC_9);
@@ -29,6 +27,9 @@
 FastPWM guard_1(PC_7);
 FastPWM guard_2(PC_6);
 
+Heater* main_heater;
+Heater* lysis_heater;
+Heater* heater;
 
 
 //indicator LEDs
@@ -66,9 +67,9 @@
 memspcr_ExperimentConfiguration exp_config = memspcr_ExperimentConfiguration_init_zero;
 int buffer_length;
 std::vector<memspcr_ThermalStep> profile;
-unsigned int c = 0;
+unsigned int c = 0; //FIXME: not global
 size_t message_length;
-uint8_t buffer[256];
+uint8_t buffer[256]; //FIXME: Needs to be longer
 
 
 
@@ -77,8 +78,10 @@
 
 void read_message()
 {
+    //FIXME: This should work with binary data
     if (pc.scanf("%d",&message_length) < 0){pc.printf("Error reading message length");}
     pc.printf("Message is %d chars long, buffer length is %d\n",message_length,buffer_length);
+    //assert message fits in buffer
     for (i = 0; i < message_length; i++) 
     {
         i = i % buffer_length;
@@ -114,7 +117,7 @@
         pc.printf("Decode callback failed\n");
     }
 
-    dest->push_back(result);
+    dest->push_back(result); //CHECK: Does result get copied into the vector?
     return true;
 }
 
@@ -178,7 +181,8 @@
     step.camera_offset_ms = 0;
     vector <memspcr_ThermalStep>::iterator it = profile.begin();
     vector <memspcr_ThermalStep>::iterator it_prev;
-    profile.insert(it,step);
+    profile.insert(it,step); //not needed - should be checked by PC
+    //just assert that profile[0] time is 0
     it++;
 
     for (it_prev = profile.begin(); it < profile.end(); it ++, it_prev++){
@@ -201,8 +205,11 @@
                 //trigger_out = 1;
                 triggered_flag = true;
             }
+            else if(triggered_flag) {
+                trigger_out = false;
+            }
 
-            wait_ms(1);
+            wait_us(200);
         }
         
     }
@@ -220,18 +227,19 @@
     buffer_length = sizeof(buffer)/sizeof(uint8_t);
     pc.printf("Input configuration file\n");
         
-    read_message();
-    
-    pc.printf("\nMessage read\n");  
-    
+    //set up nanopb
     exp_config.thermal.profile.arg = &profile;
     exp_config.thermal.profile.funcs.decode = decode_callback;
-
-
+    
+    //read and decode configuration
+    read_message();
+    pc.printf("\nMessage read\n");  
     decode_message();
     printf("\nMessage decoded\n");
-    Heater heater_(exp_config.thermal);
-    heater = &heater_;
+    
+    
+    //Heater heater_(exp_config.thermal);
+    heater = new Heater(exp_config.thermal);
     
     pc.printf("\nStarting pressure control\n");
     pressure_tick.attach(& pressure_control, 1);