better buttons polling

master
Dmitry Maylarov 7 years ago
parent ecda37396b
commit 48e8b3c309

@ -103,11 +103,15 @@ void LCD_Init(LCD_HandleTypeDef *lcd) {
//http://nerdralph.blogspot.com/2014/07/controlling-hd44780-displays.html //http://nerdralph.blogspot.com/2014/07/controlling-hd44780-displays.html
vTaskDelay(30); vTaskDelay(30);
LCD_SendCommand(lcd, LCD_FUNCTIONSET | LCD_8BITMODE); LCD_SendCommand(lcd, LCD_FUNCTIONSET | LCD_8BITMODE);
vTaskDelay(1); vTaskDelay(5);
LCD_SendCommand(lcd, LCD_FUNCTIONSET | LCD_8BITMODE); LCD_SendCommand(lcd, LCD_FUNCTIONSET | LCD_8BITMODE);
vTaskDelay(1); vTaskDelay(5);
LCD_SendCommand(lcd, LCD_FUNCTIONSET | LCD_4BITMODE); LCD_SendCommand(lcd, LCD_FUNCTIONSET | LCD_4BITMODE);
vTaskDelay(1); vTaskDelay(1);
LCD_SendCommand(lcd, LCD_FUNCTIONSET | LCD_4BITMODE | LCD_SINGLELINE | LCD_5x8DOTS); // 0b00110000);
vTaskDelay(5);
LCD_SendCommand(lcd, LCD_FUNCTIONSET | LCD_4BITMODE | LCD_SINGLELINE | LCD_5x8DOTS); // 0b00110000);
vTaskDelay(5);
LCD_SendCommand(lcd, LCD_FUNCTIONSET | LCD_4BITMODE | LCD_MULTILINE | LCD_5x8DOTS); // 0b00110000); LCD_SendCommand(lcd, LCD_FUNCTIONSET | LCD_4BITMODE | LCD_MULTILINE | LCD_5x8DOTS); // 0b00110000);
vTaskDelay(5); vTaskDelay(5);
// display & cursor home (keep this!) // display & cursor home (keep this!)

@ -455,9 +455,7 @@ static void MX_GPIO_Init(void)
void vTaskPlayerSetup(void *parameter) void vTaskPlayerSetup(void *parameter)
{ {
vTaskDelay(500);
LCD_Init(&hlcd); LCD_Init(&hlcd);
vTaskDelay(100);
LCD_MoveCursor(&hlcd, 0, 0); LCD_MoveCursor(&hlcd, 0, 0);
LCD_SendString(&hlcd, "Settings"); LCD_SendString(&hlcd, "Settings");
LCD_MoveCursor(&hlcd, 1, 0); LCD_MoveCursor(&hlcd, 1, 0);
@ -624,17 +622,15 @@ void vTaskButtonPoll(void *parameter) {
for(int i = 0; i<BUTTON_COUNT; i++) for(int i = 0; i<BUTTON_COUNT; i++)
{ {
bool state = HAL_GPIO_ReadPin(buttons[i].port, buttons[i].pin); bool state = HAL_GPIO_ReadPin(buttons[i].port, buttons[i].pin);
vTaskDelay(1); if (state != buttons[i].pressed)
if (state && !buttons[i].temp) {
buttons[i].temp = true; vTaskDelay(100);
else if (state && buttons[i].temp) state = HAL_GPIO_ReadPin(buttons[i].port, buttons[i].pin);
buttons[i].pressed = true; if (state != buttons[i].pressed)
else if (!state && !buttons[i].temp) buttons[i].pressed = !buttons[i].pressed;
buttons[i].pressed = false; }
else if (!state && buttons[i].pressed) vTaskDelay(100);
buttons[i].temp = false;
} }
vTaskDelay(50);
} }
} }
/* USER CODE END 4 */ /* USER CODE END 4 */

Loading…
Cancel
Save