para el ventilador

Dependencies:   QEI FastPWM

Revision:
7:f4e248182d31
Parent:
6:d38287621cca
Child:
8:208d965a3bd2
--- a/ventilator.cpp	Mon Apr 20 11:39:30 2020 +0000
+++ b/ventilator.cpp	Mon Apr 20 21:58:36 2020 +0000
@@ -7,10 +7,16 @@
 #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;
@@ -59,8 +65,8 @@
                     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);
+                   // 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; 
@@ -83,8 +89,8 @@
                     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);
+                   // 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; 
@@ -108,8 +114,8 @@
                     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);
+                    //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; 
@@ -131,4 +137,59 @@
                 break;
                 
         }   
- }       
\ No newline at end of file
+ }
+ 
+ 
+ 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);  
+ 
+  }
+ 
+        
\ No newline at end of file