![](/media/cache/profiles/9f0876a200701e5fdece2e58aa965574.jpg.50x50_q85.jpg)
Русифицированная версия программы для измерения температуры и отн. влажности и вывода информации на сенсорный TFT
Dependencies: FT800_2 HYT mbed
main.cpp
00001 #include "mbed.h" 00002 #include "FT_Platform.h" 00003 #include "HYT.h" 00004 #include "display.h" 00005 #include "statistics.h" 00006 00007 Ticker timeKeeping; 00008 volatile uint64_t seconds = 0; 00009 uint64_t secondsOffset = 0; 00010 00011 HYT SENSOR (PD6, PD7); // sda, scl [SLSTK3400A] 00012 FT800 TFT (PE10, PE11, PE12, PE13, PB11, PD4); // mosi, miso, sck, ss, int, pd [SLSTK3400A] 00013 //HYT SENSOR (D14, D15); // sda, scl [WIZwiki-W7500P] 00014 //FT800 TFT (D11, D12, D13, D10, D9, D8); // mosi, miso, sck, ss, int, pd [WIZwiki-W7500P] 00015 //HYT SENSOR (PA08, PA09); // sda, scl [ATSAMD21-XPRO] 00016 //FT800 TFT (PA18, PA16, PA19, PA17, PA20, PA21); // mosi, miso, sck, ss, int, pd [ATSAMD21-XPRO] 00017 00018 Display disp(&TFT); 00019 Statistics stat; 00020 00021 /************************************************************************************************************************** 00022 ************************** Update statistics data every second ************************************************************ 00023 **************************************************************************************************************************/ 00024 void secondsCallback(void) 00025 { 00026 if (seconds != 0) { 00027 secondsOffset = stat.UpdateStatistics(SENSOR.humidity, SENSOR.temperature, seconds, secondsOffset); 00028 } else { 00029 stat.InitValues(SENSOR.humidity, SENSOR.temperature); 00030 } 00031 seconds ++; 00032 } 00033 00034 /************************************************************************************************************************** 00035 ************************** HYT sensor polling cycle *********************************************************************** 00036 **************************************************************************************************************************/ 00037 void dataUpdate(void) 00038 { 00039 SENSOR.MRCommand(); 00040 wait_ms(100); 00041 SENSOR.DFCommand(); 00042 } 00043 00044 /************************************************************************************************************************** 00045 ************************** Main function ********************************************************************************** 00046 **************************************************************************************************************************/ 00047 int main() 00048 { 00049 timeKeeping.attach(&secondsCallback, 1.0f); 00050 00051 disp.LoadImagesAndFonts(); 00052 disp.HandleAllBitmaps(); 00053 disp.Calibration(); 00054 00055 disp.activeScreen = MENU_SCREEN; 00056 disp.pressedButton = NONE_PRESS; 00057 00058 // change active screen depending on pressed area 00059 while(1) { 00060 dataUpdate(); 00061 disp.pressedButton = disp.GetTouch(); 00062 00063 // ---------------------------------------------------------------------------------------------- 00064 // Main menu screen 00065 if (disp.activeScreen == MENU_SCREEN) { 00066 disp.MainMenu(SENSOR.humidity, SENSOR.temperature); 00067 if (disp.pressedButton) { 00068 wait_ms(150); 00069 if (disp.pressedButton == CURR_TEMP_PRESS) { 00070 disp.activeScreen = CURR_TEMP_SCREEN; 00071 } else if (disp.pressedButton == CURR_HUM_PRESS) { 00072 disp.activeScreen = CURR_HUM_SCREEN; 00073 } else if (disp.pressedButton == STAT_HUM_PRESS) { 00074 disp.activeScreen = HUM_24HRS_SCREEN; 00075 } else if (disp.pressedButton == STAT_TEMP_PRESS) { 00076 disp.activeScreen = TEMP_24HRS_SCREEN; 00077 } else if (disp.pressedButton == ABOUT_PRESS) { 00078 disp.activeScreen = ABOUT_SCREEN; 00079 } 00080 disp.pressedButton = NONE_PRESS; 00081 } 00082 00083 // ---------------------------------------------------------------------------------------------- 00084 // Any other screen 00085 } else { 00086 // ---------------------------------------------------------------------------------------------- 00087 // You can back to main menu from any screen 00088 if (disp.pressedButton == MENU_PRESS) { 00089 disp.pressedButton = NONE_PRESS; 00090 disp.activeScreen = MENU_SCREEN; 00091 } else { 00092 // ---------------------------------------------------------------------------------------------- 00093 // Screen with current temperature 00094 if (disp.activeScreen == CURR_TEMP_SCREEN) { 00095 disp.CurrentTemperature(SENSOR.temperature); 00096 // ---------------------------------------------------------------------------------------------- 00097 // Screen with current humidity 00098 } else if (disp.activeScreen == CURR_HUM_SCREEN) { 00099 disp.CurrentHumidity(SENSOR.humidity); 00100 // ---------------------------------------------------------------------------------------------- 00101 // Screens with humidity statistics 00102 } else if (disp.activeScreen == HUM_24HRS_SCREEN) { 00103 disp.StatHumidity_24hrs(seconds, stat.humidity24hrs, secondsOffset); 00104 if (disp.pressedButton >= ZONE_1_PRESS && disp.pressedButton <= ZONE_8_PRESS) { 00105 wait_ms(150); 00106 disp.activeScreen = HUM_3HRS_SCREEN; 00107 disp.pressedButton = NONE_PRESS; 00108 } 00109 } else if (disp.activeScreen == HUM_3HRS_SCREEN) { 00110 disp.StatHumidity_3hrs(seconds, stat.humidity24hrs, secondsOffset); 00111 if (disp.pressedButton >= ZONE_1_PRESS && disp.pressedButton <= ZONE_6_PRESS) { 00112 wait_ms(150); 00113 disp.activeScreen = HUM_30MIN_SCREEN; 00114 disp.pressedButton = NONE_PRESS; 00115 } 00116 } else if (disp.activeScreen == HUM_30MIN_SCREEN) { 00117 disp.StatHumidity_30min(seconds, stat.humidity24hrs, secondsOffset); 00118 if (disp.pressedButton == STAT_HUM_PRESS) { 00119 disp.activeScreen = HUM_24HRS_SCREEN; 00120 disp.pressedButton = NONE_PRESS; 00121 } 00122 // ---------------------------------------------------------------------------------------------- 00123 // Screens with humidity statistics 00124 } else if (disp.activeScreen == TEMP_24HRS_SCREEN) { 00125 disp.StatTemperature_24hrs(seconds, stat.temperature24hrs, secondsOffset); 00126 if (disp.pressedButton >= ZONE_1_PRESS && disp.pressedButton <= ZONE_8_PRESS) { 00127 wait_ms(150); 00128 disp.activeScreen = TEMP_3HRS_SCREEN; 00129 disp.pressedButton = NONE_PRESS; 00130 } 00131 } else if (disp.activeScreen == TEMP_3HRS_SCREEN) { 00132 disp.StatTemperature_3hrs(seconds, stat.temperature24hrs, secondsOffset); 00133 if (disp.pressedButton >= ZONE_1_PRESS && disp.pressedButton <= ZONE_6_PRESS) { 00134 wait_ms(150); 00135 disp.activeScreen = TEMP_30MIN_SCREEN; 00136 disp.pressedButton = NONE_PRESS; 00137 } 00138 } else if (disp.activeScreen == TEMP_30MIN_SCREEN) { 00139 disp.StatTemperature_30min(seconds, stat.temperature24hrs, secondsOffset); 00140 if (disp.pressedButton == STAT_TEMP_PRESS) { 00141 disp.activeScreen = TEMP_24HRS_SCREEN; 00142 disp.pressedButton = NONE_PRESS; 00143 } 00144 // ---------------------------------------------------------------------------------------------- 00145 // Screens with information about sensor 00146 } else if (disp.activeScreen == ABOUT_SCREEN) { 00147 disp.AboutSensor(); 00148 } 00149 } 00150 } 00151 } 00152 }
Generated on Wed Jul 13 2022 04:41:34 by
![doxygen](doxygen.png)