Interfaçage NeoPixel Ring 12, LPRO MECSE, Arnaud A.

Committer:
Rhamao
Date:
Mon Jun 15 02:01:15 2020 +0000
Revision:
2:fd11fb4d51f8
Parent:
1:3ce68d55dfb8
Child:
4:b4c30f6f526e
boutons +/- et boutons leds fonctionnels

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhamao 0:eccd33c01946 1 #include "button.h"
Rhamao 0:eccd33c01946 2 #include "mbed.h"
Rhamao 0:eccd33c01946 3 #include "stm32746g_discovery_lcd.h"
Rhamao 0:eccd33c01946 4
Rhamao 0:eccd33c01946 5 int Button::strlen(uint8_t *str)
Rhamao 0:eccd33c01946 6 {
Rhamao 0:eccd33c01946 7 int i = 0;
Rhamao 0:eccd33c01946 8 while(str[i])
Rhamao 0:eccd33c01946 9 {
Rhamao 0:eccd33c01946 10 i++;
Rhamao 0:eccd33c01946 11 }
Rhamao 0:eccd33c01946 12 return i;
Rhamao 0:eccd33c01946 13 }
Rhamao 0:eccd33c01946 14
Rhamao 0:eccd33c01946 15
Rhamao 0:eccd33c01946 16 Button::Button(int x, int y, int width, int height, uint32_t bgColor, uint32_t borderWidth)
Rhamao 0:eccd33c01946 17 : m_x(x), m_y(y), m_width(width), m_height(height), m_bgColor(bgColor), m_borderWidth(borderWidth)
Rhamao 0:eccd33c01946 18 {
Rhamao 0:eccd33c01946 19
Rhamao 0:eccd33c01946 20 }
Rhamao 0:eccd33c01946 21
Rhamao 0:eccd33c01946 22 bool Button::contain(int x, int y)
Rhamao 0:eccd33c01946 23 {
Rhamao 0:eccd33c01946 24 m_etat = (x > m_x && x < m_x + m_width && y > m_y && y < m_y + m_height);
Rhamao 0:eccd33c01946 25 return m_etat;
Rhamao 0:eccd33c01946 26 }
Rhamao 0:eccd33c01946 27
Rhamao 0:eccd33c01946 28 void Button::draw()
Rhamao 0:eccd33c01946 29 {
Rhamao 0:eccd33c01946 30 int x = m_x;
Rhamao 0:eccd33c01946 31 while (x < m_x + m_width) {
Rhamao 0:eccd33c01946 32 int y = m_y;
Rhamao 0:eccd33c01946 33 while (y < m_y + m_height) {
Rhamao 0:eccd33c01946 34 if (y - m_y < m_borderWidth)
Rhamao 0:eccd33c01946 35 BSP_LCD_DrawPixel(x, y, m_borderColor);
Rhamao 0:eccd33c01946 36 else if ( (m_y + m_height) - y <= m_borderWidth)
Rhamao 0:eccd33c01946 37 BSP_LCD_DrawPixel(x, y, m_borderColor);
Rhamao 0:eccd33c01946 38 else if (x - m_x < m_borderWidth)
Rhamao 0:eccd33c01946 39 BSP_LCD_DrawPixel(x, y, m_borderColor);
Rhamao 0:eccd33c01946 40 else if ( (m_x + m_width) - x <= m_borderWidth)
Rhamao 0:eccd33c01946 41 BSP_LCD_DrawPixel(x, y, m_borderColor);
Rhamao 0:eccd33c01946 42 else
Rhamao 0:eccd33c01946 43 BSP_LCD_DrawPixel(x, y, m_bgColor);
Rhamao 0:eccd33c01946 44
Rhamao 0:eccd33c01946 45 y++;
Rhamao 0:eccd33c01946 46 }
Rhamao 0:eccd33c01946 47 x++;
Rhamao 0:eccd33c01946 48 }
Rhamao 0:eccd33c01946 49 BSP_LCD_SetTextColor(m_textColor);
Rhamao 0:eccd33c01946 50 BSP_LCD_SetBackColor(m_bgColor);
Rhamao 0:eccd33c01946 51 BSP_LCD_DisplayStringAt((m_x + m_width/2)- 8*(strlen(m_text)/2), (m_y + m_height/2) - 5, (uint8_t *)&m_text, LEFT_MODE);
Rhamao 0:eccd33c01946 52
Rhamao 0:eccd33c01946 53 }
Rhamao 0:eccd33c01946 54
Rhamao 0:eccd33c01946 55
Rhamao 0:eccd33c01946 56 void Button::setText(const char *str, uint32_t textColor){
Rhamao 0:eccd33c01946 57 m_textColor = textColor;
Rhamao 0:eccd33c01946 58 sprintf((char*)m_text, str);
Rhamao 0:eccd33c01946 59
Rhamao 0:eccd33c01946 60 }
Rhamao 1:3ce68d55dfb8 61
Rhamao 1:3ce68d55dfb8 62 uint8_t* Button::getText(){
Rhamao 1:3ce68d55dfb8 63 return m_text;
Rhamao 1:3ce68d55dfb8 64 }
Rhamao 2:fd11fb4d51f8 65
Rhamao 2:fd11fb4d51f8 66 void Button::setBackgroundColor(uint32_t color){
Rhamao 2:fd11fb4d51f8 67 m_bgColor = color;
Rhamao 2:fd11fb4d51f8 68 }