pachas
Dependencies: mbed QEI FastPWM
ventilator.cpp
- Committer:
- miguelangel_2511
- Date:
- 2020-04-20
- Revision:
- 7:f4e248182d31
- Parent:
- 6:d38287621cca
- Child:
- 8:208d965a3bd2
File content as of revision 7:f4e248182d31:
/* File inclusion */ #include "mbed.h" #include "stdint.h" #include "QEI.h" #include "project_defines.h" #include "buttons.h" #include "encoder_interface.h" #include "nextion_interface.h" #include "pressure_sensors.h" #include "ventilator.h" /* Global variable definition */ volatile uint8_t read_pressure_sensors_flag; volatile uint8_t pressure_sensor_display_update_flag; volatile uint8_t pressure_sensor_waveform_update_flag; uint16_t volume_setpoint = VOLUME_SETPOINT_VALUE_DEFAULT; uint16_t volume_measured = 480; uint8_t resp_frequency = RESP_FREQUENCY_VALUE_DEFAULT; float inspiration_time = INSPIRATION_TIME_VALUE_DEFAULT; float expiration_time = EXPIRATION_TIME_VALUE_DEFAULT; uint8_t pressure_measured = 16; uint8_t gas_input = AIR_INPUT; Main_Screen_State_t main_screen_state = MAIN_SCREEN_DEFAULT_STATE; uint8_t first_time_in_state = 1; /* Function definition */ void Nextion_Encoder_Interaction(void){ switch(main_screen_state){ case Main_Screen_Cursor_Disable: if(Get_Button_Press(1 << ENTER_SW)){ rotary_encoder.reset(); main_screen_state = Main_Screen_Cursor_Enable; } break; case Main_Screen_Cursor_Enable: if(first_time_in_state){ first_time_in_state = 0; Parameter_Selection_Box_Update(); }else if(parameter_selection_index_change_flag){ parameter_selection_index_change_flag = 0; Parameter_Selection_Box_Update(); }else{ //Does nothing } if(Get_Button_Press(1 << ENTER_SW)){ main_screen_state = (Main_Screen_State_t)(2 + parameter_selection_index); first_time_in_state = 1; } break; case Main_Screen_Volume_Setpoint_Adjust: if(first_time_in_state){ first_time_in_state = 0; nextion_display.printf("t6.pco=%d", ADJUST_COLOR); // Change font color nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); // pc.printf("t6.pco=%d\n\r", ADJUST_COLOR); // Change font color // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff); Volume_Setpoint_Display_Update(); }else if(volume_setpoint_index_change_flag){ volume_setpoint_index_change_flag = 0; Volume_Setpoint_Display_Update(); }else{ //Does nothing } if(Get_Button_Press(1 << ENTER_SW)){ main_screen_state = Main_Screen_Cursor_Disable; first_time_in_state = 1; Volume_Setpoint_Fix(); Parameter_Selection_Box_Remove(); } break; case Main_Screen_Resp_Frequency_Adjust: if(first_time_in_state){ first_time_in_state = 0; nextion_display.printf("t7.pco=%d", ADJUST_COLOR); // Change font color nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); // pc.printf("t7.pco=%d\n\r", ADJUST_COLOR); // Change font color // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff); Resp_Frequency_Display_Update(); }else if(resp_frequency_index_change_flag){ resp_frequency_index_change_flag = 0; Resp_Frequency_Display_Update(); }else{ //Does nothing } if(Get_Button_Press(1 << ENTER_SW)){ main_screen_state = Main_Screen_Cursor_Disable; first_time_in_state = 1; Resp_Frequency_Fix(); Parameter_Selection_Box_Remove(); } break; case Main_Screen_I_E_Ratio_Adjust: if(first_time_in_state){ first_time_in_state = 0; nextion_display.printf("t8.pco=%d", ADJUST_COLOR); // Change font color nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); //pc.printf("t8.pco=%d\n\r", ADJUST_COLOR); // Change font color // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff); I_E_Ratio_Display_Update(); }else if(i_e_ratio_index_change_flag){ i_e_ratio_index_change_flag = 0; I_E_Ratio_Display_Update(); }else{ //Does nothing } if(Get_Button_Press(1 << ENTER_SW)){ main_screen_state = Main_Screen_Cursor_Disable; first_time_in_state = 1; I_E_Ratio_Fix(); Parameter_Selection_Box_Remove(); } break; default: break; } } void Nextion_Update_Sensor_Values(void){ static float previous_pressure_01_psi = 0, previous_pressure_02_psi = 0; static float previous_diff_pressure_psi = 0; float delta; /* Check if anu value has change in a meningful way */ delta = pressure_01_psi - previous_pressure_01_psi; if((delta > PRESSURE_DISPLAY_THRESHOLD) || (delta < -PRESSURE_DISPLAY_THRESHOLD)){ Pressure_01_Display_Update(); } delta = pressure_02_psi - previous_pressure_02_psi; if((delta > PRESSURE_DISPLAY_THRESHOLD) || (delta < -PRESSURE_DISPLAY_THRESHOLD)){ Pressure_02_Display_Update(); } delta = diff_pressure_psi - previous_diff_pressure_psi; if((delta > PRESSURE_DISPLAY_THRESHOLD) || (delta < -PRESSURE_DISPLAY_THRESHOLD)){ Diff_Pressure_Display_Update(); } /* Update the previous values */ previous_pressure_01_psi = pressure_01_psi; previous_pressure_02_psi = pressure_02_psi; previous_diff_pressure_psi = diff_pressure_psi; } void Nextion_Update_Waveform_Values(void){ uint8_t pressure_graph_val; /* Plot pressure 01 in a 0 to 1 PSI scale */ pressure_graph_val = (uint8_t)(pressure_01_psi * 128); nextion_display.printf("add 10,0,%d", pressure_graph_val); nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); /* Plot pressure 02 in a 0 to 1 PSI scale */ pressure_graph_val = (uint8_t)(pressure_02_psi * 128); nextion_display.printf("add 11,0,%d", pressure_graph_val); nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); /* Plot differential pressure in a -1 PSI to 1 PSI scale */ pressure_graph_val = 64 + (uint8_t)(diff_pressure_psi * 64); nextion_display.printf("add 1,0,%d", pressure_graph_val); nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); }