/** * @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 Touchscreen Demo * @param None * @retval None */ void Touchscreen_demo (void) { uint8_t status = 0; uint16_t x,y; uint8_t state = 0; if(stmpe811_ts_drv.ReadID(TS_I2C_ADDRESS) == STMPE811_ID) { if(IsCalibrationDone() == 0) { Touchscreen_Calibration(); } } Touchscreen_SetHint(); status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); if (status != TS_OK) { BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 95, (uint8_t *)"ERROR", CENTER_MODE); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 80, (uint8_t *)"Touchscreen cannot be initialized", CENTER_MODE); } else { Touchscreen_DrawBackground(state); } while (1) { if (status == TS_OK) { BSP_TS_GetState(&TS_State); if(stmpe811_ts_drv.ReadID(TS_I2C_ADDRESS) == STMPE811_ID) { x = Calibration_GetX(TS_State.x); y = Calibration_GetY(TS_State.y); } else { x = TS_State.x; y = TS_State.y; } if((TS_State.TouchDetected) && (y > (CIRCLE_YPOS(1) - CIRCLE_RADIUS))&& (y < (CIRCLE_YPOS(1) + CIRCLE_RADIUS))) { if((x > (CIRCLE_XPOS(1) - CIRCLE_RADIUS))&& (x < (CIRCLE_XPOS(1) + CIRCLE_RADIUS))) { if((state & 1) == 0) { Touchscreen_DrawBackground(state); BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS); state = 1; } } if((x > (CIRCLE_XPOS(2) - CIRCLE_RADIUS))&& (x < (CIRCLE_XPOS(2) + CIRCLE_RADIUS))) { if((state & 2) == 0) { Touchscreen_DrawBackground(state); BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS); state = 2; } } if((x > (CIRCLE_XPOS(3) - CIRCLE_RADIUS))&& (x < (CIRCLE_XPOS(3) + CIRCLE_RADIUS))) { if((state & 4) == 0) { Touchscreen_DrawBackground(state); BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); BSP_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS); state = 4; } } if((x > (CIRCLE_XPOS(4) - CIRCLE_RADIUS))&& (x < (CIRCLE_XPOS(4) + CIRCLE_RADIUS))) { if((state & 8) == 0) { Touchscreen_DrawBackground(state); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(3), CIRCLE_RADIUS); state = 8; } } } } if(CheckForUserInput() > 0) { return; } HAL_Delay(10); } }
/** * @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(); } }