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

Committer:
Rhamao
Date:
Wed Jun 17 14:05:32 2020 +0000
Revision:
5:c4038609e806
Parent:
4:b4c30f6f526e
Changement de l'interface

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 5:c4038609e806 16 Button::Button(int x, int y, int width, int height, uint32_t bgColor, uint32_t borderColor,uint32_t borderWidth)
Rhamao 5:c4038609e806 17 : m_x(x), m_y(y), m_width(width), m_height(height), m_bgColor(bgColor), m_borderColor(borderColor),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 4:b4c30f6f526e 43 BSP_LCD_DrawPixel(x, y, m_bgColor);
Rhamao 0:eccd33c01946 44 y++;
Rhamao 0:eccd33c01946 45 }
Rhamao 0:eccd33c01946 46 x++;
Rhamao 0:eccd33c01946 47 }
Rhamao 0:eccd33c01946 48 BSP_LCD_SetTextColor(m_textColor);
Rhamao 0:eccd33c01946 49 BSP_LCD_SetBackColor(m_bgColor);
Rhamao 0:eccd33c01946 50 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 51
Rhamao 0:eccd33c01946 52 }
Rhamao 0:eccd33c01946 53
Rhamao 0:eccd33c01946 54
Rhamao 0:eccd33c01946 55 void Button::setText(const char *str, uint32_t textColor){
Rhamao 0:eccd33c01946 56 m_textColor = textColor;
Rhamao 0:eccd33c01946 57 sprintf((char*)m_text, str);
Rhamao 0:eccd33c01946 58
Rhamao 0:eccd33c01946 59 }
Rhamao 1:3ce68d55dfb8 60
Rhamao 1:3ce68d55dfb8 61 uint8_t* Button::getText(){
Rhamao 1:3ce68d55dfb8 62 return m_text;
Rhamao 1:3ce68d55dfb8 63 }
Rhamao 2:fd11fb4d51f8 64
Rhamao 2:fd11fb4d51f8 65 void Button::setBackgroundColor(uint32_t color){
Rhamao 2:fd11fb4d51f8 66 m_bgColor = color;
Rhamao 4:b4c30f6f526e 67 }
Rhamao 4:b4c30f6f526e 68
Rhamao 4:b4c30f6f526e 69 void Button::setBorderWidth(uint32_t borderWidth){
Rhamao 4:b4c30f6f526e 70 m_borderWidth = borderWidth;
Rhamao 2:fd11fb4d51f8 71 }