pachas

Dependencies:   mbed QEI FastPWM

Committer:
miguelangel_2511
Date:
Mon Apr 20 21:58:36 2020 +0000
Revision:
7:f4e248182d31
Parent:
6:d38287621cca
Child:
8:208d965a3bd2
Se agregaron sensores de presion, cuyos valores medidos son mostrados en la pantalla.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
miguelangel_2511 6:d38287621cca 1
miguelangel_2511 6:d38287621cca 2 #include "mbed.h"
miguelangel_2511 6:d38287621cca 3 #include "stdint.h"
miguelangel_2511 6:d38287621cca 4 #include "project_defines.h"
miguelangel_2511 6:d38287621cca 5 #include "nextion_interface.h"
miguelangel_2511 6:d38287621cca 6 #include "encoder_interface.h"
miguelangel_2511 7:f4e248182d31 7 #include "pressure_sensors.h"
miguelangel_2511 7:f4e248182d31 8 #include "stepper_motor_driver.h"
miguelangel_2511 6:d38287621cca 9 #include "ventilator.h"
miguelangel_2511 7:f4e248182d31 10
miguelangel_2511 6:d38287621cca 11
miguelangel_2511 6:d38287621cca 12 /* Object definition */
miguelangel_2511 7:f4e248182d31 13 Serial nextion_display(NEXTION_DISPLAY_TX_PIN,NEXTION_DISPLAY_RX_PIN);
miguelangel_2511 6:d38287621cca 14 // For testing pusposes only
miguelangel_2511 7:f4e248182d31 15 //Serial pc(USBTX, USBRX);
miguelangel_2511 6:d38287621cca 16
miguelangel_2511 6:d38287621cca 17 /* Global variable definition */
miguelangel_2511 6:d38287621cca 18
miguelangel_2511 6:d38287621cca 19 uint16_t volume_setpoint_display = VOLUME_SETPOINT_VALUE_DEFAULT;
miguelangel_2511 6:d38287621cca 20 uint16_t volume_measured_display = 480;
miguelangel_2511 6:d38287621cca 21 uint8_t resp_frequency_display = RESP_FREQUENCY_VALUE_DEFAULT;
miguelangel_2511 6:d38287621cca 22 float inspiration_time_display = INSPIRATION_TIME_VALUE_DEFAULT;
miguelangel_2511 6:d38287621cca 23 float expiration_time_display = EXPIRATION_TIME_VALUE_DEFAULT;
miguelangel_2511 6:d38287621cca 24 uint8_t pressure_measured_display = 16;
miguelangel_2511 6:d38287621cca 25 uint8_t gas_input_display = AIR_INPUT;
miguelangel_2511 6:d38287621cca 26
miguelangel_2511 6:d38287621cca 27 uint16_t selection_box_coordinates[3][4]={
miguelangel_2511 6:d38287621cca 28 {1,1,159,159},
miguelangel_2511 6:d38287621cca 29 {161,1,319,159},
miguelangel_2511 6:d38287621cca 30 {321,1,478, 159}
miguelangel_2511 6:d38287621cca 31 };
miguelangel_2511 6:d38287621cca 32
miguelangel_2511 6:d38287621cca 33 float i_e_ratio_display_table[I_E_RATIO_INDEX_LIMIT][2]={
miguelangel_2511 6:d38287621cca 34 {1.0,2.0},
miguelangel_2511 6:d38287621cca 35 {1.0,2.5},
miguelangel_2511 6:d38287621cca 36 {1.0,3.0}
miguelangel_2511 6:d38287621cca 37 };
miguelangel_2511 6:d38287621cca 38
miguelangel_2511 6:d38287621cca 39
miguelangel_2511 6:d38287621cca 40 /* Function definition */
miguelangel_2511 6:d38287621cca 41
miguelangel_2511 6:d38287621cca 42 void Nextion_Interface_Initialize(void){
miguelangel_2511 6:d38287621cca 43 /* Configure baud rate */
miguelangel_2511 7:f4e248182d31 44 nextion_display.baud(NEXTION_DISPLAY_BAUD_RATE);
miguelangel_2511 7:f4e248182d31 45 //pc.baud(115200);
miguelangel_2511 6:d38287621cca 46
miguelangel_2511 7:f4e248182d31 47 //pc.printf("PUERTO SERIAL HABILITADO\n\n\r");
miguelangel_2511 6:d38287621cca 48
miguelangel_2511 6:d38287621cca 49 /* Set font color */
miguelangel_2511 6:d38287621cca 50 nextion_display.printf("t6.pco=%d", NORMAL_COLOR);
miguelangel_2511 6:d38287621cca 51 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 52 nextion_display.printf("t7.pco=%d", NORMAL_COLOR);
miguelangel_2511 6:d38287621cca 53 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 54 nextion_display.printf("t8.pco=%d", NORMAL_COLOR);
miguelangel_2511 6:d38287621cca 55 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 56
miguelangel_2511 7:f4e248182d31 57 // pc.printf("t6.pco=%d\n\r", NORMAL_COLOR);
miguelangel_2511 7:f4e248182d31 58 //pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 59 // pc.printf("t7.pco=%d\n\r", NORMAL_COLOR);
miguelangel_2511 7:f4e248182d31 60 // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 61 // pc.printf("t8.pco=%d\n\r", NORMAL_COLOR);
miguelangel_2511 7:f4e248182d31 62 //pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 63
miguelangel_2511 6:d38287621cca 64 /* Print default values */
miguelangel_2511 6:d38287621cca 65 Volume_Setpoint_Fix();
miguelangel_2511 6:d38287621cca 66 Resp_Frequency_Fix();
miguelangel_2511 6:d38287621cca 67 I_E_Ratio_Fix();
miguelangel_2511 6:d38287621cca 68
miguelangel_2511 6:d38287621cca 69 }
miguelangel_2511 6:d38287621cca 70
miguelangel_2511 6:d38287621cca 71
miguelangel_2511 6:d38287621cca 72
miguelangel_2511 6:d38287621cca 73
miguelangel_2511 6:d38287621cca 74 void Parameter_Selection_Box_Update(void){
miguelangel_2511 6:d38287621cca 75
miguelangel_2511 6:d38287621cca 76 /* Remove the selection box from the previous position */
miguelangel_2511 6:d38287621cca 77 switch(past_parameter_selection_index){
miguelangel_2511 6:d38287621cca 78 case 0:
miguelangel_2511 6:d38287621cca 79 nextion_display.printf("t6.pco=%d", NORMAL_COLOR);
miguelangel_2511 6:d38287621cca 80 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 81 // pc.printf("t6.pco=%d", NORMAL_COLOR);
miguelangel_2511 7:f4e248182d31 82 // pc.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 83 break;
miguelangel_2511 6:d38287621cca 84 case 1:
miguelangel_2511 6:d38287621cca 85 nextion_display.printf("t7.pco=%d", NORMAL_COLOR);
miguelangel_2511 6:d38287621cca 86 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 87 // pc.printf("t7.pco=%d\n\r", NORMAL_COLOR);
miguelangel_2511 7:f4e248182d31 88 // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 89 break;
miguelangel_2511 6:d38287621cca 90 case 2:
miguelangel_2511 6:d38287621cca 91 nextion_display.printf("t8.pco=%d", NORMAL_COLOR);
miguelangel_2511 6:d38287621cca 92 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 93 // pc.printf("t8.pco=%d\n\r", NORMAL_COLOR);
miguelangel_2511 7:f4e248182d31 94 // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 95 break;
miguelangel_2511 6:d38287621cca 96 default:
miguelangel_2511 6:d38287621cca 97 break;
miguelangel_2511 6:d38287621cca 98 }
miguelangel_2511 6:d38287621cca 99
miguelangel_2511 6:d38287621cca 100
miguelangel_2511 6:d38287621cca 101 /* Draw the selection box in the new position */
miguelangel_2511 6:d38287621cca 102 switch(parameter_selection_index){
miguelangel_2511 6:d38287621cca 103 case 0:
miguelangel_2511 6:d38287621cca 104 nextion_display.printf("t6.pco=%d", SELECT_COLOR);
miguelangel_2511 6:d38287621cca 105 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 106 // pc.printf("t6.pco=%d", SELECT_COLOR);
miguelangel_2511 7:f4e248182d31 107 // pc.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 108 break;
miguelangel_2511 6:d38287621cca 109 case 1:
miguelangel_2511 6:d38287621cca 110 nextion_display.printf("t7.pco=%d", SELECT_COLOR);
miguelangel_2511 6:d38287621cca 111 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 112 // pc.printf("t7.pco=%d\n\r", SELECT_COLOR);
miguelangel_2511 7:f4e248182d31 113 // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 114 break;
miguelangel_2511 6:d38287621cca 115 case 2:
miguelangel_2511 6:d38287621cca 116 nextion_display.printf("t8.pco=%d", SELECT_COLOR);
miguelangel_2511 6:d38287621cca 117 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 118 // pc.printf("t8.pco=%d\n\r", SELECT_COLOR);
miguelangel_2511 7:f4e248182d31 119 // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 120 break;
miguelangel_2511 6:d38287621cca 121 default:
miguelangel_2511 6:d38287621cca 122 break;
miguelangel_2511 6:d38287621cca 123 }
miguelangel_2511 6:d38287621cca 124
miguelangel_2511 6:d38287621cca 125 }
miguelangel_2511 6:d38287621cca 126
miguelangel_2511 6:d38287621cca 127
miguelangel_2511 6:d38287621cca 128 void Parameter_Selection_Box_Remove(void){
miguelangel_2511 6:d38287621cca 129
miguelangel_2511 6:d38287621cca 130 /* Remove the selection box from the current position */
miguelangel_2511 6:d38287621cca 131
miguelangel_2511 6:d38287621cca 132 switch(parameter_selection_index){
miguelangel_2511 6:d38287621cca 133 case 0:
miguelangel_2511 6:d38287621cca 134 nextion_display.printf("t6.pco=%d", NORMAL_COLOR);
miguelangel_2511 6:d38287621cca 135 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 136 // pc.printf("t6.pco=%d", NORMAL_COLOR);
miguelangel_2511 7:f4e248182d31 137 // pc.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 138 break;
miguelangel_2511 6:d38287621cca 139 case 1:
miguelangel_2511 6:d38287621cca 140 nextion_display.printf("t7.pco=%d", NORMAL_COLOR);
miguelangel_2511 6:d38287621cca 141 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 142 // pc.printf("t7.pco=%d\n\r", NORMAL_COLOR);
miguelangel_2511 7:f4e248182d31 143 // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 144 break;
miguelangel_2511 6:d38287621cca 145 case 2:
miguelangel_2511 6:d38287621cca 146 nextion_display.printf("t8.pco=%d", NORMAL_COLOR);
miguelangel_2511 6:d38287621cca 147 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 148 // pc.printf("t8.pco=%d\n\r", NORMAL_COLOR);
miguelangel_2511 7:f4e248182d31 149 // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 150 break;
miguelangel_2511 6:d38287621cca 151 default:
miguelangel_2511 6:d38287621cca 152 break;
miguelangel_2511 6:d38287621cca 153 }
miguelangel_2511 6:d38287621cca 154
miguelangel_2511 6:d38287621cca 155 }
miguelangel_2511 6:d38287621cca 156
miguelangel_2511 6:d38287621cca 157
miguelangel_2511 6:d38287621cca 158
miguelangel_2511 6:d38287621cca 159
miguelangel_2511 6:d38287621cca 160 void Volume_Setpoint_Display_Update(void){
miguelangel_2511 6:d38287621cca 161
miguelangel_2511 6:d38287621cca 162 volume_setpoint_display = VOLUME_SETPOINT_MINIMUM_VALUE + VOLUME_SETPOINT_STEP*volume_setpoint_index;
miguelangel_2511 6:d38287621cca 163
miguelangel_2511 6:d38287621cca 164 /* Print volume value */
miguelangel_2511 6:d38287621cca 165 nextion_display.printf("t6.txt=\"%d mL\"", volume_setpoint_display);
miguelangel_2511 6:d38287621cca 166 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 167 // pc.printf("t6.txt=\"%d mL\"\n\r", volume_setpoint_display);
miguelangel_2511 7:f4e248182d31 168 // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 169 }
miguelangel_2511 6:d38287621cca 170
miguelangel_2511 6:d38287621cca 171
miguelangel_2511 6:d38287621cca 172 void Volume_Setpoint_Fix(void){
miguelangel_2511 6:d38287621cca 173
miguelangel_2511 6:d38287621cca 174 volume_setpoint = volume_setpoint_display;
miguelangel_2511 6:d38287621cca 175 stepper_parameters_update_flag = 1;
miguelangel_2511 6:d38287621cca 176
miguelangel_2511 6:d38287621cca 177 /* Print volume value */
miguelangel_2511 6:d38287621cca 178 nextion_display.printf("t6.txt=\"%d mL\"", volume_setpoint_display);
miguelangel_2511 6:d38287621cca 179 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 180 // pc.printf("t6.txt=\"%d mL\"\n\r", volume_setpoint_display);
miguelangel_2511 7:f4e248182d31 181 // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 182 }
miguelangel_2511 6:d38287621cca 183
miguelangel_2511 6:d38287621cca 184
miguelangel_2511 6:d38287621cca 185 void Resp_Frequency_Display_Update(void){
miguelangel_2511 6:d38287621cca 186
miguelangel_2511 6:d38287621cca 187 resp_frequency_display = 10 + resp_frequency_index;
miguelangel_2511 6:d38287621cca 188
miguelangel_2511 6:d38287621cca 189 /* Print frequency value */
miguelangel_2511 6:d38287621cca 190 nextion_display.printf("t7.txt=\"%d RPM\"", resp_frequency_display);
miguelangel_2511 6:d38287621cca 191 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 192 // pc.printf("t7.txt=\"%d RPM\"\n\r", resp_frequency_display);
miguelangel_2511 7:f4e248182d31 193 // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 194 }
miguelangel_2511 6:d38287621cca 195
miguelangel_2511 6:d38287621cca 196
miguelangel_2511 6:d38287621cca 197 void Resp_Frequency_Fix(void){
miguelangel_2511 6:d38287621cca 198
miguelangel_2511 6:d38287621cca 199 resp_frequency = resp_frequency_display;
miguelangel_2511 6:d38287621cca 200 stepper_parameters_update_flag = 1;
miguelangel_2511 6:d38287621cca 201
miguelangel_2511 6:d38287621cca 202 /* Print frequency value */
miguelangel_2511 6:d38287621cca 203 nextion_display.printf("t7.txt=\"%d RPM\"", resp_frequency_display);
miguelangel_2511 6:d38287621cca 204 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 205 // pc.printf("t7.txt=\"%d RPM\"\n\r", resp_frequency_display);
miguelangel_2511 7:f4e248182d31 206 // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 207
miguelangel_2511 6:d38287621cca 208 }
miguelangel_2511 6:d38287621cca 209
miguelangel_2511 6:d38287621cca 210 void I_E_Ratio_Display_Update(void){
miguelangel_2511 6:d38287621cca 211
miguelangel_2511 6:d38287621cca 212 inspiration_time_display = i_e_ratio_display_table[i_e_ratio_index][0];
miguelangel_2511 6:d38287621cca 213 expiration_time_display = i_e_ratio_display_table[i_e_ratio_index][1];
miguelangel_2511 6:d38287621cca 214
miguelangel_2511 6:d38287621cca 215 /* Print i:e ratio value */
miguelangel_2511 6:d38287621cca 216 nextion_display.printf("t8.txt=\"%2.1f/%2.1f\"", inspiration_time_display, expiration_time_display);
miguelangel_2511 6:d38287621cca 217 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 218 // pc.printf("t8.txt=\"%2.1f/%2.1f\"\n\r", inspiration_time_display, expiration_time_display);
miguelangel_2511 7:f4e248182d31 219 // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 220 }
miguelangel_2511 6:d38287621cca 221
miguelangel_2511 6:d38287621cca 222
miguelangel_2511 6:d38287621cca 223 void I_E_Ratio_Fix(void){
miguelangel_2511 6:d38287621cca 224
miguelangel_2511 6:d38287621cca 225 inspiration_time = inspiration_time_display;
miguelangel_2511 6:d38287621cca 226 expiration_time = expiration_time_display;
miguelangel_2511 6:d38287621cca 227 stepper_parameters_update_flag = 1;
miguelangel_2511 6:d38287621cca 228
miguelangel_2511 6:d38287621cca 229 /* Print i:e ratio value */
miguelangel_2511 6:d38287621cca 230 nextion_display.printf("t8.txt=\"%2.1f/%2.1f\"", inspiration_time_display, expiration_time_display);
miguelangel_2511 6:d38287621cca 231 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 232 // pc.printf("t8.txt=\"%2.1f/%2.1f\"\n\r", inspiration_time_display, expiration_time_display);
miguelangel_2511 7:f4e248182d31 233 // pc.printf("%c%c%c\n\r", 0xff, 0xff, 0xff);
miguelangel_2511 6:d38287621cca 234 }
miguelangel_2511 7:f4e248182d31 235
miguelangel_2511 7:f4e248182d31 236 void Pressure_01_Display_Update(void){
miguelangel_2511 7:f4e248182d31 237 nextion_display.printf("t1.txt=\"%.2f mL\"", pressure_01_psi);
miguelangel_2511 7:f4e248182d31 238 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 239 }
miguelangel_2511 7:f4e248182d31 240
miguelangel_2511 7:f4e248182d31 241 void Pressure_02_Display_Update(void){
miguelangel_2511 7:f4e248182d31 242 nextion_display.printf("t2.txt=\"%.2f mL\"", pressure_02_psi);
miguelangel_2511 7:f4e248182d31 243 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 244 }
miguelangel_2511 7:f4e248182d31 245
miguelangel_2511 7:f4e248182d31 246 void Diff_Pressure_Display_Update(void){
miguelangel_2511 7:f4e248182d31 247 nextion_display.printf("t0.txt=\"%.2f mL\"", diff_pressure_psi);
miguelangel_2511 7:f4e248182d31 248 nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff);
miguelangel_2511 7:f4e248182d31 249 }