
Code sensor IR
Dependencies: BSP_DISCO_F746NG
button.cpp@0:8c1b74ecac29, 2020-06-25 (annotated)
- Committer:
- stephane_m
- Date:
- Thu Jun 25 16:51:20 2020 +0000
- Revision:
- 0:8c1b74ecac29
Code capteur IR
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stephane_m | 0:8c1b74ecac29 | 1 | #include "button.h" |
stephane_m | 0:8c1b74ecac29 | 2 | #include "mbed.h" |
stephane_m | 0:8c1b74ecac29 | 3 | |
stephane_m | 0:8c1b74ecac29 | 4 | #include "stm32746g_discovery_lcd.h" |
stephane_m | 0:8c1b74ecac29 | 5 | |
stephane_m | 0:8c1b74ecac29 | 6 | int Button::strlen(uint8_t *str) |
stephane_m | 0:8c1b74ecac29 | 7 | { |
stephane_m | 0:8c1b74ecac29 | 8 | int i = 0; |
stephane_m | 0:8c1b74ecac29 | 9 | while(str[i]) |
stephane_m | 0:8c1b74ecac29 | 10 | { |
stephane_m | 0:8c1b74ecac29 | 11 | i++; |
stephane_m | 0:8c1b74ecac29 | 12 | } |
stephane_m | 0:8c1b74ecac29 | 13 | return i; |
stephane_m | 0:8c1b74ecac29 | 14 | } |
stephane_m | 0:8c1b74ecac29 | 15 | |
stephane_m | 0:8c1b74ecac29 | 16 | |
stephane_m | 0:8c1b74ecac29 | 17 | Button::Button(int x, int y, int width, int height, uint32_t bgColor, uint32_t borderWidth) |
stephane_m | 0:8c1b74ecac29 | 18 | : m_x(x), m_y(y), m_width(width), m_height(height), m_bgColor(bgColor), m_borderWidth(borderWidth) |
stephane_m | 0:8c1b74ecac29 | 19 | { |
stephane_m | 0:8c1b74ecac29 | 20 | |
stephane_m | 0:8c1b74ecac29 | 21 | } |
stephane_m | 0:8c1b74ecac29 | 22 | |
stephane_m | 0:8c1b74ecac29 | 23 | bool Button::contain(int x, int y) |
stephane_m | 0:8c1b74ecac29 | 24 | { |
stephane_m | 0:8c1b74ecac29 | 25 | m_etat = (x > m_x && x < m_x + m_width && y > m_y && y < m_y + m_height); |
stephane_m | 0:8c1b74ecac29 | 26 | return m_etat; |
stephane_m | 0:8c1b74ecac29 | 27 | } |
stephane_m | 0:8c1b74ecac29 | 28 | |
stephane_m | 0:8c1b74ecac29 | 29 | void Button::draw() |
stephane_m | 0:8c1b74ecac29 | 30 | { |
stephane_m | 0:8c1b74ecac29 | 31 | int x = m_x; |
stephane_m | 0:8c1b74ecac29 | 32 | while (x < m_x + m_width) { |
stephane_m | 0:8c1b74ecac29 | 33 | int y = m_y; |
stephane_m | 0:8c1b74ecac29 | 34 | while (y < m_y + m_height) { |
stephane_m | 0:8c1b74ecac29 | 35 | if (y - m_y < m_borderWidth) |
stephane_m | 0:8c1b74ecac29 | 36 | BSP_LCD_DrawPixel(x, y, m_borderColor); |
stephane_m | 0:8c1b74ecac29 | 37 | else if ( (m_y + m_height) - y <= m_borderWidth) |
stephane_m | 0:8c1b74ecac29 | 38 | BSP_LCD_DrawPixel(x, y, m_borderColor); |
stephane_m | 0:8c1b74ecac29 | 39 | else if (x - m_x < m_borderWidth) |
stephane_m | 0:8c1b74ecac29 | 40 | BSP_LCD_DrawPixel(x, y, m_borderColor); |
stephane_m | 0:8c1b74ecac29 | 41 | else if ( (m_x + m_width) - x <= m_borderWidth) |
stephane_m | 0:8c1b74ecac29 | 42 | BSP_LCD_DrawPixel(x, y, m_borderColor); |
stephane_m | 0:8c1b74ecac29 | 43 | else |
stephane_m | 0:8c1b74ecac29 | 44 | BSP_LCD_DrawPixel(x, y, m_bgColor); |
stephane_m | 0:8c1b74ecac29 | 45 | |
stephane_m | 0:8c1b74ecac29 | 46 | y++; |
stephane_m | 0:8c1b74ecac29 | 47 | } |
stephane_m | 0:8c1b74ecac29 | 48 | x++; |
stephane_m | 0:8c1b74ecac29 | 49 | } |
stephane_m | 0:8c1b74ecac29 | 50 | BSP_LCD_SetTextColor(m_textColor); |
stephane_m | 0:8c1b74ecac29 | 51 | BSP_LCD_SetBackColor(m_bgColor); |
stephane_m | 0:8c1b74ecac29 | 52 | 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); |
stephane_m | 0:8c1b74ecac29 | 53 | |
stephane_m | 0:8c1b74ecac29 | 54 | } |
stephane_m | 0:8c1b74ecac29 | 55 | |
stephane_m | 0:8c1b74ecac29 | 56 | void Button::setText(const char *str, uint32_t textColor){ |
stephane_m | 0:8c1b74ecac29 | 57 | m_textColor = textColor; |
stephane_m | 0:8c1b74ecac29 | 58 | sprintf((char*)m_text, str); |
stephane_m | 0:8c1b74ecac29 | 59 | |
stephane_m | 0:8c1b74ecac29 | 60 | } |