
Projet Interfacage capteur de recul
Dependencies: TS_DISCO_F746NG LCD_DISCO_F746NG SRF02 BSP_DISCO_F746NG BUTTON_GROUP
main.cpp@5:8df147fe09cc, 2021-06-22 (annotated)
- Committer:
- ColineC
- Date:
- Tue Jun 22 13:22:31 2021 +0000
- Revision:
- 5:8df147fe09cc
- Parent:
- 4:fb942253d9e6
projet intefacage
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
darkseb | 0:735dae6ecacf | 1 | #include "mbed.h" |
darkseb | 0:735dae6ecacf | 2 | #include "stm32746g_discovery_lcd.h" |
darkseb | 0:735dae6ecacf | 3 | #include "stm32746g_discovery_ts.h" |
darkseb | 0:735dae6ecacf | 4 | #include "button_group.hpp" |
antoine_carpentier | 4:fb942253d9e6 | 5 | #include "LogoParisSaclay.h" |
antoine_carpentier | 4:fb942253d9e6 | 6 | #include "fleche.h" |
ColineC | 5:8df147fe09cc | 7 | #include "mbed.h" |
ColineC | 5:8df147fe09cc | 8 | #include "SRF02.h" |
antoine_carpentier | 4:fb942253d9e6 | 9 | |
ColineC | 5:8df147fe09cc | 10 | //declarations |
antoine_carpentier | 4:fb942253d9e6 | 11 | TS_StateTypeDef TS_State; |
antoine_carpentier | 4:fb942253d9e6 | 12 | |
antoine_carpentier | 4:fb942253d9e6 | 13 | uint16_t x, y; |
antoine_carpentier | 4:fb942253d9e6 | 14 | uint8_t text[30]; |
antoine_carpentier | 4:fb942253d9e6 | 15 | uint8_t status; |
ColineC | 5:8df147fe09cc | 16 | |
ColineC | 5:8df147fe09cc | 17 | void page_capteur(void); //0 |
ColineC | 5:8df147fe09cc | 18 | void page_alarme(void); //1 |
ColineC | 5:8df147fe09cc | 19 | void page_accueil(void); //2 |
ColineC | 5:8df147fe09cc | 20 | |
ColineC | 5:8df147fe09cc | 21 | int page = 2; |
antoine_carpentier | 4:fb942253d9e6 | 22 | uint8_t idx; |
ColineC | 5:8df147fe09cc | 23 | uint8_t dStd = 50; |
ColineC | 5:8df147fe09cc | 24 | uint8_t dLim = 40; |
ColineC | 5:8df147fe09cc | 25 | uint8_t dCrit = 30; |
ColineC | 5:8df147fe09cc | 26 | |
ColineC | 5:8df147fe09cc | 27 | SRF02 sensor(0xE0,PB_9,PB_8); // address, SDA, SCL |
ColineC | 5:8df147fe09cc | 28 | DigitalOut buzzer(PH_6); |
azerty000 | 1:7e34491bfd01 | 29 | |
azerty000 | 1:7e34491bfd01 | 30 | |
ColineC | 5:8df147fe09cc | 31 | //fonction pour afficher l'image fleche |
antoine_carpentier | 4:fb942253d9e6 | 32 | void drawImage_fleche(int offsetX, int offsetY) |
antoine_carpentier | 4:fb942253d9e6 | 33 | { |
antoine_carpentier | 4:fb942253d9e6 | 34 | int x = 0; |
antoine_carpentier | 4:fb942253d9e6 | 35 | int y = 0; |
antoine_carpentier | 4:fb942253d9e6 | 36 | uint32_t* dataPtr = (uint32_t*)fleche.data; |
antoine_carpentier | 4:fb942253d9e6 | 37 | while(y < fleche.height) { |
antoine_carpentier | 4:fb942253d9e6 | 38 | while(x < fleche.width) { |
antoine_carpentier | 4:fb942253d9e6 | 39 | BSP_LCD_DrawPixel(x + offsetX, y + offsetY, *dataPtr); |
antoine_carpentier | 4:fb942253d9e6 | 40 | dataPtr++; |
antoine_carpentier | 4:fb942253d9e6 | 41 | x++; |
antoine_carpentier | 4:fb942253d9e6 | 42 | } |
antoine_carpentier | 4:fb942253d9e6 | 43 | x = 0; |
antoine_carpentier | 4:fb942253d9e6 | 44 | y++; |
antoine_carpentier | 4:fb942253d9e6 | 45 | } |
antoine_carpentier | 4:fb942253d9e6 | 46 | } |
antoine_carpentier | 4:fb942253d9e6 | 47 | |
antoine_carpentier | 4:fb942253d9e6 | 48 | |
ColineC | 5:8df147fe09cc | 49 | //fonction pour afficher l'image logo |
antoine_carpentier | 4:fb942253d9e6 | 50 | void drawImage_LogoParisSaclay(int offsetX, int offsetY) |
antoine_carpentier | 4:fb942253d9e6 | 51 | { |
antoine_carpentier | 4:fb942253d9e6 | 52 | int x = 0; |
antoine_carpentier | 4:fb942253d9e6 | 53 | int y = 0; |
antoine_carpentier | 4:fb942253d9e6 | 54 | uint32_t* dataPtr = (uint32_t*)LogoParisSaclay.data; |
antoine_carpentier | 4:fb942253d9e6 | 55 | while(y < LogoParisSaclay.height) { |
antoine_carpentier | 4:fb942253d9e6 | 56 | while(x < LogoParisSaclay.width) { |
antoine_carpentier | 4:fb942253d9e6 | 57 | BSP_LCD_DrawPixel(x + offsetX, y + offsetY, *dataPtr); |
antoine_carpentier | 4:fb942253d9e6 | 58 | dataPtr++; |
antoine_carpentier | 4:fb942253d9e6 | 59 | x++; |
antoine_carpentier | 4:fb942253d9e6 | 60 | } |
antoine_carpentier | 4:fb942253d9e6 | 61 | x = 0; |
antoine_carpentier | 4:fb942253d9e6 | 62 | y++; |
antoine_carpentier | 4:fb942253d9e6 | 63 | } |
antoine_carpentier | 4:fb942253d9e6 | 64 | } |
antoine_carpentier | 4:fb942253d9e6 | 65 | |
azerty000 | 1:7e34491bfd01 | 66 | |
azerty000 | 1:7e34491bfd01 | 67 | |
ColineC | 5:8df147fe09cc | 68 | ///////////////////// |
ColineC | 5:8df147fe09cc | 69 | ///// PROGRAMME ///// |
ColineC | 5:8df147fe09cc | 70 | ///////////////////// |
darkseb | 0:735dae6ecacf | 71 | int main() |
darkseb | 0:735dae6ecacf | 72 | { |
ColineC | 5:8df147fe09cc | 73 | //initialisation de l'ecran |
darkseb | 0:735dae6ecacf | 74 | BSP_LCD_Init(); |
darkseb | 0:735dae6ecacf | 75 | BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); |
darkseb | 0:735dae6ecacf | 76 | BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); |
antoine_carpentier | 4:fb942253d9e6 | 77 | BSP_LCD_Clear(LCD_COLOR_WHITE); |
antoine_carpentier | 4:fb942253d9e6 | 78 | |
antoine_carpentier | 4:fb942253d9e6 | 79 | status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); |
antoine_carpentier | 4:fb942253d9e6 | 80 | if (status != TS_OK) { |
antoine_carpentier | 4:fb942253d9e6 | 81 | BSP_LCD_Clear(LCD_COLOR_WHITE); |
antoine_carpentier | 4:fb942253d9e6 | 82 | BSP_LCD_SetBackColor(LCD_COLOR_WHITE); |
antoine_carpentier | 4:fb942253d9e6 | 83 | BSP_LCD_SetTextColor(LCD_COLOR_GREEN); |
antoine_carpentier | 4:fb942253d9e6 | 84 | BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE); |
ColineC | 5:8df147fe09cc | 85 | } |
ColineC | 5:8df147fe09cc | 86 | else { |
antoine_carpentier | 4:fb942253d9e6 | 87 | BSP_LCD_Clear(LCD_COLOR_WHITE); |
ColineC | 5:8df147fe09cc | 88 | BSP_LCD_SetBackColor(LCD_COLOR_CYAN); |
ColineC | 5:8df147fe09cc | 89 | BSP_LCD_SetTextColor(LCD_COLOR_BLACK); |
ColineC | 5:8df147fe09cc | 90 | BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"PROJET INTERFACAGE", CENTER_MODE); |
antoine_carpentier | 4:fb942253d9e6 | 91 | } |
antoine_carpentier | 4:fb942253d9e6 | 92 | |
antoine_carpentier | 4:fb942253d9e6 | 93 | HAL_Delay(2000); |
antoine_carpentier | 4:fb942253d9e6 | 94 | BSP_LCD_Clear(LCD_COLOR_WHITE); |
antoine_carpentier | 4:fb942253d9e6 | 95 | |
antoine_carpentier | 4:fb942253d9e6 | 96 | BSP_LCD_SetFont(&Font12); |
antoine_carpentier | 4:fb942253d9e6 | 97 | BSP_LCD_SetBackColor(LCD_COLOR_WHITE); |
antoine_carpentier | 4:fb942253d9e6 | 98 | BSP_LCD_SetTextColor(LCD_COLOR_BLACK); |
darkseb | 3:5b6f580d3f3a | 99 | |
ColineC | 5:8df147fe09cc | 100 | //lancement du programme |
darkseb | 3:5b6f580d3f3a | 101 | while(1) { |
ColineC | 5:8df147fe09cc | 102 | |
ColineC | 5:8df147fe09cc | 103 | ////////////////////////////// |
ColineC | 5:8df147fe09cc | 104 | ///// DETECTION CLICS : ////// |
ColineC | 5:8df147fe09cc | 105 | ////////////////////////////// |
ColineC | 5:8df147fe09cc | 106 | |
antoine_carpentier | 4:fb942253d9e6 | 107 | BSP_TS_GetState(&TS_State); |
antoine_carpentier | 4:fb942253d9e6 | 108 | for (idx = 0; idx < TS_State.touchDetected; idx++) |
antoine_carpentier | 4:fb942253d9e6 | 109 | { |
ColineC | 5:8df147fe09cc | 110 | x = TS_State.touchX[idx]; |
ColineC | 5:8df147fe09cc | 111 | y = TS_State.touchY[idx]; |
ColineC | 5:8df147fe09cc | 112 | } |
ColineC | 5:8df147fe09cc | 113 | |
ColineC | 5:8df147fe09cc | 114 | |
ColineC | 5:8df147fe09cc | 115 | ////////////////////////////// |
ColineC | 5:8df147fe09cc | 116 | ///// AFFICHAGE PAGES : ////// |
ColineC | 5:8df147fe09cc | 117 | ////////////////////////////// |
ColineC | 5:8df147fe09cc | 118 | |
ColineC | 5:8df147fe09cc | 119 | //PAGE ACCUEIL VERS PAGE CAPTEUR |
ColineC | 5:8df147fe09cc | 120 | //si page p et clic sur cadre correspondant |
ColineC | 5:8df147fe09cc | 121 | if ((page == 2) && (x>= 65 && x<= 215) && (y>= 55 && y<= 230)) |
ColineC | 5:8df147fe09cc | 122 | { |
ColineC | 5:8df147fe09cc | 123 | //reset ecran et coordonnées |
ColineC | 5:8df147fe09cc | 124 | BSP_LCD_Clear(LCD_COLOR_WHITE); |
ColineC | 5:8df147fe09cc | 125 | x = 0; |
ColineC | 5:8df147fe09cc | 126 | y = 0; |
ColineC | 5:8df147fe09cc | 127 | //affichage page p |
ColineC | 5:8df147fe09cc | 128 | page = 0; |
ColineC | 5:8df147fe09cc | 129 | HAL_Delay(300); |
ColineC | 5:8df147fe09cc | 130 | } |
ColineC | 5:8df147fe09cc | 131 | |
ColineC | 5:8df147fe09cc | 132 | //PAGE ACCUEIL VERS PAGE ALARME |
ColineC | 5:8df147fe09cc | 133 | if ((page == 2) && (x>= 265 && x<= 415) && (y>= 55 && y<= 230)) |
ColineC | 5:8df147fe09cc | 134 | { |
ColineC | 5:8df147fe09cc | 135 | BSP_LCD_Clear(LCD_COLOR_WHITE); |
ColineC | 5:8df147fe09cc | 136 | x = 0; |
ColineC | 5:8df147fe09cc | 137 | y = 0; |
ColineC | 5:8df147fe09cc | 138 | page = 1; |
ColineC | 5:8df147fe09cc | 139 | HAL_Delay(300); |
ColineC | 5:8df147fe09cc | 140 | } |
ColineC | 5:8df147fe09cc | 141 | |
ColineC | 5:8df147fe09cc | 142 | // PAGE CAPTEUR VERS PAGE D'ACCUEIL |
ColineC | 5:8df147fe09cc | 143 | if ((page == 0) && (x>= 455 && x<= 480) && (y>= 0 && y<= 25)) |
ColineC | 5:8df147fe09cc | 144 | { |
ColineC | 5:8df147fe09cc | 145 | BSP_LCD_Clear(LCD_COLOR_WHITE); |
ColineC | 5:8df147fe09cc | 146 | x = 0; |
ColineC | 5:8df147fe09cc | 147 | y = 0; |
ColineC | 5:8df147fe09cc | 148 | page = 2; |
ColineC | 5:8df147fe09cc | 149 | HAL_Delay(300); |
ColineC | 5:8df147fe09cc | 150 | } |
ColineC | 5:8df147fe09cc | 151 | |
ColineC | 5:8df147fe09cc | 152 | // PAGE ALARME VERS PAGE D'ACCUEIL |
ColineC | 5:8df147fe09cc | 153 | if ((page == 1) && (x>= 455 && x<= 480) && (y>= 0 && y<= 25)) |
ColineC | 5:8df147fe09cc | 154 | { |
ColineC | 5:8df147fe09cc | 155 | BSP_LCD_Clear(LCD_COLOR_WHITE); |
ColineC | 5:8df147fe09cc | 156 | x = 0; |
ColineC | 5:8df147fe09cc | 157 | y = 0; |
ColineC | 5:8df147fe09cc | 158 | page = 2; |
ColineC | 5:8df147fe09cc | 159 | HAL_Delay(300); |
ColineC | 5:8df147fe09cc | 160 | } |
ColineC | 5:8df147fe09cc | 161 | |
ColineC | 5:8df147fe09cc | 162 | // AFFICHAGE DE LA PAGE D'ACCUEIL |
ColineC | 5:8df147fe09cc | 163 | else if (page == 2) |
antoine_carpentier | 4:fb942253d9e6 | 164 | { |
ColineC | 5:8df147fe09cc | 165 | page_accueil(); |
ColineC | 5:8df147fe09cc | 166 | } |
ColineC | 5:8df147fe09cc | 167 | |
ColineC | 5:8df147fe09cc | 168 | |
ColineC | 5:8df147fe09cc | 169 | ///////////////////////// |
ColineC | 5:8df147fe09cc | 170 | ///// MODE CAPTEUR : //// |
ColineC | 5:8df147fe09cc | 171 | ///////////////////////// |
ColineC | 5:8df147fe09cc | 172 | |
ColineC | 5:8df147fe09cc | 173 | //REGLAGE DES SEUILS D'ALARME : |
antoine_carpentier | 4:fb942253d9e6 | 174 | |
ColineC | 5:8df147fe09cc | 175 | //dStd -1 |
ColineC | 5:8df147fe09cc | 176 | //en page capteur, si clic sur cadre correspondant |
ColineC | 5:8df147fe09cc | 177 | else if ((page == 0) && (x>= 8 && x<= 55) && (y>= 33 && y<= 85)) |
ColineC | 5:8df147fe09cc | 178 | { |
ColineC | 5:8df147fe09cc | 179 | x = 0; |
ColineC | 5:8df147fe09cc | 180 | y = 0; |
ColineC | 5:8df147fe09cc | 181 | //si seuil changeable |
ColineC | 5:8df147fe09cc | 182 | if (dStd >> (dLim+5) && dStd <= 80) |
ColineC | 5:8df147fe09cc | 183 | //modifier en conséquence |
ColineC | 5:8df147fe09cc | 184 | { dStd = dStd - 1; } |
ColineC | 5:8df147fe09cc | 185 | HAL_Delay(200); |
ColineC | 5:8df147fe09cc | 186 | } |
ColineC | 5:8df147fe09cc | 187 | |
ColineC | 5:8df147fe09cc | 188 | //dStd +1 |
ColineC | 5:8df147fe09cc | 189 | else if ((page == 0) && (x>= 188 && x<= 231) && (y>= 33 && y<= 85)) |
ColineC | 5:8df147fe09cc | 190 | { |
ColineC | 5:8df147fe09cc | 191 | x = 0; |
ColineC | 5:8df147fe09cc | 192 | y = 0; |
ColineC | 5:8df147fe09cc | 193 | if (dStd >= (dLim+5) && dStd < 80) |
ColineC | 5:8df147fe09cc | 194 | { dStd = dStd + 1; } |
ColineC | 5:8df147fe09cc | 195 | HAL_Delay(200); |
ColineC | 5:8df147fe09cc | 196 | } |
ColineC | 5:8df147fe09cc | 197 | |
ColineC | 5:8df147fe09cc | 198 | //dLim -1 |
ColineC | 5:8df147fe09cc | 199 | else if ((page == 0) && (x>= 8 && x<= 51) && (y>= 113 && y<= 160)) |
antoine_carpentier | 4:fb942253d9e6 | 200 | { |
ColineC | 5:8df147fe09cc | 201 | x = 0; |
ColineC | 5:8df147fe09cc | 202 | y = 0; |
ColineC | 5:8df147fe09cc | 203 | if (dLim > (dCrit+5) && dLim <= (dStd-5)) |
ColineC | 5:8df147fe09cc | 204 | { dLim = dLim - 1; } |
ColineC | 5:8df147fe09cc | 205 | HAL_Delay(200); |
ColineC | 5:8df147fe09cc | 206 | } |
ColineC | 5:8df147fe09cc | 207 | |
ColineC | 5:8df147fe09cc | 208 | //dLim +1 |
ColineC | 5:8df147fe09cc | 209 | else if ((page == 0) && (x>= 193 && x<= 236) && (y>= 113 && y<= 160)) |
ColineC | 5:8df147fe09cc | 210 | { |
ColineC | 5:8df147fe09cc | 211 | x = 0; |
ColineC | 5:8df147fe09cc | 212 | y = 0; |
ColineC | 5:8df147fe09cc | 213 | if (dLim >= (dCrit+5) && dLim < (dStd-5)) |
ColineC | 5:8df147fe09cc | 214 | { dLim = dLim + 1; } |
ColineC | 5:8df147fe09cc | 215 | HAL_Delay(200); |
ColineC | 5:8df147fe09cc | 216 | } |
ColineC | 5:8df147fe09cc | 217 | |
ColineC | 5:8df147fe09cc | 218 | //dCrit -1 |
ColineC | 5:8df147fe09cc | 219 | else if ((page == 0) && (x>= 8 && x<= 51) && (y>= 193 && y<= 240)) |
ColineC | 5:8df147fe09cc | 220 | { |
ColineC | 5:8df147fe09cc | 221 | x = 0; |
ColineC | 5:8df147fe09cc | 222 | y = 0; |
ColineC | 5:8df147fe09cc | 223 | if (dCrit > 20 && dCrit <= (dLim-5)) |
ColineC | 5:8df147fe09cc | 224 | { dCrit = dCrit - 1; } |
ColineC | 5:8df147fe09cc | 225 | HAL_Delay(200); |
ColineC | 5:8df147fe09cc | 226 | } |
antoine_carpentier | 4:fb942253d9e6 | 227 | |
antoine_carpentier | 4:fb942253d9e6 | 228 | |
ColineC | 5:8df147fe09cc | 229 | //dCrit +1 |
ColineC | 5:8df147fe09cc | 230 | else if ((page == 0) && (x>= 193 && x<= 236) && (y>= 193 && y<= 240)) |
antoine_carpentier | 4:fb942253d9e6 | 231 | { |
ColineC | 5:8df147fe09cc | 232 | x = 0; |
ColineC | 5:8df147fe09cc | 233 | y = 0; |
ColineC | 5:8df147fe09cc | 234 | if (dCrit >= 20 && dCrit < (dLim-5)) |
ColineC | 5:8df147fe09cc | 235 | { dCrit = dCrit + 1; } |
ColineC | 5:8df147fe09cc | 236 | HAL_Delay(200); |
ColineC | 5:8df147fe09cc | 237 | } |
antoine_carpentier | 4:fb942253d9e6 | 238 | |
ColineC | 5:8df147fe09cc | 239 | else if (page == 0) |
antoine_carpentier | 4:fb942253d9e6 | 240 | { |
ColineC | 5:8df147fe09cc | 241 | // AFFICHAGE DE LA PAGE MODE CAPTEUR |
ColineC | 5:8df147fe09cc | 242 | page_capteur(); |
ColineC | 5:8df147fe09cc | 243 | |
ColineC | 5:8df147fe09cc | 244 | |
ColineC | 5:8df147fe09cc | 245 | //LECTURE DU CAPTEUR ET AFFICHAGE DE LA DISTANCE MESUREE |
ColineC | 5:8df147fe09cc | 246 | int distance; |
ColineC | 5:8df147fe09cc | 247 | //lecture du capteur en cm |
ColineC | 5:8df147fe09cc | 248 | distance = sensor.GetCentimeters(); |
ColineC | 5:8df147fe09cc | 249 | //affichage sur l'ecran |
ColineC | 5:8df147fe09cc | 250 | BSP_LCD_SetTextColor(LCD_COLOR_BLACK); |
ColineC | 5:8df147fe09cc | 251 | sprintf((char*)text, "Distance = %d cm",distance); |
ColineC | 5:8df147fe09cc | 252 | BSP_LCD_DisplayStringAt(80, LINE(3), (uint8_t *)&text, RIGHT_MODE); |
ColineC | 5:8df147fe09cc | 253 | HAL_Delay(20); |
ColineC | 5:8df147fe09cc | 254 | |
ColineC | 5:8df147fe09cc | 255 | |
ColineC | 5:8df147fe09cc | 256 | //AFFICHAGE DES ALARMES ET DECLENCHEMENT DES BIPS |
ColineC | 5:8df147fe09cc | 257 | if(distance >= dStd){ //distance > a tous les seuils d'alarme (ras) |
ColineC | 5:8df147fe09cc | 258 | buzzer = 0; |
antoine_carpentier | 4:fb942253d9e6 | 259 | } |
antoine_carpentier | 4:fb942253d9e6 | 260 | |
ColineC | 5:8df147fe09cc | 261 | //premier seuil |
ColineC | 5:8df147fe09cc | 262 | if(distance < dStd){ //dStd triggered |
ColineC | 5:8df147fe09cc | 263 | //afficher rectangle vert |
ColineC | 5:8df147fe09cc | 264 | BSP_LCD_SetTextColor(LCD_COLOR_GREEN); |
ColineC | 5:8df147fe09cc | 265 | BSP_LCD_FillRect(347, 180, 40, 40); |
antoine_carpentier | 4:fb942253d9e6 | 266 | } |
ColineC | 5:8df147fe09cc | 267 | else{ //dStd ok |
ColineC | 5:8df147fe09cc | 268 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
ColineC | 5:8df147fe09cc | 269 | BSP_LCD_FillRect(347, 180, 40, 40); |
antoine_carpentier | 4:fb942253d9e6 | 270 | } |
antoine_carpentier | 4:fb942253d9e6 | 271 | |
ColineC | 5:8df147fe09cc | 272 | //deuxième seuil |
ColineC | 5:8df147fe09cc | 273 | if(distance < dLim){ //dLim triggered |
ColineC | 5:8df147fe09cc | 274 | //afficher rectangle orange |
ColineC | 5:8df147fe09cc | 275 | BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); |
ColineC | 5:8df147fe09cc | 276 | BSP_LCD_FillRect(338, 115, 60, 50); |
ColineC | 5:8df147fe09cc | 277 | //faire bipper buzzer |
ColineC | 5:8df147fe09cc | 278 | if(distance > dCrit){ |
ColineC | 5:8df147fe09cc | 279 | buzzer = 1; |
ColineC | 5:8df147fe09cc | 280 | HAL_Delay(250); |
ColineC | 5:8df147fe09cc | 281 | buzzer = 0; |
ColineC | 5:8df147fe09cc | 282 | HAL_Delay(750); |
ColineC | 5:8df147fe09cc | 283 | } |
ColineC | 5:8df147fe09cc | 284 | } |
ColineC | 5:8df147fe09cc | 285 | else{ //dLim ok |
ColineC | 5:8df147fe09cc | 286 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
ColineC | 5:8df147fe09cc | 287 | BSP_LCD_FillRect(338, 115, 60, 50); |
ColineC | 5:8df147fe09cc | 288 | buzzer = 0; |
antoine_carpentier | 4:fb942253d9e6 | 289 | } |
antoine_carpentier | 4:fb942253d9e6 | 290 | |
ColineC | 5:8df147fe09cc | 291 | //seuil max |
ColineC | 5:8df147fe09cc | 292 | if(distance < dCrit){ //dCrit triggered |
ColineC | 5:8df147fe09cc | 293 | //afficher rectangle rouge |
ColineC | 5:8df147fe09cc | 294 | BSP_LCD_SetTextColor(LCD_COLOR_RED); |
ColineC | 5:8df147fe09cc | 295 | BSP_LCD_FillRect(330, 45, 80, 55); |
ColineC | 5:8df147fe09cc | 296 | //faire sonner buzzer en continu |
ColineC | 5:8df147fe09cc | 297 | buzzer = 1; |
ColineC | 5:8df147fe09cc | 298 | } |
ColineC | 5:8df147fe09cc | 299 | else{ //dCrit ok |
ColineC | 5:8df147fe09cc | 300 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
ColineC | 5:8df147fe09cc | 301 | BSP_LCD_FillRect(330, 45, 80, 55); |
ColineC | 5:8df147fe09cc | 302 | buzzer = 0; |
antoine_carpentier | 4:fb942253d9e6 | 303 | } |
antoine_carpentier | 4:fb942253d9e6 | 304 | |
ColineC | 5:8df147fe09cc | 305 | }//fin mode capteur |
ColineC | 5:8df147fe09cc | 306 | |
ColineC | 5:8df147fe09cc | 307 | |
ColineC | 5:8df147fe09cc | 308 | ///////////////////////// |
ColineC | 5:8df147fe09cc | 309 | ///// MODE ALARME : ///// |
ColineC | 5:8df147fe09cc | 310 | ///////////////////////// |
darkseb | 0:735dae6ecacf | 311 | |
antoine_carpentier | 4:fb942253d9e6 | 312 | else if (page == 1) |
antoine_carpentier | 4:fb942253d9e6 | 313 | { |
ColineC | 5:8df147fe09cc | 314 | // AFFICHAGE DE LA PAGE MODE ALARME |
ColineC | 5:8df147fe09cc | 315 | page_alarme(); |
ColineC | 5:8df147fe09cc | 316 | |
darkseb | 3:5b6f580d3f3a | 317 | |
ColineC | 5:8df147fe09cc | 318 | //LECTURE DU CAPTEUR ET AFFICHAGE DE LA DISTANCE MESUREE |
ColineC | 5:8df147fe09cc | 319 | int distance; |
ColineC | 5:8df147fe09cc | 320 | //lecture du capteur en cm |
ColineC | 5:8df147fe09cc | 321 | distance = sensor.GetCentimeters(); |
ColineC | 5:8df147fe09cc | 322 | sprintf((char*)text, "Distance = %d cm",distance); |
ColineC | 5:8df147fe09cc | 323 | BSP_LCD_DisplayStringAt(80, LINE(3), (uint8_t *)&text, RIGHT_MODE); |
ColineC | 5:8df147fe09cc | 324 | HAL_Delay(20); |
antoine_carpentier | 4:fb942253d9e6 | 325 | |
antoine_carpentier | 4:fb942253d9e6 | 326 | |
ColineC | 5:8df147fe09cc | 327 | // ALERTE |
ColineC | 5:8df147fe09cc | 328 | if(distance < 40){ //alarme triggered |
ColineC | 5:8df147fe09cc | 329 | //afficher rectangle |
ColineC | 5:8df147fe09cc | 330 | BSP_LCD_SetTextColor(LCD_COLOR_RED); |
ColineC | 5:8df147fe09cc | 331 | BSP_LCD_FillRect(165,70,150,150); |
ColineC | 5:8df147fe09cc | 332 | //faire sonner buzzer en continu |
ColineC | 5:8df147fe09cc | 333 | buzzer = 1; |
antoine_carpentier | 4:fb942253d9e6 | 334 | } |
ColineC | 5:8df147fe09cc | 335 | else{ //alarme ok |
ColineC | 5:8df147fe09cc | 336 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
ColineC | 5:8df147fe09cc | 337 | BSP_LCD_FillRect(165,70,150,150); |
ColineC | 5:8df147fe09cc | 338 | buzzer = 0; |
darkseb | 0:735dae6ecacf | 339 | } |
darkseb | 0:735dae6ecacf | 340 | |
ColineC | 5:8df147fe09cc | 341 | //afficher message detection |
ColineC | 5:8df147fe09cc | 342 | sprintf((char*)text, "INTRUSION"); |
ColineC | 5:8df147fe09cc | 343 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)&text, CENTER_MODE); |
antoine_carpentier | 4:fb942253d9e6 | 344 | |
ColineC | 5:8df147fe09cc | 345 | }//fin mode alarme |
ColineC | 5:8df147fe09cc | 346 | |
ColineC | 5:8df147fe09cc | 347 | }//fin while |
ColineC | 5:8df147fe09cc | 348 | |
ColineC | 5:8df147fe09cc | 349 | }//fin main |
ColineC | 5:8df147fe09cc | 350 | |
ColineC | 5:8df147fe09cc | 351 | |
ColineC | 5:8df147fe09cc | 352 | |
ColineC | 5:8df147fe09cc | 353 | ///////////////////////// |
ColineC | 5:8df147fe09cc | 354 | ///// PAGE CAPTEUR ////// |
ColineC | 5:8df147fe09cc | 355 | ///////////////////////// |
ColineC | 5:8df147fe09cc | 356 | void page_capteur () |
ColineC | 5:8df147fe09cc | 357 | { |
ColineC | 5:8df147fe09cc | 358 | page = 0; |
ColineC | 5:8df147fe09cc | 359 | BSP_LCD_SetTextColor(LCD_COLOR_BLACK); |
ColineC | 5:8df147fe09cc | 360 | |
ColineC | 5:8df147fe09cc | 361 | //afficher logo |
ColineC | 5:8df147fe09cc | 362 | drawImage_LogoParisSaclay(0,0); |
ColineC | 5:8df147fe09cc | 363 | |
ColineC | 5:8df147fe09cc | 364 | //afficher titre page |
ColineC | 5:8df147fe09cc | 365 | sprintf((char*)text, "Mode Capteur de recul"); |
ColineC | 5:8df147fe09cc | 366 | BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)&text, CENTER_MODE); |
ColineC | 5:8df147fe09cc | 367 | |
ColineC | 5:8df147fe09cc | 368 | //afficher fleche |
ColineC | 5:8df147fe09cc | 369 | drawImage_fleche(447,0); |
ColineC | 5:8df147fe09cc | 370 | |
ColineC | 5:8df147fe09cc | 371 | //ligne de "cadre" |
ColineC | 5:8df147fe09cc | 372 | BSP_LCD_DrawHLine(0,24,480); |
ColineC | 5:8df147fe09cc | 373 | |
antoine_carpentier | 4:fb942253d9e6 | 374 | |
ColineC | 5:8df147fe09cc | 375 | //ZONE REGLAGE dStd |
ColineC | 5:8df147fe09cc | 376 | //afficher rectangle cadre |
ColineC | 5:8df147fe09cc | 377 | BSP_LCD_DrawRect(8, 33, 228, 74); |
ColineC | 5:8df147fe09cc | 378 | //afficher seuil |
ColineC | 5:8df147fe09cc | 379 | sprintf ((char*)text, "%d", dStd); |
ColineC | 5:8df147fe09cc | 380 | BSP_LCD_DisplayStringAt(110, 51, (uint8_t *)&text, LEFT_MODE); |
ColineC | 5:8df147fe09cc | 381 | //ligne "cadre" - |
ColineC | 5:8df147fe09cc | 382 | BSP_LCD_DrawVLine(51,33,47); |
ColineC | 5:8df147fe09cc | 383 | //afficher - |
ColineC | 5:8df147fe09cc | 384 | sprintf((char*)text, "-"); |
ColineC | 5:8df147fe09cc | 385 | BSP_LCD_DisplayStringAt(26, 51, (uint8_t *)&text, LEFT_MODE); |
ColineC | 5:8df147fe09cc | 386 | //ligne "cadre" + |
ColineC | 5:8df147fe09cc | 387 | BSP_LCD_DrawVLine(193,33,47); |
ColineC | 5:8df147fe09cc | 388 | //afficher + |
ColineC | 5:8df147fe09cc | 389 | sprintf((char*)text, "+"); |
ColineC | 5:8df147fe09cc | 390 | BSP_LCD_DisplayStringAt(212, 51, (uint8_t *)&text, LEFT_MODE); |
ColineC | 5:8df147fe09cc | 391 | //ligne "cadre" nom du seuil |
ColineC | 5:8df147fe09cc | 392 | BSP_LCD_DrawHLine(8,80,228); |
ColineC | 5:8df147fe09cc | 393 | //afficher nom du seuil |
ColineC | 5:8df147fe09cc | 394 | sprintf((char*)text, "Distance acceptable"); |
ColineC | 5:8df147fe09cc | 395 | BSP_LCD_DisplayStringAt(57,87, (uint8_t *)&text, LEFT_MODE); |
ColineC | 5:8df147fe09cc | 396 | |
ColineC | 5:8df147fe09cc | 397 | |
ColineC | 5:8df147fe09cc | 398 | //ZONE REGLAGE dLim |
ColineC | 5:8df147fe09cc | 399 | BSP_LCD_DrawRect(8, 113, 228, 74); |
ColineC | 5:8df147fe09cc | 400 | sprintf((char*)text, "%d", dLim); |
ColineC | 5:8df147fe09cc | 401 | BSP_LCD_DisplayStringAt(110, 131, (uint8_t *)&text, LEFT_MODE); |
ColineC | 5:8df147fe09cc | 402 | BSP_LCD_DrawVLine(51,113,47); |
ColineC | 5:8df147fe09cc | 403 | sprintf((char*)text, "-"); |
ColineC | 5:8df147fe09cc | 404 | BSP_LCD_DisplayStringAt(27, 131, (uint8_t *)&text, LEFT_MODE); |
ColineC | 5:8df147fe09cc | 405 | BSP_LCD_DrawVLine(193,113,47); |
ColineC | 5:8df147fe09cc | 406 | sprintf((char*)text, "+"); |
ColineC | 5:8df147fe09cc | 407 | BSP_LCD_DisplayStringAt(212, 131, (uint8_t *)&text, LEFT_MODE); |
ColineC | 5:8df147fe09cc | 408 | BSP_LCD_DrawHLine(8,160,228); |
ColineC | 5:8df147fe09cc | 409 | sprintf((char*)text, "Distance limite"); |
ColineC | 5:8df147fe09cc | 410 | BSP_LCD_DisplayStringAt(70, 167, (uint8_t *)&text, LEFT_MODE); |
ColineC | 5:8df147fe09cc | 411 | |
ColineC | 5:8df147fe09cc | 412 | //ZONE REGLAGE dCrit |
ColineC | 5:8df147fe09cc | 413 | BSP_LCD_DrawRect(8, 193, 228, 73); |
ColineC | 5:8df147fe09cc | 414 | sprintf((char*)text, "%d", dCrit); |
ColineC | 5:8df147fe09cc | 415 | BSP_LCD_DisplayStringAt(110, 212, (uint8_t *)&text, LEFT_MODE); |
ColineC | 5:8df147fe09cc | 416 | BSP_LCD_DrawVLine(50,193,47); |
ColineC | 5:8df147fe09cc | 417 | sprintf((char*)text, "-"); |
ColineC | 5:8df147fe09cc | 418 | BSP_LCD_DisplayStringAt(27, 212, (uint8_t *)&text, LEFT_MODE); |
ColineC | 5:8df147fe09cc | 419 | BSP_LCD_DrawVLine(193,193,47); |
ColineC | 5:8df147fe09cc | 420 | sprintf((char*)text, "+"); |
ColineC | 5:8df147fe09cc | 421 | BSP_LCD_DisplayStringAt(212, 212, (uint8_t *)&text, LEFT_MODE); |
ColineC | 5:8df147fe09cc | 422 | BSP_LCD_DrawHLine(8,240,228); |
ColineC | 5:8df147fe09cc | 423 | sprintf((char*)text, "Distance critique"); |
ColineC | 5:8df147fe09cc | 424 | BSP_LCD_DisplayStringAt(63, 247, (uint8_t *)&text, LEFT_MODE); |
ColineC | 5:8df147fe09cc | 425 | |
ColineC | 5:8df147fe09cc | 426 | |
ColineC | 5:8df147fe09cc | 427 | //PASTILLE DE BASE |
ColineC | 5:8df147fe09cc | 428 | BSP_LCD_SetTextColor(LCD_COLOR_GREEN); |
ColineC | 5:8df147fe09cc | 429 | BSP_LCD_FillRect(350, 237, 30, 30); |
antoine_carpentier | 4:fb942253d9e6 | 430 | } |
antoine_carpentier | 4:fb942253d9e6 | 431 | |
antoine_carpentier | 4:fb942253d9e6 | 432 | |
antoine_carpentier | 4:fb942253d9e6 | 433 | |
ColineC | 5:8df147fe09cc | 434 | /////////////////////// |
ColineC | 5:8df147fe09cc | 435 | ///// PAGE ALARME ///// |
ColineC | 5:8df147fe09cc | 436 | /////////////////////// |
ColineC | 5:8df147fe09cc | 437 | void page_alarme() |
ColineC | 5:8df147fe09cc | 438 | { |
antoine_carpentier | 4:fb942253d9e6 | 439 | page = 1; |
darkseb | 3:5b6f580d3f3a | 440 | |
ColineC | 5:8df147fe09cc | 441 | //afficher logo |
antoine_carpentier | 4:fb942253d9e6 | 442 | drawImage_LogoParisSaclay(0,0); |
ColineC | 5:8df147fe09cc | 443 | |
ColineC | 5:8df147fe09cc | 444 | //afficher fleche |
antoine_carpentier | 4:fb942253d9e6 | 445 | drawImage_fleche(447,0); |
antoine_carpentier | 4:fb942253d9e6 | 446 | BSP_LCD_SetTextColor(LCD_COLOR_BLACK); |
ColineC | 5:8df147fe09cc | 447 | |
ColineC | 5:8df147fe09cc | 448 | //ligne de "cadre" |
ColineC | 5:8df147fe09cc | 449 | BSP_LCD_DrawHLine(0,24,480); |
antoine_carpentier | 4:fb942253d9e6 | 450 | |
ColineC | 5:8df147fe09cc | 451 | //afficher titre page |
ColineC | 5:8df147fe09cc | 452 | sprintf((char*)text, "Mode Alarme de securite"); |
ColineC | 5:8df147fe09cc | 453 | BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)&text, CENTER_MODE); |
ColineC | 5:8df147fe09cc | 454 | } |
ColineC | 5:8df147fe09cc | 455 | |
ColineC | 5:8df147fe09cc | 456 | |
ColineC | 5:8df147fe09cc | 457 | //////////////////////// |
ColineC | 5:8df147fe09cc | 458 | ///// PAGE ACCUEIL ///// |
ColineC | 5:8df147fe09cc | 459 | //////////////////////// |
antoine_carpentier | 4:fb942253d9e6 | 460 | |
ColineC | 5:8df147fe09cc | 461 | void page_accueil() |
ColineC | 5:8df147fe09cc | 462 | { |
antoine_carpentier | 4:fb942253d9e6 | 463 | page = 2; |
antoine_carpentier | 4:fb942253d9e6 | 464 | BSP_LCD_SetTextColor(LCD_COLOR_BLACK); |
darkseb | 3:5b6f580d3f3a | 465 | |
ColineC | 5:8df147fe09cc | 466 | //afficher logo |
antoine_carpentier | 4:fb942253d9e6 | 467 | drawImage_LogoParisSaclay(0,0); |
darkseb | 3:5b6f580d3f3a | 468 | |
ColineC | 5:8df147fe09cc | 469 | //afficher titre page |
antoine_carpentier | 4:fb942253d9e6 | 470 | sprintf((char*)text, "Page d'accueil"); |
antoine_carpentier | 4:fb942253d9e6 | 471 | BSP_LCD_DisplayStringAt(0, LINE(2), (uint8_t *)&text, CENTER_MODE); |
darkseb | 3:5b6f580d3f3a | 472 | |
ColineC | 5:8df147fe09cc | 473 | //Mode recul |
ColineC | 5:8df147fe09cc | 474 | //afficher rectangle cadre |
ColineC | 5:8df147fe09cc | 475 | BSP_LCD_DrawRect(65, 55, 150, 175); |
ColineC | 5:8df147fe09cc | 476 | //ligne "cadre" nom du mode |
antoine_carpentier | 4:fb942253d9e6 | 477 | BSP_LCD_DrawHLine(65,210,150); |
ColineC | 5:8df147fe09cc | 478 | //afficher nom du mode |
ColineC | 5:8df147fe09cc | 479 | sprintf((char*)text, "Capteur de recul"); |
ColineC | 5:8df147fe09cc | 480 | BSP_LCD_DisplayStringAt(85, LINE(18), (uint8_t *)&text, LEFT_MODE); |
darkseb | 3:5b6f580d3f3a | 481 | |
darkseb | 3:5b6f580d3f3a | 482 | |
ColineC | 5:8df147fe09cc | 483 | //Mode alarme |
ColineC | 5:8df147fe09cc | 484 | BSP_LCD_DrawRect(265, 55, 150, 175); |
antoine_carpentier | 4:fb942253d9e6 | 485 | BSP_LCD_DrawHLine(265,210,150); |
antoine_carpentier | 4:fb942253d9e6 | 486 | BSP_LCD_SetTextColor(LCD_COLOR_BLUE); |
ColineC | 5:8df147fe09cc | 487 | sprintf((char*)text, "Alarme de securite"); |
antoine_carpentier | 4:fb942253d9e6 | 488 | BSP_LCD_DisplayStringAt(102, LINE(18), (uint8_t *)&text, CENTER_MODE); |
ColineC | 5:8df147fe09cc | 489 | } |