![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
LEX_Threaded_Programming
Dependencies: Heater_V2 MODSERIAL Nanopb FastPWM ADS8568_ADC
Diff: main.cpp
- Revision:
- 2:b27d8f9a6e49
- Parent:
- 0:54bedd3964e2
- Child:
- 4:63d7f2a0dec6
diff -r ab47101b2f7c -r b27d8f9a6e49 main.cpp --- a/main.cpp Tue Aug 27 09:23:10 2019 +0000 +++ b/main.cpp Tue Aug 27 15:04:53 2019 +0000 @@ -45,6 +45,7 @@ //Threads Thread heater_control; +Thread logging_thread; //Tickers Ticker heat_tick; @@ -56,6 +57,7 @@ bool start_flag = false; bool config_flag = false; volatile bool heater_flag = false; +volatile bool log_flag = false; bool triggered_flag = false; bool untriggered_flag = false; bool status = true; @@ -127,6 +129,10 @@ heater_flag = true; } +void log_trigger() +{ + log_flag = true; +} void pressure_control() { //Input pressure control function here @@ -141,10 +147,7 @@ led_1 = !led_1; } -void log_state() -{ - heater->log(); -} + //Other functions__________________________________________________________________ @@ -153,13 +156,20 @@ void temp_control() { while(1){ while(!heater_flag); - led_0 = !led_0; heater->read(); heater->update(); heater_flag = false; } } - + +void log_state() +{ + while(1){ + while(!log_flag); + heater->log(); + log_flag = false; + } +} void set_point_routine() { memspcr_ThermalStep step; @@ -169,6 +179,7 @@ vector <memspcr_ThermalStep>::iterator it = profile.begin(); vector <memspcr_ThermalStep>::iterator it_prev; profile.insert(it,step); + it++; for (it_prev = profile.begin(); it < profile.end(); it ++, it_prev++){ triggered_flag = false; @@ -205,6 +216,7 @@ int main() { pc.baud(115200); adc.init(); + buffer_length = sizeof(buffer)/sizeof(uint8_t); pc.printf("Input configuration file\n"); @@ -223,19 +235,22 @@ pc.printf("\nStarting pressure control\n"); pressure_tick.attach(& pressure_control, 1); - pc.printf("\nWaiting for start signal to begin temperature control\n"); + pc.printf("\nWaiting for start signal to begin temperature control (type in an s or press button 0)\n"); - while (pc.getc()!='s'); + while (pc.getcNb()!='s' && !user_0); pc.printf("Start signal received"); heater_control.start(& temp_control); - heat_tick.attach_us(& temp_trigger,exp_config.thermal.control_loop_interval); + heat_tick.attach_us(& temp_trigger,exp_config.thermal.control_loop_interval * 1000); - log_tick.attach_us(& log_state,exp_config.logging_interval_ms * 1000); + logging_thread.start(& log_state); + log_tick.attach_us(& log_trigger,exp_config.logging_interval_ms * 1000); pc.printf("\nStarting routine\n"); + timer.start(); set_point_routine(); + heater->turn_off(); pc.printf("Finished");