Interfaçage NeoPixel Ring 12, LPRO MECSE, Arnaud A.
Revision 7:ca859a221807, committed 2020-06-17
- Comitter:
- Rhamao
- Date:
- Wed Jun 17 16:33:20 2020 +0000
- Parent:
- 6:03acf74857cc
- Commit message:
- View 1 finie
Changed in this revision
button.h | Show annotated file Show diff for this revision Revisions of this file |
view.cpp | Show diff for this revision Revisions of this file |
view.h | Show diff for this revision Revisions of this file |
--- a/button.h Wed Jun 17 14:16:14 2020 +0000 +++ b/button.h Wed Jun 17 16:33:20 2020 +0000 @@ -1,6 +1,7 @@ #ifndef BUTTON_H #define BUTTON_H #include "stm32746g_discovery_lcd.h" + class Button {
--- a/view.cpp Wed Jun 17 14:16:14 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,448 +0,0 @@ -#include "view.h" -#include "stm32746g_discovery_lcd.h" -#include "mbed.h" -#include "button.h" -#include <list> -#include <string.h> - -RawSerial pc(USBTX, USBRX, 115200); -RawSerial wifi(D1, D0, 115200); - - -uint8_t donnee[100]; -uint8_t donneecpy[100]; -uint8_t donneeIp[100]; -uint8_t valReaded = 0; -uint8_t dataReaded = 0; -uint8_t ipOk = 0; -uint8_t isInit = 0; - -int ft_strlen(const uint8_t* str) -{ - int i = 0; - - while (str[i] != '\0' || str[i] != '\r' || str[i] != '\n') - { - i++; - - } - return i; - -} - -View::View(int width, int height) - : m_width(width), m_height(height) -{ - initLCD(); - led0->setBackgroundColor((uint32_t)0xFF010101); - m_bgColor = LCD_COLOR_BLACK; - //LEDS - led0->setText(""); - led1->setText(""); - led2->setText(""); - led3->setText(""); - led4->setText(""); - led5->setText(""); - led6->setText(""); - led7->setText(""); - led8->setText(""); - led9->setText(""); - led10->setText(""); - led11->setText(""); - //RGB TextView - redTextview->setText("000"); - greenTextview->setText("000"); - blueTextview->setText("000"); - //RGB + and - - plusRED->setText("+1"); - minusRED->setText("-1"); - plusGREEN->setText("+1"); - minusGREEN->setText("-1"); - plusBLUE->setText("+1"); - minusBLUE->setText("-1"); - plus10RED->setText("+10"); - minus10RED->setText("-10"); - plus10GREEN->setText("+10"); - minus10GREEN->setText("-10"); - plus10BLUE->setText("+10"); - minus10BLUE->setText("-10"); - //SET NEW COLOR - setNewColor->setText("SET NEW COLOR"); - cancel->setText("CANCEL"); - //Animations - /*anim1->setText("Animations1"); - anim2->setText("Animations2"); - anim3->setText("Animations3"); - start->setText("Start animation"); - stop->setText("Stop animation");*/ - //LEDS buttons - m_buttonList.push_front(led0); - m_buttonList.push_front(led1); - m_buttonList.push_front(led2); - m_buttonList.push_front(led3); - m_buttonList.push_front(led4); - m_buttonList.push_front(led5); - m_buttonList.push_front(led6); - m_buttonList.push_front(led7); - m_buttonList.push_front(led8); - m_buttonList.push_front(led9); - m_buttonList.push_front(led10); - m_buttonList.push_front(led11); - //RGB TextView - m_buttonList.push_front(redTextview); - m_buttonList.push_front(greenTextview); - m_buttonList.push_front(blueTextview); - //RGB + and - - m_buttonList.push_front(plusRED); - m_buttonList.push_front(minusRED); - m_buttonList.push_front(plusGREEN); - m_buttonList.push_front(minusGREEN); - m_buttonList.push_front(plusBLUE); - m_buttonList.push_front(minusBLUE); - m_buttonList.push_front(plus10RED); - m_buttonList.push_front(minus10RED); - m_buttonList.push_front(plus10GREEN); - m_buttonList.push_front(minus10GREEN); - m_buttonList.push_front(plus10BLUE); - m_buttonList.push_front(minus10BLUE); - //SET NEW COLOR - m_buttonList.push_front(setNewColor); - m_buttonList.push_front(cancel); - //Animations - /*m_buttonList.push_front(anim1); - m_buttonList.push_front(anim2); - m_buttonList.push_front(anim3); - m_buttonList.push_front(start); - m_buttonList.push_front(stop);*/ -} - -View::~View() //Destructeur de bouton -{ - for (Button * button : m_buttonList) { - delete button; - } - m_buttonList.clear(); -} - - -void View::contain(int x, int y) -{ - if(!screenReleased){ - screenReleased=true; - for (Button * button : m_buttonList) { - if (button->contain(x,y)) { - updatePlusMinus(button); - updateLEDS(button); - updateSetNewColorAndCancel(button); - } - } - } -} - - -void View::draw() -{ - BSP_LCD_Clear(m_bgColor); //Enlève l'affichage du début - for (Button * button : m_buttonList) { - button->draw(); - } - drawText(); -} - - -void View::initLCD(){ - uint8_t status; - - BSP_LCD_Init(); //Initialise le LCD - BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); - BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); - - status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); - if (status != TS_OK) { - BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE); - while (1); - } else { - BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE); - } - - HAL_Delay(100); - BSP_LCD_SetFont(&Font12); -} - -void View::drawText(){ - //(uint32_t)0xFFFFFFFF - BSP_LCD_SetTextColor(LCD_COLOR_RED); - BSP_LCD_SetBackColor(LCD_COLOR_BLACK); - BSP_LCD_DisplayStringAt(120+2,38+2,(uint8_t *)"Red", LEFT_MODE); - BSP_LCD_SetTextColor(LCD_COLOR_GREEN); - BSP_LCD_DisplayStringAt(120+2,128+2,(uint8_t *)"Green", LEFT_MODE); - BSP_LCD_SetTextColor(LCD_COLOR_BLUE); - BSP_LCD_DisplayStringAt(120+2,218+2,(uint8_t *)"Blue", LEFT_MODE); -} - -void View::updateLCD(){ - BSP_TS_GetState(&TS_State); - if (TS_State.touchDetected) { //Detecte si l'écran tactile est touché - cleared = false; - for (idx = 0; idx < TS_State.touchDetected; idx++) { - x = TS_State.touchX[idx]; - y = TS_State.touchY[idx]; - contain(x, y); - - } - } else { - screenReleased=false; - if (!cleared) { - draw(); - cleared = true; - - } - } - -} - -bool View::updatePlusMinus(Button* button){ - if(button == plusRED){ - RGB[0]= std::atoi((const char*)redTextview->getText()); - RGB[0]++; - sprintf(str, "%d", RGB[0]); - redTextview->setText(str); - } else if(button == minusRED){ - RGB[0]= std::atoi((const char*)redTextview->getText()); - RGB[0]--; - sprintf(str, "%d", RGB[0]); - redTextview->setText(str); - } else if(button == plus10RED){ - RGB[0]= std::atoi((const char*)redTextview->getText()); - RGB[0]+=10; - sprintf(str, "%d", RGB[0]); - redTextview->setText(str); - } else if(button == minus10RED){ - RGB[0]= std::atoi((const char*)redTextview->getText()); - RGB[0]-=10; - sprintf(str, "%d", RGB[0]); - redTextview->setText(str); - } else if(button == plusGREEN){ - RGB[1]= std::atoi((const char*)greenTextview->getText()); - RGB[1]++; - sprintf(str, "%d", RGB[1]); - greenTextview->setText(str); - } else if(button == minusGREEN){ - RGB[1]= std::atoi((const char*)greenTextview->getText()); - RGB[1]--; - sprintf(str, "%d", RGB[1]); - greenTextview->setText(str); - } else if(button == plus10GREEN){ - RGB[1]= std::atoi((const char*)greenTextview->getText()); - RGB[1]+=10; - sprintf(str, "%d", RGB[1]); - greenTextview->setText(str); - } else if(button == minus10GREEN){ - RGB[1]= std::atoi((const char*)greenTextview->getText()); - RGB[1]-=10; - sprintf(str, "%d", RGB[1]); - greenTextview->setText(str); - }else if(button == plusBLUE){ - RGB[2]= std::atoi((const char*)blueTextview->getText()); - RGB[2]++; - sprintf(str, "%d", RGB[2]); - blueTextview->setText(str); - } else if(button == minusBLUE){ - RGB[2]= std::atoi((const char*)blueTextview->getText()); - RGB[2]--; - sprintf(str, "%d", RGB[2]); - blueTextview->setText(str); - } else if(button == plus10BLUE){ - RGB[2]= std::atoi((const char*)blueTextview->getText()); - RGB[2]+=10; - sprintf(str, "%d", RGB[2]); - blueTextview->setText(str); - } else if(button == minus10BLUE){ - RGB[2]= std::atoi((const char*)blueTextview->getText()); - RGB[2]-=10; - sprintf(str, "%d", RGB[2]); - blueTextview->setText(str); - } else - return false; - - return true; -} - -bool View::updateLEDS(Button* button){ - if(button == led0) - if(!ledSelected[0]){ - ledSelected[0]=true; - button->setBorderWidth(3); - } - else{ - ledSelected[0]=false; - button->setBorderWidth(1); - } - else if(button == led1) - if(!ledSelected[1]){ - ledSelected[1]=true; - button->setBorderWidth(3); - } - else{ - ledSelected[1]=false; - button->setBorderWidth(1); - } - else if(button == led2) - if(!ledSelected[2]){ - ledSelected[2]=true; - button->setBorderWidth(3); - } - else{ - ledSelected[2]=false; - button->setBorderWidth(1); - } - else if(button == led3) - if(!ledSelected[3]){ - ledSelected[3]=true; - button->setBorderWidth(3); - } - else{ - ledSelected[3]=false; - button->setBorderWidth(1); - } - else if(button == led4) - if(!ledSelected[4]){ - ledSelected[4]=true; - button->setBorderWidth(3); - } - else{ - ledSelected[4]=false; - button->setBorderWidth(1); - } - else if(button == led5) - if(!ledSelected[5]){ - ledSelected[5]=true; - button->setBorderWidth(3); - } - else{ - ledSelected[5]=false; - button->setBorderWidth(1); - } - else if(button == led6) - if(!ledSelected[6]){ - ledSelected[6]=true; - button->setBorderWidth(3); - } - else{ - ledSelected[6]=false; - button->setBorderWidth(3); - } - else if(button == led7) - if(!ledSelected[7]){ - ledSelected[7]=true; - button->setBorderWidth(1); - } - else{ - ledSelected[7]=false; - button->setBorderWidth(3); - } - else if(button == led8) - if(!ledSelected[8]){ - ledSelected[8]=true; - button->setBorderWidth(3); - } - else{ - ledSelected[8]=false; - button->setBorderWidth(1); - } - else if(button == led9) - if(!ledSelected[9]){ - ledSelected[9]=true; - button->setBorderWidth(3); - } - else{ - ledSelected[9]=false; - button->setBorderWidth(1); - } - else if(button == led10) - if(!ledSelected[10]){ - ledSelected[10]=true; - button->setBorderWidth(3); - } - else{ - ledSelected[10]=false; - button->setBorderWidth(1); - } - else if(button == led11) - if(!ledSelected[11]){ - ledSelected[11]=true; - button->setBorderWidth(3); - } - else{ - ledSelected[11]=false; - button->setBorderWidth(1); - } - else - return false; - - return true; -} - -bool View::updateSetNewColorAndCancel(Button* button){ - int i=0; - uint32_t RGBcolor=0xFF000000; - if(button == cancel){ - led0->setBorderWidth(1); - led1->setBorderWidth(1); - led2->setBorderWidth(1); - led3->setBorderWidth(1); - led4->setBorderWidth(1); - led5->setBorderWidth(1); - led6->setBorderWidth(1); - led7->setBorderWidth(1); - led8->setBorderWidth(1); - led9->setBorderWidth(1); - led10->setBorderWidth(1); - led11->setBorderWidth(1); - - }else if(button == setNewColor){ - RGBcolor+=RGB[2]+(RGB[1]<<8)+(RGB[0]<<16); - led0->setBorderWidth(1); - led1->setBorderWidth(1); - led2->setBorderWidth(1); - led3->setBorderWidth(1); - led4->setBorderWidth(1); - led5->setBorderWidth(1); - led6->setBorderWidth(1); - led7->setBorderWidth(1); - led8->setBorderWidth(1); - led9->setBorderWidth(1); - led10->setBorderWidth(1); - led11->setBorderWidth(1); - if(ledSelected[0]){ - led0->setBackgroundColor(RGBcolor); - }if(ledSelected[1]){ - led1->setBackgroundColor(RGBcolor); - }if(ledSelected[2]){ - led2->setBackgroundColor(RGBcolor); - }if(ledSelected[3]){ - led3->setBackgroundColor(RGBcolor); - }if(ledSelected[4]){ - led4->setBackgroundColor(RGBcolor); - }if(ledSelected[5]){ - led5->setBackgroundColor(RGBcolor); - }if(ledSelected[6]){ - led6->setBackgroundColor(RGBcolor); - }if(ledSelected[7]){ - led7->setBackgroundColor(RGBcolor); - }if(ledSelected[8]){ - led8->setBackgroundColor(RGBcolor); - }if(ledSelected[9]){ - led9->setBackgroundColor(RGBcolor); - }if(ledSelected[10]){ - led10->setBackgroundColor(RGBcolor); - }if(ledSelected[11]){ - led11->setBackgroundColor(RGBcolor); - } - }else - return false; - - for(i=0; i<12; i++) - ledSelected[i]=false; - return true; -} \ No newline at end of file
--- a/view.h Wed Jun 17 14:16:14 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,97 +0,0 @@ -#ifndef VIEW_H -#define VIEW_H -#include "mbed.h" -#include "button.h" -#include "stm32746g_discovery_lcd.h" -#include "stm32746g_discovery_ts.h" -#include <list> -#include <stdlib.h> -#define SCREENWIDTH 480 -#define SCREENHEIGHT 272 -#define LED_BUTTON_SIZE 40 -#define RGB_TEXT_VIEW_WIDTH 30 -#define RGB_TEXT_VIEW_HEIGHT 15 -#define PLUS_MINUS_BUTTON_SIZE 30 -#define ANIMATION_BUTTON_WIDTH 80 -#define ANIMATION_BUTTON_HEIGHT 15 -#define LIGHT_GRAY (uint32_t)0xFFe0e0d1 -#include <ESP8266.h> - -extern RawSerial pc; -extern RawSerial wifi; - - -class View -{ -public: - View(int width = SCREENWIDTH, int height = SCREENHEIGHT); - void contain(int x, int y); - void draw(); - void updateLCD(); - bool updatePlusMinus(Button* button); - bool updateLEDS(Button* button); - bool updateSetNewColorAndCancel(Button* button); - ~View(); - - -private : - void initLCD(); - void drawText(); - int16_t m_width = SCREENWIDTH; - int16_t m_height = SCREENHEIGHT; - uint32_t m_bgColor = LCD_COLOR_WHITE; - list<Button *> m_buttonList; - ESP8266 * m_esp; - TS_StateTypeDef TS_State; - uint16_t x, y; - uint8_t idx; - bool screenReleased=false; - bool cleared = false; - uint8_t RGB[3]={0x00, 0x00, 0x00}; - char str[10]; - bool ledSelected[12]={false, false, false, false, - false, false, false, false, - false, false, false, false}; - //LEDS buttons - Button *led0 = new Button(300, 5, LED_BUTTON_SIZE, LED_BUTTON_SIZE, LCD_COLOR_BLACK, LCD_COLOR_WHITE); - Button *led1 = new Button(353, 20, LED_BUTTON_SIZE, LED_BUTTON_SIZE, LCD_COLOR_BLACK, LCD_COLOR_WHITE); - Button *led2 = new Button(397, 65, LED_BUTTON_SIZE, LED_BUTTON_SIZE, LCD_COLOR_BLACK, LCD_COLOR_WHITE); - Button *led3 = new Button(410, 118, LED_BUTTON_SIZE, LED_BUTTON_SIZE, LCD_COLOR_BLACK, LCD_COLOR_WHITE); - Button *led4 = new Button(396, 170, LED_BUTTON_SIZE, LED_BUTTON_SIZE, LCD_COLOR_BLACK, LCD_COLOR_WHITE); - Button *led5 = new Button(354, 212, LED_BUTTON_SIZE, LED_BUTTON_SIZE, LCD_COLOR_BLACK, LCD_COLOR_WHITE); - Button *led6 = new Button(300, 227, LED_BUTTON_SIZE, LED_BUTTON_SIZE, LCD_COLOR_BLACK, LCD_COLOR_WHITE); - Button *led7 = new Button(245, 212, LED_BUTTON_SIZE, LED_BUTTON_SIZE, LCD_COLOR_BLACK, LCD_COLOR_WHITE); - Button *led8 = new Button(204, 170, LED_BUTTON_SIZE, LED_BUTTON_SIZE, LCD_COLOR_BLACK, LCD_COLOR_WHITE); - Button *led9 = new Button(190, 118, LED_BUTTON_SIZE, LED_BUTTON_SIZE, LCD_COLOR_BLACK, LCD_COLOR_WHITE); - Button *led10 = new Button(203, 62, LED_BUTTON_SIZE, LED_BUTTON_SIZE, LCD_COLOR_BLACK, LCD_COLOR_WHITE); - Button *led11 = new Button(245, 20, LED_BUTTON_SIZE, LED_BUTTON_SIZE, LCD_COLOR_BLACK, LCD_COLOR_WHITE); - //RGB TextView - Button *redTextview = new Button(90, 38, RGB_TEXT_VIEW_WIDTH, RGB_TEXT_VIEW_HEIGHT, LCD_COLOR_RED); - Button *greenTextview = new Button(90, 128, RGB_TEXT_VIEW_WIDTH, RGB_TEXT_VIEW_HEIGHT, LCD_COLOR_GREEN); - Button *blueTextview = new Button(90, 218, RGB_TEXT_VIEW_WIDTH, RGB_TEXT_VIEW_HEIGHT, LCD_COLOR_BLUE); - //RGB + and - - Button *plusRED = new Button(185-130, 8, PLUS_MINUS_BUTTON_SIZE, PLUS_MINUS_BUTTON_SIZE, LIGHT_GRAY); - Button *minusRED = new Button(185-130, 53, PLUS_MINUS_BUTTON_SIZE, PLUS_MINUS_BUTTON_SIZE, LIGHT_GRAY); - Button *plusGREEN = new Button(185-130, 98, PLUS_MINUS_BUTTON_SIZE, PLUS_MINUS_BUTTON_SIZE, LIGHT_GRAY); - Button *minusGREEN = new Button(185-130, 143, PLUS_MINUS_BUTTON_SIZE, PLUS_MINUS_BUTTON_SIZE, LIGHT_GRAY); - Button *plusBLUE = new Button(185-130, 188, PLUS_MINUS_BUTTON_SIZE, PLUS_MINUS_BUTTON_SIZE, LIGHT_GRAY); - Button *minusBLUE = new Button(185-130, 233, PLUS_MINUS_BUTTON_SIZE, PLUS_MINUS_BUTTON_SIZE, LIGHT_GRAY); - Button *plus10RED = new Button(185-35-130, 8, PLUS_MINUS_BUTTON_SIZE, PLUS_MINUS_BUTTON_SIZE, LIGHT_GRAY); - Button *minus10RED = new Button(185-35-130, 53, PLUS_MINUS_BUTTON_SIZE, PLUS_MINUS_BUTTON_SIZE, LIGHT_GRAY); - Button *plus10GREEN = new Button(185-35-130, 98, PLUS_MINUS_BUTTON_SIZE, PLUS_MINUS_BUTTON_SIZE, LIGHT_GRAY); - Button *minus10GREEN = new Button(185-35-130, 143, PLUS_MINUS_BUTTON_SIZE, PLUS_MINUS_BUTTON_SIZE, LIGHT_GRAY); - Button *plus10BLUE = new Button(185-35-130, 188, PLUS_MINUS_BUTTON_SIZE, PLUS_MINUS_BUTTON_SIZE, LIGHT_GRAY); - Button *minus10BLUE = new Button(185-35-130, 233, PLUS_MINUS_BUTTON_SIZE, PLUS_MINUS_BUTTON_SIZE, LIGHT_GRAY); - //SET NEW COLOR - Button *setNewColor = new Button(270, 100, 100, 25, LIGHT_GRAY); - Button *cancel = new Button(270, 150, 100, 25, LIGHT_GRAY); - //Animations - /*Button *anim1 = new Button(20, 38, ANIMATION_BUTTON_WIDTH, ANIMATION_BUTTON_HEIGHT, LIGHT_GRAY); - Button *anim2 = new Button(20, 68, ANIMATION_BUTTON_WIDTH, ANIMATION_BUTTON_HEIGHT, LIGHT_GRAY); - Button *anim3 = new Button(20, 98, ANIMATION_BUTTON_WIDTH, ANIMATION_BUTTON_HEIGHT, LIGHT_GRAY); - Button *start = new Button(20, 128, 120, ANIMATION_BUTTON_HEIGHT+5, LIGHT_GRAY); - Button *stop = new Button(20, 163, 120, ANIMATION_BUTTON_HEIGHT+5, LIGHT_GRAY);*/ - -}; - -#endif