
Projet Interfacage capteur de recul
Dependencies: TS_DISCO_F746NG LCD_DISCO_F746NG SRF02 BSP_DISCO_F746NG BUTTON_GROUP
main.cpp
- Committer:
- antoine_carpentier
- Date:
- 2021-06-03
- Revision:
- 4:fb942253d9e6
- Parent:
- 3:5b6f580d3f3a
- Child:
- 5:8df147fe09cc
File content as of revision 4:fb942253d9e6:
#include "mbed.h" #include "stm32746g_discovery_lcd.h" #include "stm32746g_discovery_ts.h" #include "button_group.hpp" #include "bluetooth.h" #include "LogoParisSaclay.h" #include "market.h" #include "fleche.h" #include "badine.h" #include "balzac.h" #include "barjavel.h" #include "blacksad.h" #include "boule.h" #include "cahier.h" #include "cid.h" #include "cyrano.h" #include "domjuan.h" #include "eblouissements.h" #include "fleurs.h" #include "fourneaux.h" #include "gazette.h" #include "hernani.h" #include "passemiroir.h" #include "potter.h" #include "quijote.h" #include "saturniens.h" #include "talon.h" #include "vergers.h" //using namespace Mikami; //TS_DISCO_F746NG ts_; //LCD_DISCO_F746NG lcd_; TS_StateTypeDef TS_State; void page_commande(void); void page_liste(void); void page_accueil(void); int page = 2; uint16_t x, y; uint8_t text[30]; uint8_t status; uint8_t idx; uint8_t cleared = 0; uint8_t prev_nb_touches = 0; //float prix_total = 0; //char buffer [50]; //market void drawImage_market(int offsetX, int offsetY) { int x = 0; int y = 0; uint32_t* dataPtr = (uint32_t*)market.data; while(y < market.height) { while(x < market.width) { BSP_LCD_DrawPixel(x + offsetX, y + offsetY, *dataPtr); dataPtr++; x++; } x = 0; y++; } } //fleche void drawImage_fleche(int offsetX, int offsetY) { int x = 0; int y = 0; uint32_t* dataPtr = (uint32_t*)fleche.data; while(y < fleche.height) { while(x < fleche.width) { BSP_LCD_DrawPixel(x + offsetX, y + offsetY, *dataPtr); dataPtr++; x++; } x = 0; y++; } } //LogoBT void drawImage_BT(int offsetX, int offsetY) { int x = 0; int y = 0; uint32_t* dataPtr = (uint32_t*)bluetooth.data; while(y < bluetooth.height) { while(x < bluetooth.width) { BSP_LCD_DrawPixel(x + offsetX, y + offsetY, *dataPtr); dataPtr++; x++; } x = 0; y++; } } //Logo void drawImage_LogoParisSaclay(int offsetX, int offsetY) { int x = 0; int y = 0; uint32_t* dataPtr = (uint32_t*)LogoParisSaclay.data; while(y < LogoParisSaclay.height) { while(x < LogoParisSaclay.width) { BSP_LCD_DrawPixel(x + offsetX, y + offsetY, *dataPtr); dataPtr++; x++; } x = 0; y++; } } //blacksad void drawImage_blacksad(int offsetX, int offsetY) { int x = 0; int y = 0; uint32_t* dataPtr = (uint32_t*)blacksad.data; while(y < blacksad.height) { while(x < blacksad.width) { BSP_LCD_DrawPixel(x + offsetX, y + offsetY, *dataPtr); dataPtr++; x++; } x = 0; y++; } } int main() { int c[6]={0,0,0,0,0,0}; //0 = a traiter 1 = en cours 2 = fait int commande = 6; BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); BSP_LCD_Clear(LCD_COLOR_WHITE); status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); if (status != TS_OK) { BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE); } else { BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)"Bienvenue chez Liroy Merlin", CENTER_MODE); } HAL_Delay(2000); BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_SetFont(&Font12); BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); while(1) { // DETECTION CLICS BSP_TS_GetState(&TS_State); for (idx = 0; idx < TS_State.touchDetected; idx++) { x = TS_State.touchX[idx]; y = TS_State.touchY[idx]; } //////////////////CLICS////////////// // PAGE COMMANDE VERS PAGE D'ACCUEIL if ((page == 0) && (x>= 458 && x<= 480) && (y>= 0 && y<= 22)) { BSP_LCD_Clear(LCD_COLOR_WHITE); x = 0; y = 0; page = 2; HAL_Delay(300); } //PAGE ACCUEIL VERS PAGE COMMANDE if ((page == 2) && (x>= 65 && x<= 215) && (y>= 60 && y<= 240)) { BSP_LCD_Clear(LCD_COLOR_WHITE); x = 0; y = 0; page = 0; HAL_Delay(300); } // PAGE LISTE VERS PAGE COMMANDE if ((page == 1) && (x>= 458 && x<= 480) && (y>= 0 && y<= 22)) { BSP_LCD_Clear(LCD_COLOR_WHITE); x = 0; y = 0; page = 0; commande = 6; HAL_Delay(300); } //PAGE COMMANDE // HAUT GAUCHE else if ((page == 0) && (x>= 8 && x<= 236) && (y>= 29 && y<= 103)) { x = 0; y = 0; page = 1; BSP_LCD_Clear(LCD_COLOR_WHITE); page_liste(); commande = 0; HAL_Delay(200); } // HAUT DROITE else if ((page == 0) && (x>= 244 && x<= 472) && (y>= 29 && y<= 103)) { x = 0; y = 0; page = 1; BSP_LCD_Clear(LCD_COLOR_WHITE); page_liste(); commande = 1; HAL_Delay(200); } // MILIEU GAUCHE else if ((page == 0) && (x>= 8 && x<= 236) && (y>= 110 && y<= 184)) { x = 0; y = 0; page = 1; BSP_LCD_Clear(LCD_COLOR_WHITE); page_liste(); commande = 2; HAL_Delay(200); } // MILIEU DROITE else if ((page == 0) && (x>= 244 && x<= 472) && (y>= 110 && y<= 184)) { x = 0; y = 0; page = 1; BSP_LCD_Clear(LCD_COLOR_WHITE); page_liste(); commande = 3; HAL_Delay(200); } // BAS GAUCHE else if ((page == 0) && (x>= 8 && x<= 236) && (y>= 192 && y<= 266)) { x = 0; y = 0; page = 1; BSP_LCD_Clear(LCD_COLOR_WHITE); page_liste(); commande = 4; HAL_Delay(200); } // BAS DROITE else if ((page == 0) && (x>= 244 && x<= 472) && (y>= 192 && y<= 266)) { x = 0; y = 0; page = 1; BSP_LCD_Clear(LCD_COLOR_WHITE); page_liste(); commande = 5; HAL_Delay(200); } else if (page == 0) { page_commande(); // AFFICHAGE DES PASTILLES DE COULEURS for (int i=0;i<6;i++) { if(c[i] == 0){ BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_FillRect(211+(236*(i%2)), 80+(80*(i/2)), 25, 24); } else if(c[i] == 1){ BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_FillRect(211+(236*(i%2)), 80+(80*(i/2)), 25, 24); } else if(c[i] == 2){ BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_FillRect(211+(236*(i%2)), 80+(80*(i/2)), 25, 24); } } } else if (page == 1) { page_liste(); } else if (page == 2) { page_accueil(); } switch (commande) { case 0: if ( c[0] == 0 ){ BSP_LCD_DrawRect(8, 220, 228, 45); sprintf((char*)text, "CHOISIR LA COMMANDE"); BSP_LCD_DisplayStringAt(52, 242, (uint8_t *)&text, LEFT_MODE); if ( (x>= 8 && x<= 236) && (y>= 220 && y<= 265) ){ x=0; y=0; c[0]= 1 ; HAL_Delay(200); BSP_LCD_Clear(LCD_COLOR_WHITE); } } if ( c[0] == 1 ){ sprintf((char*)text, "COMMANDE EN COURS"); BSP_LCD_DisplayStringAt(52, 242, (uint8_t *)&text, LEFT_MODE); BSP_LCD_DrawRect(244, 220, 228, 45); sprintf((char*)text, "FIN DE COMMANDE"); BSP_LCD_DisplayStringAt(300, 242, (uint8_t *)&text, LEFT_MODE); if ( (x>= 244 && x<= 472) && (y>= 220 && y<= 265) ){ x=0; y=0; c[0]= 2 ; x=475; y=5; HAL_Delay(200); BSP_LCD_Clear(LCD_COLOR_WHITE); } } if ( c[0] == 2 ){ sprintf((char*)text, "COMMANDE TRAITEE"); BSP_LCD_DisplayStringAt(0,260, (uint8_t *)&text, CENTER_MODE); } break; case 1 : if ( c[1] == 0 ){ BSP_LCD_DrawRect(8, 191, 228, 74); sprintf((char*)text, "CHOISIR LA COMMANDE"); BSP_LCD_DisplayStringAt(60, LINE(18), (uint8_t *)&text, LEFT_MODE); if ( (x>= 8 && x<= 236) && (y>= 192 && y<= 266) ){ x=0; y=0; c[1]= 1 ; HAL_Delay(200); } } if ( c[1] == 1 ){ sprintf((char*)text, "COMMANDE EN COURS"); BSP_LCD_DisplayStringAt(80, LINE(9), (uint8_t *)&text, CENTER_MODE); BSP_LCD_DrawRect(244, 200, 228, 65); sprintf((char*)text, "FIN DE COMMANDE"); BSP_LCD_DisplayStringAt(80, LINE(19), (uint8_t *)&text, LEFT_MODE); if ( (x>= 244 && x<= 472) && (y>= 200 && y<= 265) ){ x=0; y=0; c[1]= 2 ; x=475; y=5; HAL_Delay(200); } } if ( c[1] == 2 ){ sprintf((char*)text, "COMMANDE TRAITEE"); BSP_LCD_DisplayStringAt(80, LINE(9), (uint8_t *)&text, CENTER_MODE); } break; case 2 : if ( c[2] == 0 ){ BSP_LCD_DrawRect(8, 191, 228, 74); sprintf((char*)text, "CHOISIR LA COMMANDE"); BSP_LCD_DisplayStringAt(60, LINE(18), (uint8_t *)&text, LEFT_MODE); if ( (x>= 8 && x<= 236) && (y>= 192 && y<= 266) ){ x=0; y=0; c[2]= 1 ; HAL_Delay(200); } } if ( c[2] == 1 ){ sprintf((char*)text, "COMMANDE EN COURS"); BSP_LCD_DisplayStringAt(80, LINE(9), (uint8_t *)&text, CENTER_MODE); BSP_LCD_DrawRect(244, 200, 228, 65); sprintf((char*)text, "FIN DE COMMANDE"); BSP_LCD_DisplayStringAt(80, LINE(19), (uint8_t *)&text, LEFT_MODE); if ( (x>= 244 && x<= 472) && (y>= 200 && y<= 265) ){ x=0; y=0; c[2]= 2 ; x=475; y=5; HAL_Delay(200); } } if ( c[2] == 2 ){ sprintf((char*)text, "COMMANDE TRAITEE"); BSP_LCD_DisplayStringAt(80, LINE(9), (uint8_t *)&text, CENTER_MODE); } break; case 3 : if ( c[3] == 0 ){ BSP_LCD_DrawRect(8, 191, 228, 74); sprintf((char*)text, "CHOISIR LA COMMANDE"); BSP_LCD_DisplayStringAt(60, LINE(18), (uint8_t *)&text, LEFT_MODE); if ( (x>= 8 && x<= 236) && (y>= 192 && y<= 266) ){ x=0; y=0; c[3]= 1 ; HAL_Delay(200); } } if ( c[3] == 1 ){ sprintf((char*)text, "COMMANDE EN COURS"); BSP_LCD_DisplayStringAt(80, LINE(9), (uint8_t *)&text, CENTER_MODE); BSP_LCD_DrawRect(244, 200, 228, 65); sprintf((char*)text, "FIN DE COMMANDE"); BSP_LCD_DisplayStringAt(80, LINE(19), (uint8_t *)&text, LEFT_MODE); if ( (x>= 244 && x<= 472) && (y>= 200 && y<= 265) ){ x=0; y=0; c[3]= 2 ; x=475; y=5; HAL_Delay(200); } } if ( c[3] == 2 ){ sprintf((char*)text, "COMMANDE TRAITEE"); BSP_LCD_DisplayStringAt(80, LINE(9), (uint8_t *)&text, CENTER_MODE); } break; case 4 : if ( c[4] == 0 ){ BSP_LCD_DrawRect(8, 191, 228, 74); sprintf((char*)text, "CHOISIR LA COMMANDE"); BSP_LCD_DisplayStringAt(60, LINE(18), (uint8_t *)&text, LEFT_MODE); if ( (x>= 8 && x<= 236) && (y>= 192 && y<= 266) ){ x=0; y=0; c[4]= 1 ; HAL_Delay(200); } } if ( c[4] == 1 ){ sprintf((char*)text, "COMMANDE EN COURS"); BSP_LCD_DisplayStringAt(80, LINE(9), (uint8_t *)&text, CENTER_MODE); BSP_LCD_DrawRect(244, 200, 228, 65); sprintf((char*)text, "FIN DE COMMANDE"); BSP_LCD_DisplayStringAt(80, LINE(19), (uint8_t *)&text, LEFT_MODE); if ( (x>= 244 && x<= 472) && (y>= 200 && y<= 265) ){ x=0; y=0; c[4]= 2 ; x=475; y=5; HAL_Delay(200); } } if ( c[4] == 2 ){ sprintf((char*)text, "COMMANDE TRAITEE"); BSP_LCD_DisplayStringAt(80, LINE(9), (uint8_t *)&text, CENTER_MODE); } break; case 5 : if ( c[5] == 0 ){ BSP_LCD_DrawRect(8, 191, 228, 74); sprintf((char*)text, "CHOISIR LA COMMANDE"); BSP_LCD_DisplayStringAt(60, LINE(18), (uint8_t *)&text, LEFT_MODE); if ( (x>= 8 && x<= 236) && (y>= 192 && y<= 266) ){ x=0; y=0; c[5]= 1 ; HAL_Delay(200); } } if ( c[5] == 1 ){ sprintf((char*)text, "COMMANDE EN COURS"); BSP_LCD_DisplayStringAt(80, LINE(9), (uint8_t *)&text, CENTER_MODE); BSP_LCD_DrawRect(244, 200, 228, 65); sprintf((char*)text, "FIN DE COMMANDE"); BSP_LCD_DisplayStringAt(80, LINE(19), (uint8_t *)&text, LEFT_MODE); if ( (x>= 244 && x<= 472) && (y>= 200 && y<= 265) ){ x=0; y=0; c[5]= 2 ; x=475; y=5; HAL_Delay(200); } } if ( c[5] == 2 ){ sprintf((char*)text, "COMMANDE TRAITEE"); BSP_LCD_DisplayStringAt(80, LINE(9), (uint8_t *)&text, CENTER_MODE); } break; case 6 : break; default: break; } } } ////////////////////////////////////// ////////////PAGE COMMANDE///////////// ////////////////////////////////////// void page_commande (){ page = 0; BSP_LCD_SetTextColor(LCD_COLOR_BLACK); drawImage_LogoParisSaclay(0,0); sprintf((char*)text, "Page commandes"); BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, CENTER_MODE); BSP_LCD_DrawHLine(0,22,480); drawImage_fleche(447,0); // LES COMMANDES // Au dessus 22px de la barre + 7// /* 8px */ BSP_LCD_DrawRect(8, 29, 228, 74); /* 8px */ BSP_LCD_DrawRect(244, 29, 228, 74); /* 8px */ /* 7px */ /* 8px */ BSP_LCD_DrawRect(8, 110, 228, 74); /* 8px */ BSP_LCD_DrawRect(244, 110, 228, 74); /* 8px */ /* 7px */ /* 8px */ BSP_LCD_DrawRect(8, 191, 228, 73); /* 8px */ BSP_LCD_DrawRect(244, 191, 228, 73); /* 8px */ // Au dessous 7px// //SEGMENTATION DES CASES COMMANDES BSP_LCD_DrawHLine(8,80,228); BSP_LCD_DrawHLine(244,80,228); BSP_LCD_DrawHLine(8,160,228); BSP_LCD_DrawHLine(244,159,228); BSP_LCD_DrawHLine(8,240,228); BSP_LCD_DrawHLine(244,240,228); sprintf((char*)text, "Commande #0001"); BSP_LCD_DisplayStringAt(20,87, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "Commande #0002"); BSP_LCD_DisplayStringAt(257, 87, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "Commande #0003"); BSP_LCD_DisplayStringAt(20, 167, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "Commande #0004"); BSP_LCD_DisplayStringAt(257, 167, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "Commande #0005"); BSP_LCD_DisplayStringAt(20, 247, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "Commande #0006"); BSP_LCD_DisplayStringAt(257, 247, (uint8_t *)&text, LEFT_MODE); // CONTENU COMMANDE //1 sprintf((char*)text, "1 THEATRE(S)"); BSP_LCD_DisplayStringAt(20, 40, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "2 POESIE(S)"); BSP_LCD_DisplayStringAt(20, 60, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "1 ROMAN(S)"); BSP_LCD_DisplayStringAt(140, 40, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "2 BD"); BSP_LCD_DisplayStringAt(140, 60, (uint8_t *)&text, LEFT_MODE); //2 sprintf((char*)text, "3 THEATRE(S)"); BSP_LCD_DisplayStringAt(257, 40, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "0 POESIE(S)"); BSP_LCD_DisplayStringAt(257, 60, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "1 ROMAN(S)"); BSP_LCD_DisplayStringAt(377, 40, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "0 BD"); BSP_LCD_DisplayStringAt(377, 60, (uint8_t *)&text, LEFT_MODE); //3 sprintf((char*)text, "0 THEATRE(S)"); BSP_LCD_DisplayStringAt(20, 120, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "0 POESIE(S)"); BSP_LCD_DisplayStringAt(20, 140, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "3 ROMAN(S)"); BSP_LCD_DisplayStringAt(140, 120, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "2 BD"); BSP_LCD_DisplayStringAt(140, 140, (uint8_t *)&text, LEFT_MODE); //4 sprintf((char*)text, "1 THEATRE(S)"); BSP_LCD_DisplayStringAt(257, 120, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "1 POESIE(S)"); BSP_LCD_DisplayStringAt(257, 140, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "1 ROMAN(S)"); BSP_LCD_DisplayStringAt(377, 120, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "1 BD"); BSP_LCD_DisplayStringAt(377, 140, (uint8_t *)&text, LEFT_MODE); //5 sprintf((char*)text, "0 THEATRE(S)"); BSP_LCD_DisplayStringAt(20, 200, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "3 POESIE(S)"); BSP_LCD_DisplayStringAt(20, 220, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "1 ROMAN(S)"); BSP_LCD_DisplayStringAt(140, 200, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "2 BD"); BSP_LCD_DisplayStringAt(140, 220, (uint8_t *)&text, LEFT_MODE); //6 sprintf((char*)text, "1 THEATRE(S)"); BSP_LCD_DisplayStringAt(257, 200, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "1 POESIE(S)"); BSP_LCD_DisplayStringAt(257, 220, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "2 ROMAN(S)"); BSP_LCD_DisplayStringAt(377, 200, (uint8_t *)&text, LEFT_MODE); sprintf((char*)text, "1 BD"); BSP_LCD_DisplayStringAt(377, 220, (uint8_t *)&text, LEFT_MODE); } /////////////////////////////////////////////////////////////////////////// //////////////////////////////////// //////////PAGE LISTE//////////////// //////////////////////////////////// void page_liste(){ page = 1; drawImage_LogoParisSaclay(0,0); drawImage_fleche(447,0); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_DrawHLine(0,22,480); sprintf((char*)text, "Page liste"); BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, CENTER_MODE); } /////////////////////////////////////////////////////////////////////////// //////////////////////////////////// ///////////PAGE ACCUEIL///////////// //////////////////////////////////// void page_accueil(){ page = 2; BSP_LCD_SetTextColor(LCD_COLOR_BLACK); drawImage_LogoParisSaclay(0,0); drawImage_BT(268,60); drawImage_market(70,57); sprintf((char*)text, "Page d'accueil"); BSP_LCD_DisplayStringAt(0, LINE(2), (uint8_t *)&text, CENTER_MODE); BSP_LCD_DrawRect(65, 55, 150, 175); //Bouton commande BSP_LCD_DrawHLine(65,210,150); sprintf((char*)text, "PAGE COMMANDE"); BSP_LCD_DisplayStringAt(95, LINE(18), (uint8_t *)&text, LEFT_MODE); BSP_LCD_DrawRect(265, 55, 150, 175); //Bouton BT BSP_LCD_DrawHLine(265,210,150); BSP_LCD_SetTextColor(LCD_COLOR_BLUE); sprintf((char*)text, "BLUETOOTH"); BSP_LCD_DisplayStringAt(102, LINE(18), (uint8_t *)&text, CENTER_MODE); } ///////////////////////////////////////////////////////////////////////////