/** * @brief Update the selected color * @param None * @retval None */ static void Update_Color(void) { static uint32_t color; /* Get the current text color */ color = BSP_LCD_GetTextColor(); /* Update the selected color icon */ BSP_LCD_FillRect(380, (BSP_LCD_GetYSize()-40), 30, 30); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_DrawRect(380, (BSP_LCD_GetYSize()-40), 30, 30); BSP_LCD_SetTextColor(color); }
/** * @brief Updates the selected size * @param size: Size to be updated * @retval None */ static void Update_Size(uint8_t size) { static uint32_t color; /* Get the current text color */ color = BSP_LCD_GetTextColor(); /* Update the selected size icon */ BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillCircle(450, (BSP_LCD_GetYSize()-24), 20); BSP_LCD_SetTextColor(color); BSP_LCD_FillCircle(450, (BSP_LCD_GetYSize()-24), size); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_DrawCircle(450, (BSP_LCD_GetYSize()-24), size); BSP_LCD_SetTextColor(color); }
/** * @brief Updates the selected Color and Size * @param None * @retval None */ static void Update_ColorSize(void) { static uint32_t color; /* Clear the current circle */ color = BSP_LCD_GetTextColor(); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillCircle(220, (BSP_LCD_GetYSize()-24), 10); BSP_LCD_SetTextColor(color); /* Update the selected color icon */ BSP_LCD_FillCircle(220, (BSP_LCD_GetYSize()-24), radius); /* Draw black circle */ BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_DrawCircle(220, (BSP_LCD_GetYSize() - 24), radius); BSP_LCD_SetTextColor(color); }
/** * @brief Configures and gets Touch screen position. * @param None * @retval None */ static void GetPosition(void) { static uint32_t color_width; static uint32_t color; uint16_t x, y; color_width = 35; /* Get Touch screen position */ BSP_TS_GetState(&TS_State); if(TS_State.touchDetected) { /* A touch occured, read the touch coordinates */ /* Get X and Y position of the first touch post calibrated */ x = TouchScreen_Get_Calibrated_X(TS_State.touchX[0]); y = TouchScreen_Get_Calibrated_Y(TS_State.touchY[0]); if((x > (90 + Radius)) & (y > (7 + Radius) ) & ( x < (BSP_LCD_GetXSize() - (7 + Radius ))) & (y < (BSP_LCD_GetYSize() - (95 + Radius )))) { BSP_LCD_FillCircle((x), (y), Radius); } else if((x > 0 ) & ( x < 90 )) { if((y > 0 ) & (y < color_width )) { BSP_LCD_SetTextColor(LCD_COLOR_WHITE); Update_Size(Radius); } else if((y > color_width ) & (y < (2 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); Update_Size(Radius); } else if((y > (2 * color_width)) & (y < (3 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); Update_Size(Radius); } else if((y > (3 * color_width)) & (y < (4 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_LIGHTMAGENTA); Update_Size(Radius); } else if((y > (4 * color_width)) & (y < (5 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_DARKGREEN); Update_Size(Radius); } else if((y > (5 * color_width)) &(y < (6 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_GREEN); Update_Size(Radius); } else if((y > (6 * color_width)) &(y < (7 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_BROWN); Update_Size(Radius); } else if((y > (7 * color_width)) & (y < (8 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_RED); Update_Size(Radius); } else if((y > (8 * color_width)) & (y < (9 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_DARKMAGENTA); Update_Size(Radius); } else if((y > (9 * color_width)) & (y < (10 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_CYAN); Update_Size(Radius); } else if((y > (10 * color_width)) & (y < (11 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE); Update_Size(Radius); } else if((y > (11 * color_width)) & (y < (12 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_BLACK); Update_Size(Radius); } else if((y > (12 * color_width)) & (y < (14 * color_width))) { /* Get the current text color */ color = BSP_LCD_GetTextColor(); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); /* Clear the working window */ BSP_LCD_FillRect(97, 8, 694, 374); BSP_LCD_SetTextColor(color); } else { x = 0; y = 0; } Update_Color(); } else if((x > 100) & (y > (BSP_LCD_GetYSize() - 90)) & (y < (BSP_LCD_GetYSize()) ) & ( x < 170)) { Radius = 15; Update_Size(Radius); } else if((x > 170) & (y > (BSP_LCD_GetYSize() - 90)) & (y < (BSP_LCD_GetYSize()) ) & ( x < 240)) { Radius = 10; Update_Size(Radius); } else if((x > 240) & (y > (BSP_LCD_GetYSize() - 90)) & (y < (BSP_LCD_GetYSize()) ) & ( x < 310)) { Radius = 5; Update_Size(Radius); } else if(((x > (BSP_LCD_GetXSize()-5) ) & (y > (14 * color_width)) & (y < (15 * color_width))) | ((x < 90) & (y < 5))) { TS_State.touchX[0] = 0; TS_State.touchY[0] = 0; } else if((x > 320) & (y > (BSP_LCD_GetYSize() - 90)) & (x < 410) & (y < BSP_LCD_GetYSize() - 5)) { Save_Picture(); } } }
/** * @brief Configures and gets Touch screen position. * @param None * @retval None */ static void GetPosition(void) { static uint32_t color_width; static uint32_t color; if (BSP_LCD_GetXSize() == 640) { color_width = 36; } else { color_width = 19; } /* Get Touch screen position */ BSP_TS_GetState(&TS_State); /* Read the coordinate */ x = Calibration_GetX(TS_State.x); y = Calibration_GetX(TS_State.y); if ((TS_State.TouchDetected) & (x > (67 + Radius)) & (y > (7 + Radius) ) & ( x < (BSP_LCD_GetXSize()-(7 + Radius )) ) & (y < (BSP_LCD_GetYSize()-(67 + Radius )) )) { BSP_LCD_FillCircle((x), (y), Radius); } else if ((TS_State.TouchDetected) & (x > 0 ) & ( x < 50 )) { if ((TS_State.TouchDetected) & ( y > 0 ) & ( y < color_width )) { BSP_LCD_SetTextColor(LCD_COLOR_WHITE); Update_Size(Radius); } else if ((TS_State.TouchDetected) & ( y > color_width ) & (y < (2 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); Update_Size(Radius); } else if ((TS_State.TouchDetected) & (y > (2 * color_width)) & (y < (3 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); Update_Size(Radius); } else if ((TS_State.TouchDetected) & (y > (3 * color_width)) & (y < (4 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_LIGHTMAGENTA); Update_Size(Radius); } else if ((TS_State.TouchDetected) & (y > (4 * color_width)) & (y < (5 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_DARKGREEN); Update_Size(Radius); } else if ((TS_State.TouchDetected) & (y > (5 * color_width)) &(y < (6 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_GREEN); Update_Size(Radius); } else if ((TS_State.TouchDetected) & (y > (6 * color_width)) &(y < (7 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_BROWN); Update_Size(Radius); } else if ((TS_State.TouchDetected) & (y > (7 * color_width)) & (y < (8 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_RED); Update_Size(Radius); } else if ((TS_State.TouchDetected) & (y > (8 * color_width)) & (y < (9 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_DARKMAGENTA); Update_Size(Radius); } else if ((TS_State.TouchDetected) & (y > (9 * color_width)) & (y < (10 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_CYAN); Update_Size(Radius); } else if ((TS_State.TouchDetected) & (y > (10 * color_width)) & (y < (11 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE); Update_Size(Radius); } else if ((TS_State.TouchDetected) & (y > (11 * color_width)) & (y < (12 * color_width))) { BSP_LCD_SetTextColor(LCD_COLOR_BLACK); Update_Size(Radius); } else if ((TS_State.TouchDetected) & (y > (12 * color_width)) & (y < (13 * color_width))) { /* Get the current text color */ color = BSP_LCD_GetTextColor(); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); /* Clear the working window */ BSP_LCD_FillRect(68, 8, (BSP_LCD_GetXSize() - 75), (BSP_LCD_GetYSize() - 75)); BSP_LCD_SetTextColor(color); } else { x = 0; y = 0; } Update_Color(); } else if ((TS_State.TouchDetected) & (x > 70 ) & (y > (12 * color_width)) & (y < (13 * color_width)) & ( x < 120 )) { Radius = 20; Update_Size(Radius); } else if ((TS_State.TouchDetected) & (x > 120 ) & (y > (12 * color_width)) & (y < (13 * color_width)) & ( x < 170 )) { Radius = 15; Update_Size(Radius); } else if ((TS_State.TouchDetected) & (x > 170 ) & (y > (12 * color_width)) & (y < (13 * color_width)) & ( x < 220 )) { Radius = 10; Update_Size(Radius); } else if ((TS_State.TouchDetected) & (x > 220 ) & (y > (12 * color_width)) & (y < (13 * color_width)) & ( x < 270 )) { Radius = 5; Update_Size(Radius); } else if ((TS_State.TouchDetected) & (x > 270 ) & (y > (12 * color_width)) & (y < (13 * color_width)) & ( x < 320 )) { Radius = 2; Update_Size(Radius); } else if ((TS_State.TouchDetected) & (((x > (BSP_LCD_GetXSize()-5) ) & (y > (12 * color_width)) & (y < (13 * color_width))) | (( x < 55 ) & ( y < 5 )))) { TS_State.x = 0; TS_State.y = 0; } else if ((TS_State.TouchDetected) & (x > 320) & (y > (BSP_LCD_GetYSize() - 50)) & (x < 370) & (y < BSP_LCD_GetYSize() )) { Save_Picture(); } }
/** * @brief Configures and gets Touch screen position. * @param None * @retval None */ static void GetPosition(void) { static uint32_t x = 0, y = 0; static uint32_t color_heigh; static uint32_t color; static TS_StateTypeDef TS_State; /* Heigh of color pen */ color_heigh = 20; /* Get Touch screen position */ BSP_TS_GetState(&TS_State); /* Read the coordinate */ x = Calibration_GetX(TS_State.X); y = Calibration_GetX(TS_State.Y); if ((TS_State.TouchDetected) & ( x > 0 ) & ( x < 50 )) { /* User selects one of the color pens */ if ((TS_State.TouchDetected) & ( y > 0 ) & ( y < color_heigh )) { BSP_LCD_SetTextColor(LCD_COLOR_WHITE); } else if ((TS_State.TouchDetected) & ( y > color_heigh ) & ( y < (2*color_heigh) )) { BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); } else if ((TS_State.TouchDetected) & ( y > (2*color_heigh) ) & ( y < (3*color_heigh) )) { BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); } else if ((TS_State.TouchDetected) & ( y > (3*color_heigh) ) & ( y < (4*color_heigh) )) { BSP_LCD_SetTextColor(LCD_COLOR_LIGHTMAGENTA); } else if ((TS_State.TouchDetected) & ( y > (4*color_heigh) ) & ( y < (5*color_heigh) )) { BSP_LCD_SetTextColor(LCD_COLOR_DARKGREEN); } else if ((TS_State.TouchDetected) & ( y > (5*color_heigh) ) &( y < (6*color_heigh) )) { BSP_LCD_SetTextColor(LCD_COLOR_GREEN); } else if ((TS_State.TouchDetected) & ( y > (6*color_heigh) ) &( y < (7*color_heigh) )) { BSP_LCD_SetTextColor(LCD_COLOR_BROWN); } else if ((TS_State.TouchDetected) & ( y > (7*color_heigh) ) & ( y < (8*color_heigh) )) { BSP_LCD_SetTextColor(LCD_COLOR_RED); } else if ((TS_State.TouchDetected) & ( y > (8*color_heigh) ) & ( y < (9*color_heigh) )) { BSP_LCD_SetTextColor(LCD_COLOR_DARKMAGENTA); } else if ((TS_State.TouchDetected) & ( y > (9*color_heigh) ) & ( y < (10*color_heigh) )) { BSP_LCD_SetTextColor(LCD_COLOR_CYAN); } else if ((TS_State.TouchDetected) & ( y > (10*color_heigh) ) & ( y < (11*color_heigh) )) { BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE); } else if ((TS_State.TouchDetected) & ( y > (11*color_heigh) ) & ( y < (12*color_heigh) )) { BSP_LCD_SetTextColor(LCD_COLOR_BLACK); } else if ((TS_State.TouchDetected) & ( y > (12*color_heigh) ) & ( y < (13*color_heigh) )) { /* Clear screen and reinitialize color and size */ /* Get the current text color */ color = BSP_LCD_GetTextColor(); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); /* Clear the working window */ BSP_LCD_FillRect(68, 8, 164, 245); BSP_LCD_SetTextColor(color); radius = 2; } else { x = 0; y = 0; } Update_ColorSize(); } else if ((TS_State.TouchDetected) & ( x > 65 ) & ( y > (BSP_LCD_GetYSize()-48)) & ( y < (BSP_LCD_GetYSize()) ) & ( x < 85 )) { radius = 10; Update_ColorSize(); } else if ((TS_State.TouchDetected) & ( x > 100 ) & ( y > (BSP_LCD_GetYSize()-48) ) & ( y < (BSP_LCD_GetYSize()) ) & ( x < 110 )) { radius = 5; Update_ColorSize(); } else if ((TS_State.TouchDetected) & ( x > 133 ) & ( y > (BSP_LCD_GetYSize()-48) ) & ( y < (BSP_LCD_GetYSize()) ) & ( x < 137 )) { radius = 2; Update_ColorSize(); } else if (((TS_State.TouchDetected) & ( x > (BSP_LCD_GetXSize()-5) ) & ( y > (12*color_heigh) ) & ( y < (13*color_heigh) )) | (( x < 55 ) & ( y < 5 ))) { x = 0; y = 0; } else if ((TS_State.TouchDetected) & ( x > (67 + radius)) & ( y > (7 + radius) ) & ( x < (BSP_LCD_GetXSize()-(7 + radius )) ) & ( y < (BSP_LCD_GetYSize()-(67 + radius )) )) { BSP_LCD_FillCircle((x), (y), radius); } else if ((TS_State.TouchDetected) & ( (x > 150) & ( y > (BSP_LCD_GetYSize() - 50) )) & ( x < 200 ) & ( y < (BSP_LCD_GetYSize()) )) { Save_Picture(); } }
// Note modifed by CMN to use X as a coordinate, not a character position void BSP_LCD_DisplayStringAt(uint16_t X, uint16_t Y, uint8_t *pText, Text_AlignModeTypdef mode) { uint32_t fgColor; uint32_t bgColor; fgColor = BSP_LCD_GetTextColor(); bgColor = BSP_LCD_GetBackColor(); uint16_t refcolumn = 1, i = 0; uint32_t size = 0, xsize = 0; uint8_t *ptr = pText; /* Get the text size */ while (*ptr++) size ++ ; /* Characters number per line */ xsize = (BSP_LCD_GetXSize()/DrawProp[ActiveLayer].pFont->Width); switch (mode) { case CENTER_MODE: { refcolumn = X - ((size)* DrawProp[ActiveLayer].pFont->Width) / 2; break; } case LEFT_MODE: { refcolumn = X; break; } case RIGHT_MODE: { refcolumn = X + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width); break; } default: { refcolumn = X; break; } } /* Send the string character by character on LCD */ while ((*pText != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width)) { // inverse video if (*pText & 0x80) { BSP_LCD_SetTextColor(bgColor); BSP_LCD_SetBackColor(fgColor); } else { BSP_LCD_SetTextColor(fgColor); BSP_LCD_SetBackColor(bgColor); } /* Display one character on LCD */ BSP_LCD_DisplayChar(refcolumn, Y, 0x7f & (*pText)); /* Decrement the column position by 16 */ refcolumn += DrawProp[ActiveLayer].pFont->Width; /* Point on the next character */ pText++; i++; } }
/** * @brief Save the picture in USB Disk. * @param None * @retval None */ void Save_Picture(void) { FRESULT res1, res2; /* FatFs function common result code */ uint32_t byteswritten; /* File write count */ static uint32_t color; /* Get the current text color */ color = BSP_LCD_GetTextColor(); BSP_LCD_SetTextColor(LCD_COLOR_DARKRED); BSP_LCD_SetFont(&Font20); /* Turn LED1 and LED3 Off */ BSP_LED_Off(LED1); BSP_LED_Off(LED3); if (Appli_state == APPLICATION_RUNNIG) { BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()-35), (uint8_t *)"Saving ... ", RIGHT_MODE); /*##-1- Prepare the image to be saved ####################################*/ Prepare_Picture(); /*##-2- Create and Open a new bmp file object with write access ##########*/ if(f_open(&MyFile, "image.bmp", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { /* 'image.bmp' file Open for write Error */ Error_Handler(); } else { /*##-3- Write data to the BMP file #####################################*/ /* Write the BMP header */ if (BSP_LCD_GetXSize() == 640) { /* if ampire 640x480 LCD is used */ res1 = f_write(&MyFile, (uint32_t *)aBMPHeader1, 54, (void *)&byteswritten); } else { /* if ampire 480x272 LCD is used */ res1 = f_write(&MyFile, (uint32_t *)aBMPHeader2, 54, (void *)&byteswritten); } /* Write the bmp file */ res2 = f_write(&MyFile, (uint32_t *)CONVERTED_FRAME_BUFFER, ((BSP_LCD_GetYSize()-60)*(BSP_LCD_GetXSize()-60)*3), (void *)&byteswritten); if((res1 != FR_OK) || (res2 != FR_OK) || (byteswritten == 0)) { /* 'image' file Write or EOF Error */ BSP_LED_On(LED3); BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()-35), (uint8_t *)" Aborted...", RIGHT_MODE); /* Wait for 2s */ HAL_Delay(2000); } else { /*##-4- Close the open text file #####################################*/ f_close(&MyFile); /* Success of the demo: no error occurrence */ BSP_LED_On(LED1); BSP_LCD_SetTextColor(LCD_COLOR_DARKGREEN); BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()-35), (uint8_t *)" Saved ", RIGHT_MODE); /* Wait for 2s */ HAL_Delay(2000); } } } else { /* USB not connected */ BSP_LCD_DisplayStringAt(0, (BSP_LCD_GetYSize()-35), (uint8_t *)"USB KO... ", RIGHT_MODE); /* Wait for 2s */ HAL_Delay(2000); } BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillRect(480, 430, 160, 50); BSP_LCD_SetTextColor(color); }
uint32_t LCD_DISCO_F469NI::GetTextColor(void) { return BSP_LCD_GetTextColor(); }