Une horloge à afficheurs 7 segments

Dependencies:   BSP_DISCO_F746NG

Committer:
sol427
Date:
Mon Jun 22 16:33:43 2020 +0000
Revision:
4:06a5a25319d5
Horloge fonctionnelle

Who changed what in which revision?

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