pachas
Dependencies: mbed QEI FastPWM
nextion_interface.cpp@10:b2d87404309a, 2020-04-27 (annotated)
- Committer:
- miguelangel_2511
- Date:
- Mon Apr 27 19:52:02 2020 +0000
- Revision:
- 10:b2d87404309a
- Parent:
- 9:95fdcdc0977e
- Child:
- 11:5cb7ae8bd831
Ventilador ajustado al nuevo sistema mecanico (con mordaza) y con el sensor de flujo (espirometria) calibrado de forma aproximada. Tabien se ha configurado el baud rate a su maximo valor funcional (256000 bps).
Who changed what in which revision?
User | Revision | Line number | New 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 | 8:208d965a3bd2 | 12 | |
miguelangel_2511 | 6:d38287621cca | 13 | /* Object definition */ |
miguelangel_2511 | 7:f4e248182d31 | 14 | Serial nextion_display(NEXTION_DISPLAY_TX_PIN,NEXTION_DISPLAY_RX_PIN); |
miguelangel_2511 | 6:d38287621cca | 15 | // For testing pusposes only |
miguelangel_2511 | 7:f4e248182d31 | 16 | //Serial pc(USBTX, USBRX); |
miguelangel_2511 | 6:d38287621cca | 17 | |
miguelangel_2511 | 6:d38287621cca | 18 | /* Global variable definition */ |
miguelangel_2511 | 6:d38287621cca | 19 | |
miguelangel_2511 | 6:d38287621cca | 20 | uint16_t volume_setpoint_display = VOLUME_SETPOINT_VALUE_DEFAULT; |
miguelangel_2511 | 6:d38287621cca | 21 | uint16_t volume_measured_display = 480; |
miguelangel_2511 | 6:d38287621cca | 22 | uint8_t resp_frequency_display = RESP_FREQUENCY_VALUE_DEFAULT; |
miguelangel_2511 | 6:d38287621cca | 23 | float inspiration_time_display = INSPIRATION_TIME_VALUE_DEFAULT; |
miguelangel_2511 | 6:d38287621cca | 24 | float expiration_time_display = EXPIRATION_TIME_VALUE_DEFAULT; |
miguelangel_2511 | 6:d38287621cca | 25 | uint8_t pressure_measured_display = 16; |
miguelangel_2511 | 6:d38287621cca | 26 | uint8_t gas_input_display = AIR_INPUT; |
miguelangel_2511 | 6:d38287621cca | 27 | |
miguelangel_2511 | 6:d38287621cca | 28 | uint16_t selection_box_coordinates[3][4]={ |
miguelangel_2511 | 6:d38287621cca | 29 | {1,1,159,159}, |
miguelangel_2511 | 6:d38287621cca | 30 | {161,1,319,159}, |
miguelangel_2511 | 6:d38287621cca | 31 | {321,1,478, 159} |
miguelangel_2511 | 6:d38287621cca | 32 | }; |
miguelangel_2511 | 6:d38287621cca | 33 | |
miguelangel_2511 | 6:d38287621cca | 34 | float i_e_ratio_display_table[I_E_RATIO_INDEX_LIMIT][2]={ |
miguelangel_2511 | 6:d38287621cca | 35 | {1.0,2.0}, |
miguelangel_2511 | 6:d38287621cca | 36 | {1.0,2.5}, |
miguelangel_2511 | 6:d38287621cca | 37 | {1.0,3.0} |
miguelangel_2511 | 6:d38287621cca | 38 | }; |
miguelangel_2511 | 6:d38287621cca | 39 | |
miguelangel_2511 | 6:d38287621cca | 40 | |
miguelangel_2511 | 6:d38287621cca | 41 | /* Function definition */ |
miguelangel_2511 | 6:d38287621cca | 42 | |
miguelangel_2511 | 6:d38287621cca | 43 | void Nextion_Interface_Initialize(void){ |
miguelangel_2511 | 6:d38287621cca | 44 | /* Configure baud rate */ |
miguelangel_2511 | 8:208d965a3bd2 | 45 | nextion_display.baud(9600); |
miguelangel_2511 | 8:208d965a3bd2 | 46 | wait(1); |
miguelangel_2511 | 8:208d965a3bd2 | 47 | nextion_display.printf("baud=%d", NEXTION_DISPLAY_BAUD_RATE); |
miguelangel_2511 | 8:208d965a3bd2 | 48 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 49 | wait(1); |
miguelangel_2511 | 7:f4e248182d31 | 50 | nextion_display.baud(NEXTION_DISPLAY_BAUD_RATE); |
miguelangel_2511 | 8:208d965a3bd2 | 51 | wait(1); |
miguelangel_2511 | 8:208d965a3bd2 | 52 | |
miguelangel_2511 | 8:208d965a3bd2 | 53 | /* Draw separators for the displayed values */ |
miguelangel_2511 | 8:208d965a3bd2 | 54 | nextion_display.printf("line 10,160,190,160,%d", WHITE); |
miguelangel_2511 | 8:208d965a3bd2 | 55 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 56 | nextion_display.printf("line 10,320,190,320,%d", WHITE); |
miguelangel_2511 | 8:208d965a3bd2 | 57 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 58 | nextion_display.printf("line 610,160,790,160,%d", WHITE); |
miguelangel_2511 | 8:208d965a3bd2 | 59 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 60 | nextion_display.printf("line 610,320,790,320,%d", WHITE); |
miguelangel_2511 | 8:208d965a3bd2 | 61 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 6:d38287621cca | 62 | |
miguelangel_2511 | 6:d38287621cca | 63 | /* Set font color */ |
miguelangel_2511 | 8:208d965a3bd2 | 64 | nextion_display.printf("t1.pco=%d", NORMAL_COLOR); |
miguelangel_2511 | 6:d38287621cca | 65 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 66 | nextion_display.printf("t4.pco=%d", NORMAL_COLOR); |
miguelangel_2511 | 8:208d965a3bd2 | 67 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 6:d38287621cca | 68 | nextion_display.printf("t7.pco=%d", NORMAL_COLOR); |
miguelangel_2511 | 6:d38287621cca | 69 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 9:95fdcdc0977e | 70 | |
miguelangel_2511 | 6:d38287621cca | 71 | /* Print default values */ |
miguelangel_2511 | 6:d38287621cca | 72 | Volume_Setpoint_Fix(); |
miguelangel_2511 | 6:d38287621cca | 73 | Resp_Frequency_Fix(); |
miguelangel_2511 | 6:d38287621cca | 74 | I_E_Ratio_Fix(); |
miguelangel_2511 | 6:d38287621cca | 75 | |
miguelangel_2511 | 6:d38287621cca | 76 | } |
miguelangel_2511 | 6:d38287621cca | 77 | |
miguelangel_2511 | 6:d38287621cca | 78 | |
miguelangel_2511 | 6:d38287621cca | 79 | |
miguelangel_2511 | 6:d38287621cca | 80 | |
miguelangel_2511 | 6:d38287621cca | 81 | void Parameter_Selection_Box_Update(void){ |
miguelangel_2511 | 6:d38287621cca | 82 | |
miguelangel_2511 | 6:d38287621cca | 83 | /* Remove the selection box from the previous position */ |
miguelangel_2511 | 6:d38287621cca | 84 | switch(past_parameter_selection_index){ |
miguelangel_2511 | 6:d38287621cca | 85 | case 0: |
miguelangel_2511 | 8:208d965a3bd2 | 86 | nextion_display.printf("t1.pco=%d", NORMAL_COLOR); |
miguelangel_2511 | 6:d38287621cca | 87 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 6:d38287621cca | 88 | break; |
miguelangel_2511 | 6:d38287621cca | 89 | case 1: |
miguelangel_2511 | 8:208d965a3bd2 | 90 | nextion_display.printf("t4.pco=%d", NORMAL_COLOR); |
miguelangel_2511 | 8:208d965a3bd2 | 91 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 92 | break; |
miguelangel_2511 | 8:208d965a3bd2 | 93 | case 2: |
miguelangel_2511 | 6:d38287621cca | 94 | nextion_display.printf("t7.pco=%d", NORMAL_COLOR); |
miguelangel_2511 | 6:d38287621cca | 95 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 6:d38287621cca | 96 | break; |
miguelangel_2511 | 6:d38287621cca | 97 | default: |
miguelangel_2511 | 6:d38287621cca | 98 | break; |
miguelangel_2511 | 6:d38287621cca | 99 | } |
miguelangel_2511 | 6:d38287621cca | 100 | |
miguelangel_2511 | 6:d38287621cca | 101 | |
miguelangel_2511 | 6:d38287621cca | 102 | /* Draw the selection box in the new position */ |
miguelangel_2511 | 6:d38287621cca | 103 | switch(parameter_selection_index){ |
miguelangel_2511 | 6:d38287621cca | 104 | case 0: |
miguelangel_2511 | 8:208d965a3bd2 | 105 | nextion_display.printf("t1.pco=%d", SELECT_COLOR); |
miguelangel_2511 | 6:d38287621cca | 106 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 6:d38287621cca | 107 | break; |
miguelangel_2511 | 6:d38287621cca | 108 | case 1: |
miguelangel_2511 | 8:208d965a3bd2 | 109 | nextion_display.printf("t4.pco=%d", SELECT_COLOR); |
miguelangel_2511 | 8:208d965a3bd2 | 110 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 111 | break; |
miguelangel_2511 | 8:208d965a3bd2 | 112 | case 2: |
miguelangel_2511 | 6:d38287621cca | 113 | nextion_display.printf("t7.pco=%d", SELECT_COLOR); |
miguelangel_2511 | 6:d38287621cca | 114 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 6:d38287621cca | 115 | break; |
miguelangel_2511 | 6:d38287621cca | 116 | default: |
miguelangel_2511 | 6:d38287621cca | 117 | break; |
miguelangel_2511 | 6:d38287621cca | 118 | } |
miguelangel_2511 | 6:d38287621cca | 119 | |
miguelangel_2511 | 6:d38287621cca | 120 | } |
miguelangel_2511 | 6:d38287621cca | 121 | |
miguelangel_2511 | 6:d38287621cca | 122 | |
miguelangel_2511 | 6:d38287621cca | 123 | void Parameter_Selection_Box_Remove(void){ |
miguelangel_2511 | 6:d38287621cca | 124 | |
miguelangel_2511 | 6:d38287621cca | 125 | /* Remove the selection box from the current position */ |
miguelangel_2511 | 6:d38287621cca | 126 | |
miguelangel_2511 | 6:d38287621cca | 127 | switch(parameter_selection_index){ |
miguelangel_2511 | 6:d38287621cca | 128 | case 0: |
miguelangel_2511 | 8:208d965a3bd2 | 129 | nextion_display.printf("t1.pco=%d", NORMAL_COLOR); |
miguelangel_2511 | 6:d38287621cca | 130 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 6:d38287621cca | 131 | break; |
miguelangel_2511 | 6:d38287621cca | 132 | case 1: |
miguelangel_2511 | 8:208d965a3bd2 | 133 | nextion_display.printf("t4.pco=%d", NORMAL_COLOR); |
miguelangel_2511 | 8:208d965a3bd2 | 134 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 135 | break; |
miguelangel_2511 | 8:208d965a3bd2 | 136 | case 2: |
miguelangel_2511 | 6:d38287621cca | 137 | nextion_display.printf("t7.pco=%d", NORMAL_COLOR); |
miguelangel_2511 | 6:d38287621cca | 138 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 6:d38287621cca | 139 | break; |
miguelangel_2511 | 6:d38287621cca | 140 | default: |
miguelangel_2511 | 6:d38287621cca | 141 | break; |
miguelangel_2511 | 6:d38287621cca | 142 | } |
miguelangel_2511 | 6:d38287621cca | 143 | |
miguelangel_2511 | 6:d38287621cca | 144 | } |
miguelangel_2511 | 6:d38287621cca | 145 | |
miguelangel_2511 | 6:d38287621cca | 146 | |
miguelangel_2511 | 6:d38287621cca | 147 | |
miguelangel_2511 | 6:d38287621cca | 148 | |
miguelangel_2511 | 6:d38287621cca | 149 | void Volume_Setpoint_Display_Update(void){ |
miguelangel_2511 | 6:d38287621cca | 150 | |
miguelangel_2511 | 6:d38287621cca | 151 | volume_setpoint_display = VOLUME_SETPOINT_MINIMUM_VALUE + VOLUME_SETPOINT_STEP*volume_setpoint_index; |
miguelangel_2511 | 6:d38287621cca | 152 | |
miguelangel_2511 | 6:d38287621cca | 153 | /* Print volume value */ |
miguelangel_2511 | 8:208d965a3bd2 | 154 | nextion_display.printf("t1.txt=\"%d\"", volume_setpoint_display); |
miguelangel_2511 | 6:d38287621cca | 155 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 6:d38287621cca | 156 | } |
miguelangel_2511 | 6:d38287621cca | 157 | |
miguelangel_2511 | 6:d38287621cca | 158 | |
miguelangel_2511 | 6:d38287621cca | 159 | void Volume_Setpoint_Fix(void){ |
miguelangel_2511 | 6:d38287621cca | 160 | |
miguelangel_2511 | 6:d38287621cca | 161 | volume_setpoint = volume_setpoint_display; |
miguelangel_2511 | 6:d38287621cca | 162 | stepper_parameters_update_flag = 1; |
miguelangel_2511 | 6:d38287621cca | 163 | |
miguelangel_2511 | 6:d38287621cca | 164 | /* Print volume value */ |
miguelangel_2511 | 8:208d965a3bd2 | 165 | nextion_display.printf("t1.txt=\"%d\"", volume_setpoint_display); |
miguelangel_2511 | 6:d38287621cca | 166 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 6:d38287621cca | 167 | } |
miguelangel_2511 | 6:d38287621cca | 168 | |
miguelangel_2511 | 6:d38287621cca | 169 | |
miguelangel_2511 | 6:d38287621cca | 170 | void Resp_Frequency_Display_Update(void){ |
miguelangel_2511 | 6:d38287621cca | 171 | |
miguelangel_2511 | 6:d38287621cca | 172 | resp_frequency_display = 10 + resp_frequency_index; |
miguelangel_2511 | 6:d38287621cca | 173 | |
miguelangel_2511 | 6:d38287621cca | 174 | /* Print frequency value */ |
miguelangel_2511 | 8:208d965a3bd2 | 175 | nextion_display.printf("t4.txt=\"%d\"", resp_frequency_display); |
miguelangel_2511 | 6:d38287621cca | 176 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 6:d38287621cca | 177 | } |
miguelangel_2511 | 6:d38287621cca | 178 | |
miguelangel_2511 | 6:d38287621cca | 179 | |
miguelangel_2511 | 6:d38287621cca | 180 | void Resp_Frequency_Fix(void){ |
miguelangel_2511 | 6:d38287621cca | 181 | |
miguelangel_2511 | 6:d38287621cca | 182 | resp_frequency = resp_frequency_display; |
miguelangel_2511 | 6:d38287621cca | 183 | stepper_parameters_update_flag = 1; |
miguelangel_2511 | 6:d38287621cca | 184 | |
miguelangel_2511 | 6:d38287621cca | 185 | /* Print frequency value */ |
miguelangel_2511 | 8:208d965a3bd2 | 186 | nextion_display.printf("t4.txt=\"%d\"", resp_frequency_display); |
miguelangel_2511 | 6:d38287621cca | 187 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 6:d38287621cca | 188 | } |
miguelangel_2511 | 6:d38287621cca | 189 | |
miguelangel_2511 | 6:d38287621cca | 190 | void I_E_Ratio_Display_Update(void){ |
miguelangel_2511 | 6:d38287621cca | 191 | |
miguelangel_2511 | 6:d38287621cca | 192 | inspiration_time_display = i_e_ratio_display_table[i_e_ratio_index][0]; |
miguelangel_2511 | 6:d38287621cca | 193 | expiration_time_display = i_e_ratio_display_table[i_e_ratio_index][1]; |
miguelangel_2511 | 6:d38287621cca | 194 | |
miguelangel_2511 | 6:d38287621cca | 195 | /* Print i:e ratio value */ |
miguelangel_2511 | 8:208d965a3bd2 | 196 | nextion_display.printf("t7.txt=\"%2.1f : %2.1f\"", inspiration_time_display, expiration_time_display); |
miguelangel_2511 | 8:208d965a3bd2 | 197 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 6:d38287621cca | 198 | } |
miguelangel_2511 | 6:d38287621cca | 199 | |
miguelangel_2511 | 6:d38287621cca | 200 | |
miguelangel_2511 | 6:d38287621cca | 201 | void I_E_Ratio_Fix(void){ |
miguelangel_2511 | 6:d38287621cca | 202 | |
miguelangel_2511 | 6:d38287621cca | 203 | inspiration_time = inspiration_time_display; |
miguelangel_2511 | 6:d38287621cca | 204 | expiration_time = expiration_time_display; |
miguelangel_2511 | 6:d38287621cca | 205 | stepper_parameters_update_flag = 1; |
miguelangel_2511 | 6:d38287621cca | 206 | |
miguelangel_2511 | 6:d38287621cca | 207 | /* Print i:e ratio value */ |
miguelangel_2511 | 8:208d965a3bd2 | 208 | nextion_display.printf("t7.txt=\"%2.1f : %2.1f\"", inspiration_time_display, expiration_time_display); |
miguelangel_2511 | 6:d38287621cca | 209 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 6:d38287621cca | 210 | } |
miguelangel_2511 | 7:f4e248182d31 | 211 | |
miguelangel_2511 | 8:208d965a3bd2 | 212 | void Volume_Display_Update(void){ |
miguelangel_2511 | 9:95fdcdc0977e | 213 | nextion_display.printf("t11.txt=\"%d\"", (int16_t)volume_ml); |
miguelangel_2511 | 9:95fdcdc0977e | 214 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 9:95fdcdc0977e | 215 | } |
miguelangel_2511 | 9:95fdcdc0977e | 216 | |
miguelangel_2511 | 9:95fdcdc0977e | 217 | void Flow_Display_Update(void){ |
miguelangel_2511 | 10:b2d87404309a | 218 | nextion_display.printf("t14.txt=\"%d\"", (int32_t)flow_lpm); |
miguelangel_2511 | 8:208d965a3bd2 | 219 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 220 | } |
miguelangel_2511 | 8:208d965a3bd2 | 221 | |
miguelangel_2511 | 8:208d965a3bd2 | 222 | void Pressure_Display_Update(void){ |
miguelangel_2511 | 8:208d965a3bd2 | 223 | nextion_display.printf("t15.txt=\"%.1f\"", (pressure_02_psi * PSI_TO_CMH2O_CONSTANT)); |
miguelangel_2511 | 8:208d965a3bd2 | 224 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 225 | } |
miguelangel_2511 | 8:208d965a3bd2 | 226 | |
miguelangel_2511 | 8:208d965a3bd2 | 227 | |
miguelangel_2511 | 8:208d965a3bd2 | 228 | void Nextion_Plot_Volume_Waveform(void){ |
miguelangel_2511 | 8:208d965a3bd2 | 229 | |
miguelangel_2511 | 8:208d965a3bd2 | 230 | static uint16_t x_pos_counter = 1, prev_y_pos = (VOLUME_WAVEFORM_Y0 + VOLUME_WAVEFORM_HEIGHT - 1); |
miguelangel_2511 | 8:208d965a3bd2 | 231 | int16_t x_pos, y_pos; |
miguelangel_2511 | 8:208d965a3bd2 | 232 | uint16_t volume_scaled_value; |
miguelangel_2511 | 8:208d965a3bd2 | 233 | |
miguelangel_2511 | 8:208d965a3bd2 | 234 | //volume_scaled_value = (uint16_t)((volume_ml - 0.5)*VOLUME_WAVEFORM_HEIGHT*2) ; |
miguelangel_2511 | 9:95fdcdc0977e | 235 | volume_scaled_value = (uint16_t)((volume_ml - 0.5)*4) ; |
miguelangel_2511 | 8:208d965a3bd2 | 236 | |
miguelangel_2511 | 8:208d965a3bd2 | 237 | x_pos_counter++; |
miguelangel_2511 | 8:208d965a3bd2 | 238 | |
miguelangel_2511 | 8:208d965a3bd2 | 239 | if(x_pos_counter >= VOLUME_WAVEFORM_WIDTH){ |
miguelangel_2511 | 8:208d965a3bd2 | 240 | nextion_display.printf("fill %d,%d,%d,%d,%d",VOLUME_WAVEFORM_X0,VOLUME_WAVEFORM_Y0,VOLUME_WAVEFORM_WIDTH,VOLUME_WAVEFORM_HEIGHT,8591); |
miguelangel_2511 | 8:208d965a3bd2 | 241 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 242 | x_pos_counter = 1; |
miguelangel_2511 | 8:208d965a3bd2 | 243 | } |
miguelangel_2511 | 8:208d965a3bd2 | 244 | |
miguelangel_2511 | 8:208d965a3bd2 | 245 | x_pos = VOLUME_WAVEFORM_X0 + x_pos_counter; |
miguelangel_2511 | 8:208d965a3bd2 | 246 | y_pos = VOLUME_WAVEFORM_Y0 + VOLUME_WAVEFORM_HEIGHT - volume_scaled_value - 1; |
miguelangel_2511 | 8:208d965a3bd2 | 247 | |
miguelangel_2511 | 8:208d965a3bd2 | 248 | if(y_pos <= VOLUME_WAVEFORM_Y0){ |
miguelangel_2511 | 8:208d965a3bd2 | 249 | y_pos = VOLUME_WAVEFORM_Y0 + 1; |
miguelangel_2511 | 10:b2d87404309a | 250 | }else if(y_pos >= (VOLUME_WAVEFORM_Y0 + VOLUME_WAVEFORM_HEIGHT)){ |
miguelangel_2511 | 10:b2d87404309a | 251 | y_pos = VOLUME_WAVEFORM_Y0 + VOLUME_WAVEFORM_HEIGHT - 1; |
miguelangel_2511 | 8:208d965a3bd2 | 252 | } |
miguelangel_2511 | 8:208d965a3bd2 | 253 | |
miguelangel_2511 | 8:208d965a3bd2 | 254 | nextion_display.printf("line %d,%d,%d,%d,%d",(x_pos - 1), prev_y_pos, x_pos, y_pos, GREEN); |
miguelangel_2511 | 7:f4e248182d31 | 255 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 256 | |
miguelangel_2511 | 8:208d965a3bd2 | 257 | prev_y_pos = y_pos; |
miguelangel_2511 | 7:f4e248182d31 | 258 | } |
miguelangel_2511 | 7:f4e248182d31 | 259 | |
miguelangel_2511 | 8:208d965a3bd2 | 260 | |
miguelangel_2511 | 8:208d965a3bd2 | 261 | void Nextion_Plot_Flow_Waveform(void){ |
miguelangel_2511 | 8:208d965a3bd2 | 262 | |
miguelangel_2511 | 8:208d965a3bd2 | 263 | static uint16_t x_pos_counter = 1, prev_y_pos = (FLOW_WAVEFORM_Y0 + FLOW_WAVEFORM_HEIGHT - 1); |
miguelangel_2511 | 8:208d965a3bd2 | 264 | uint16_t x_pos, y_pos; |
miguelangel_2511 | 8:208d965a3bd2 | 265 | uint16_t flow_scaled_value; |
miguelangel_2511 | 8:208d965a3bd2 | 266 | |
miguelangel_2511 | 10:b2d87404309a | 267 | flow_scaled_value = 79 + (int16_t)flow_lpm; |
miguelangel_2511 | 8:208d965a3bd2 | 268 | |
miguelangel_2511 | 8:208d965a3bd2 | 269 | x_pos_counter++; |
miguelangel_2511 | 8:208d965a3bd2 | 270 | |
miguelangel_2511 | 8:208d965a3bd2 | 271 | if(x_pos_counter >= FLOW_WAVEFORM_WIDTH){ |
miguelangel_2511 | 8:208d965a3bd2 | 272 | nextion_display.printf("fill %d,%d,%d,%d,%d",FLOW_WAVEFORM_X0,FLOW_WAVEFORM_Y0,FLOW_WAVEFORM_WIDTH,FLOW_WAVEFORM_HEIGHT,8591); |
miguelangel_2511 | 8:208d965a3bd2 | 273 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 274 | x_pos_counter = 1; |
miguelangel_2511 | 8:208d965a3bd2 | 275 | } |
miguelangel_2511 | 8:208d965a3bd2 | 276 | |
miguelangel_2511 | 8:208d965a3bd2 | 277 | x_pos = FLOW_WAVEFORM_X0 + x_pos_counter; |
miguelangel_2511 | 8:208d965a3bd2 | 278 | y_pos = FLOW_WAVEFORM_Y0 + FLOW_WAVEFORM_HEIGHT - flow_scaled_value - 1; |
miguelangel_2511 | 8:208d965a3bd2 | 279 | |
miguelangel_2511 | 8:208d965a3bd2 | 280 | |
miguelangel_2511 | 8:208d965a3bd2 | 281 | if(y_pos <= FLOW_WAVEFORM_Y0){ |
miguelangel_2511 | 10:b2d87404309a | 282 | y_pos = FLOW_WAVEFORM_Y0 + 1; |
miguelangel_2511 | 8:208d965a3bd2 | 283 | }else if(y_pos >= (FLOW_WAVEFORM_Y0 + FLOW_WAVEFORM_HEIGHT)){ |
miguelangel_2511 | 10:b2d87404309a | 284 | y_pos = FLOW_WAVEFORM_Y0 + FLOW_WAVEFORM_HEIGHT - 1; |
miguelangel_2511 | 8:208d965a3bd2 | 285 | |
miguelangel_2511 | 8:208d965a3bd2 | 286 | } |
miguelangel_2511 | 8:208d965a3bd2 | 287 | |
miguelangel_2511 | 8:208d965a3bd2 | 288 | nextion_display.printf("line %d,%d,%d,%d,%d",(x_pos - 1), prev_y_pos, x_pos, y_pos, YELLOW); |
miguelangel_2511 | 7:f4e248182d31 | 289 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 290 | |
miguelangel_2511 | 8:208d965a3bd2 | 291 | prev_y_pos = y_pos; |
miguelangel_2511 | 8:208d965a3bd2 | 292 | } |
miguelangel_2511 | 8:208d965a3bd2 | 293 | |
miguelangel_2511 | 8:208d965a3bd2 | 294 | |
miguelangel_2511 | 8:208d965a3bd2 | 295 | void Nextion_Plot_Pressure_Waveform(void){ |
miguelangel_2511 | 8:208d965a3bd2 | 296 | |
miguelangel_2511 | 8:208d965a3bd2 | 297 | static uint16_t x_pos_counter = 1, prev_y_pos = (PRESSURE_WAVEFORM_Y0 + PRESSURE_WAVEFORM_HEIGHT - 1); |
miguelangel_2511 | 8:208d965a3bd2 | 298 | uint16_t x_pos, y_pos; |
miguelangel_2511 | 8:208d965a3bd2 | 299 | uint16_t pressure_02_scaled_value; |
miguelangel_2511 | 8:208d965a3bd2 | 300 | |
miguelangel_2511 | 10:b2d87404309a | 301 | pressure_02_scaled_value = (uint16_t)(pressure_02_psi * PRESSURE_WAVEFORM_HEIGHT) ; |
miguelangel_2511 | 8:208d965a3bd2 | 302 | |
miguelangel_2511 | 8:208d965a3bd2 | 303 | x_pos_counter++; |
miguelangel_2511 | 8:208d965a3bd2 | 304 | |
miguelangel_2511 | 8:208d965a3bd2 | 305 | if(x_pos_counter >= PRESSURE_WAVEFORM_WIDTH){ |
miguelangel_2511 | 8:208d965a3bd2 | 306 | nextion_display.printf("fill %d,%d,%d,%d,%d",PRESSURE_WAVEFORM_X0,PRESSURE_WAVEFORM_Y0,PRESSURE_WAVEFORM_WIDTH,PRESSURE_WAVEFORM_HEIGHT,8591); |
miguelangel_2511 | 8:208d965a3bd2 | 307 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 308 | x_pos_counter = 1; |
miguelangel_2511 | 8:208d965a3bd2 | 309 | } |
miguelangel_2511 | 8:208d965a3bd2 | 310 | |
miguelangel_2511 | 8:208d965a3bd2 | 311 | x_pos = PRESSURE_WAVEFORM_X0 + x_pos_counter; |
miguelangel_2511 | 8:208d965a3bd2 | 312 | y_pos = PRESSURE_WAVEFORM_Y0 + PRESSURE_WAVEFORM_HEIGHT - pressure_02_scaled_value - 1; |
miguelangel_2511 | 8:208d965a3bd2 | 313 | |
miguelangel_2511 | 8:208d965a3bd2 | 314 | |
miguelangel_2511 | 8:208d965a3bd2 | 315 | if(y_pos <= PRESSURE_WAVEFORM_Y0){ |
miguelangel_2511 | 8:208d965a3bd2 | 316 | y_pos = PRESSURE_WAVEFORM_Y0 + 1; |
miguelangel_2511 | 8:208d965a3bd2 | 317 | } |
miguelangel_2511 | 8:208d965a3bd2 | 318 | |
miguelangel_2511 | 8:208d965a3bd2 | 319 | nextion_display.printf("line %d,%d,%d,%d,%d",(x_pos - 1), prev_y_pos, x_pos, y_pos, WHITE); |
miguelangel_2511 | 8:208d965a3bd2 | 320 | nextion_display.printf("%c%c%c", 0xff, 0xff, 0xff); |
miguelangel_2511 | 8:208d965a3bd2 | 321 | |
miguelangel_2511 | 8:208d965a3bd2 | 322 | prev_y_pos = y_pos; |
miguelangel_2511 | 8:208d965a3bd2 | 323 | } |
miguelangel_2511 | 8:208d965a3bd2 | 324 |