Class virtual button for lcd and ts

Files at this revision

API Documentation at this revision

Comitter:
jlpadiolleau
Date:
Sat Dec 02 11:47:56 2017 +0000
Commit message:
Correction du TP4 d'info1

Changed in this revision

buttons.cpp Show annotated file Show diff for this revision Revisions of this file
buttons.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 055a9eb7d5eb buttons.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/buttons.cpp	Sat Dec 02 11:47:56 2017 +0000
@@ -0,0 +1,54 @@
+#include "buttons.h"
+
+button::button(uint16_t x, uint16_t y, uint16_t w, uint16_t h,uint32_t colorOn,uint32_t colorOff)
+{
+     
+     m_colorOn=colorOn;
+     m_colorOff=colorOff;
+     m_x=x;
+     m_y=y;
+     m_w=w;
+     m_h=h;
+     m_state=false;
+     m_memoState=false;
+     draw();
+     BSP_TS_Init(480,272);
+     m_touchRead.attach(this,&button::readState,0.2);
+     
+}
+
+/* Changement d'état du bouton */
+void button::draw(void)
+{
+     uint32_t oldColor;
+     oldColor=BSP_LCD_GetTextColor();
+     if (m_state==true) BSP_LCD_SetTextColor(m_colorOn);
+     else BSP_LCD_SetTextColor(m_colorOff);
+     BSP_LCD_FillRect(m_x,m_y,m_w,m_h);
+     BSP_LCD_SetTextColor(oldColor);
+    
+}
+
+/* Lecture touche dans la zone du bouton */
+void button::readState(void)
+{
+    uint16_t Xpos,Ypos;
+    TS_StateTypeDef tsState; // Déclaration d'une structure liée au TouchScreen
+    BSP_TS_GetState(&tsState);
+    if (tsState.touchDetected)
+    {
+        Xpos=tsState.touchX[0]; // Lecture de la position
+        Ypos=tsState.touchY[0];
+        if(( Xpos > m_x) && (Xpos < m_x+m_w) && (Ypos > m_y) && (Ypos < m_y+m_h)) m_state=true;
+        else m_state=false;
+        
+    }
+    else m_state=false;
+    if (m_state!=m_memoState)
+    {
+        draw();
+        m_memoState=m_state;
+    }
+    
+}
+void button::readState(void){}
\ No newline at end of file
diff -r 000000000000 -r 055a9eb7d5eb buttons.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/buttons.h	Sat Dec 02 11:47:56 2017 +0000
@@ -0,0 +1,36 @@
+#ifndef __BUTTONS_H
+#define __BUTTONS_H
+
+#ifdef TARGET_DISCO_F746NG
+
+#include "mbed.h"
+#include "stm32746g_discovery_lcd.h"
+#include "stm32746g_discovery_ts.h"
+
+class button
+{
+    public:
+    button(uint16_t x, uint16_t y, uint16_t w, uint16_t h,uint32_t colorOn,uint32_t colorOff); // Constructor
+    void draw(void);
+    bool read(void) {return m_state;}
+    bool getState(void);
+    operator bool(void) {return m_state;}
+    
+    private:
+    bool m_state;
+    bool m_memoState;
+    uint16_t m_x; // position x
+    uint16_t m_y; // position y
+    uint16_t m_w; // largeur
+    uint16_t m_h; // hauteur
+    uint32_t m_colorOn; // couleur On
+    uint32_t m_colorOff; // couleur Off
+    void readState(void);
+    Ticker m_touchRead;
+};
+
+#else
+#error "This class must be used with DISCO_F746NG board only."
+#endif //TARGET_DISCO_F746NG
+
+#endif
\ No newline at end of file