Stephane Marques / Mbed OS DISCO-F746NG_LCDTS_demo

Dependencies:   BSP_DISCO_F746NG

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "button.h"
00003 #include "view.h"
00004 #include "stm32746g_discovery_lcd.h"
00005 #include "stm32746g_discovery_ts.h"
00006 #include <list>
00007 #define SCREENWIDTH 480
00008 #define SCREENHEIGHT 272
00009 
00010 uint8_t text[30];
00011 AnalogIn capteur (A0);
00012 
00013 void setBackgroundColor(uint32_t color)
00014 {
00015     BSP_LCD_Clear(color);
00016 }
00017 
00018 void setHalfColor(uint32_t color0, uint32_t color1)
00019 {
00020     BSP_LCD_Clear(color0);
00021 
00022     int x = SCREENWIDTH>>1;
00023     while (x < SCREENWIDTH) {
00024         int y = 0;
00025         while (y < SCREENHEIGHT) {
00026             BSP_LCD_DrawPixel(x, y, color1);
00027             y++;
00028         }
00029         x++;
00030     }
00031 }
00032 
00033 void updateButton()
00034 {
00035 
00036 
00037 }
00038 void drawButton(uint32_t color0, int posX, int posY, int width, int height)
00039 {
00040 }
00041 
00042 
00043 
00044 int main()
00045 {
00046     TS_StateTypeDef TS_State;
00047     uint16_t x, y;
00048     uint8_t status;
00049     uint8_t idx;
00050     uint8_t cleared = 0;
00051     uint8_t prev_nb_touches = 0;
00052     int etat = 0;
00053     int i = 0;
00054 
00055     BSP_LCD_Init();
00056     BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS);
00057     BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
00058 
00059     status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
00060     if (status != TS_OK) {
00061         BSP_LCD_Clear(LCD_COLOR_RED);
00062         BSP_LCD_SetBackColor(LCD_COLOR_RED);
00063         BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
00064         BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE);
00065         while (1);
00066     } else {
00067         BSP_LCD_Clear(LCD_COLOR_GREEN);
00068         BSP_LCD_SetBackColor(LCD_COLOR_GREEN);
00069         BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
00070         BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE);
00071     }
00072 
00073     HAL_Delay(100);
00074     BSP_LCD_SetFont(&Font12);
00075     BSP_LCD_SetBackColor(LCD_COLOR_LIGHTCYAN);
00076     BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
00077     View v;
00078     v.i=&i;
00079 
00080     Timer timer;
00081     timer.start();
00082 
00083     while(1) {
00084         v.drawImage(0, 0);
00085         float valeur = capteur.read();
00086         BSP_LCD_SetFont(&Font24);
00087         //sprintf((char*)text, "valeur: %5.3f", valeur);
00088         //BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)&text, LEFT_MODE);
00089 
00090       
00091         sprintf((char*)text, "Nombre de personne: %d", i);
00092         BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)&text, LEFT_MODE);
00093 
00094 
00095         //sprintf((char*)text, "etat: %d", etat);
00096         //BSP_LCD_DisplayStringAt(0, LINE(2), (uint8_t *)&text, LEFT_MODE);
00097         switch (etat) {
00098             case 0 :
00099                 // il n'y a personne
00100                 if (valeur > 0.68) {
00101                     etat = 1;
00102                     i++;
00103                     timer.reset();
00104                 }
00105                 break;
00106             case 1:
00107                 if (timer.read()>1) {
00108                     etat=2;
00109                 }
00110                 break;
00111             case 2 :
00112                 // il y a quelqu'un
00113                 if (valeur <0.4) {
00114                     // la personne est passée : il faut incrémenter
00115                     etat = 0;
00116                     timer.reset();
00117                 }
00118                 break;
00119 
00120             default :
00121                 // ce cas ne devrait jamais se produire
00122                 etat = 0;
00123         } // fin du switch
00124 
00125 
00126 
00127 
00128         BSP_TS_GetState(&TS_State);
00129         if (TS_State.touchDetected) {
00130             cleared = 0;
00131             /*sprintf((char*)text, "Touches: %d", TS_State.touchDetected);
00132             BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
00133             */for (idx = 0; idx < TS_State.touchDetected; idx++) {
00134                 x = TS_State.touchX[idx];
00135                 y = TS_State.touchY[idx];
00136                 v.contain(x, y);
00137             }
00138 
00139 
00140         } else {
00141             if (!cleared) {
00142                 v.draw();
00143                 /*sprintf((char*)text, "Touches: 0");
00144                 BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
00145                 */cleared = 1;
00146             }
00147         }
00148     }
00149 }