Nice, working menus

master
Dmitry Maylarov 7 years ago
parent c1f541ad7e
commit 6ef14d0149

@ -12,7 +12,7 @@ typedef struct {
uint8_t activePlayers; uint8_t activePlayers;
uint8_t currentPlayer; uint8_t currentPlayer;
uint32_t turnTime; uint32_t turnTime;
uint32_t timerValue; int32_t timerValue;
uint32_t scores[MAX_PLAYERS+1]; uint32_t scores[MAX_PLAYERS+1];
} GameEngine; } GameEngine;

@ -4,7 +4,7 @@ extern GameEngine game;
void InitGameEngine() { void InitGameEngine() {
game.timerValue = game.turnTime; game.timerValue = game.turnTime;
game.countScores = false; game.countScores = true;
game.activePlayers = 0; game.activePlayers = 0;
game.currentPlayer = 1; game.currentPlayer = 1;
game.turnTime = TIMER_MAX / 2; game.turnTime = TIMER_MAX / 2;

@ -129,6 +129,16 @@ static void MX_TIM3_Init(void);
static void MX_USART1_UART_Init(void); static void MX_USART1_UART_Init(void);
/* USER CODE BEGIN PFP */ /* USER CODE BEGIN PFP */
void PrintTime() {
LCD_MoveCursor(&hlcd, 0, 0);
sprintf(
lcdBuffer,
(game.timerValue > 0 ? " %1ld:%02d " : " -%ld:%02d "),
abs(game.timerValue / 60),
abs(game.timerValue % 60)
);
LCD_SendString(&hlcd, lcdBuffer);
}
/* USER CODE END PFP */ /* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/ /* Private user code ---------------------------------------------------------*/
@ -489,6 +499,11 @@ void vTaskPlayerSetup(void *parameter)
} }
void vTaskTimerSetup(void *parameter) { void vTaskTimerSetup(void *parameter) {
if (xLCDUpdaterHandle != NULL)
{
vTaskDelete(xLCDUpdaterHandle);
xLCDUpdaterHandle = NULL;
}
LCD_MoveHome(&hlcd); LCD_MoveHome(&hlcd);
LCD_SendString(&hlcd, "Settings"); LCD_SendString(&hlcd, "Settings");
while (1) while (1)
@ -527,6 +542,11 @@ void vTaskTimerSetup(void *parameter) {
} }
void vTaskConfig(void *parameter) { void vTaskConfig(void *parameter) {
if (xLCDUpdaterHandle != NULL)
{
vTaskDelete(xLCDUpdaterHandle);
xLCDUpdaterHandle = NULL;
}
LCD_MoveHome(&hlcd); LCD_MoveHome(&hlcd);
LCD_SendString(&hlcd, "Settings"); LCD_SendString(&hlcd, "Settings");
while (1) while (1)
@ -557,17 +577,17 @@ void vTaskTurnTimeUpdate(void *parameter) {
while (1) while (1)
{ {
LCD_MoveCursor(&hlcd, 0, 0); PrintTime();
sprintf(lcdBuffer, " %1ld:%02ld ",game.timerValue / 60, game.timerValue % 60);
LCD_SendString(&hlcd, lcdBuffer);
vTaskDelayUntil(&xLastWakeTime,1000); vTaskDelayUntil(&xLastWakeTime,1000);
} }
} }
void vTaskTurn(void *parameter) { void vTaskTurn(void *parameter) {
xTaskCreate(vTaskTurnTimeUpdate, "TimeUpdate", configMINIMAL_STACK_SIZE, NULL, 1, &xLCDUpdaterHandle); if (xLCDUpdaterHandle == NULL)
vTaskDelay(1); {
xTaskCreate(vTaskTurnTimeUpdate, "TimeUpdate", configMINIMAL_STACK_SIZE, NULL, 1, &xLCDUpdaterHandle);
vTaskDelay(100);
}
TickType_t xLastWakeTime; TickType_t xLastWakeTime;
xLastWakeTime = xTaskGetTickCount(); xLastWakeTime = xTaskGetTickCount();
@ -619,21 +639,25 @@ void vTaskTurn(void *parameter) {
// HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin); // HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
} }
xTimerStop(secondsTimerHandle, 0); xTimerStop(secondsTimerHandle, 0);
ResetTurnTimer();
if (xMusicHandle) { if (xMusicHandle) {
vTaskDelete(xMusicHandle); vTaskDelete(xMusicHandle);
MusicStop(); MusicStop();
xMusicHandle = NULL; xMusicHandle = NULL;
} }
vTaskDelete(xLCDUpdaterHandle);
vTaskDelete(NULL); vTaskDelete(NULL);
} }
void vTaskTurnEnd(void *parameter) { void vTaskTurnEnd(void *parameter) {
if (xLCDUpdaterHandle != NULL)
{
vTaskDelete(xLCDUpdaterHandle);
xLCDUpdaterHandle = NULL;
}
if (game.countScores) { if (game.countScores) {
int32_t delta = 0; int32_t delta = 0;
LCD_MoveHome(&hlcd); LCD_MoveHome(&hlcd);
PrintTime();
LCD_MoveCursor(&hlcd, 1, 0); LCD_MoveCursor(&hlcd, 1, 0);
sprintf(lcdBuffer, "Player: %1d Score: %3ld",game.currentPlayer, game.scores[game.currentPlayer]); sprintf(lcdBuffer, "Player: %1d Score: %3ld",game.currentPlayer, game.scores[game.currentPlayer]);
LCD_SendString(&hlcd, lcdBuffer); LCD_SendString(&hlcd, lcdBuffer);
@ -660,12 +684,14 @@ void vTaskTurnEnd(void *parameter) {
} }
} }
} }
ResetTurnTimer();
NextPlayer(); NextPlayer();
xTaskCreate(vTaskTurn, "TaskTurn", configMINIMAL_STACK_SIZE, NULL, 1, NULL); xTaskCreate(vTaskTurn, "TaskTurn", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
vTaskDelete(NULL); vTaskDelete(NULL);
} }
void vTaskOvertime(void *parameter) { void vTaskOvertime(void *parameter) {
/*
Track music[2] = { Track music[2] = {
{ .begin = tetris, .size = tetris_len}, { .begin = tetris, .size = tetris_len},
{ .begin = super_mario, .size = super_mario_len} { .begin = super_mario, .size = super_mario_len}
@ -676,13 +702,13 @@ void vTaskOvertime(void *parameter) {
MusicPlay(&music[0]); MusicPlay(&music[0]);
HAL_GPIO_WritePin(LED2_GPIO_Port, LED1_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(LED2_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);
vTaskDelay(1000); vTaskDelay(1000);
} } */
while (1) {};
} }
void vTimerCallback(TimerHandle_t xTimer) { void vTimerCallback(TimerHandle_t xTimer) {
if (game.timerValue > 0) game.timerValue--;
game.timerValue--; if(game.timerValue == 0 && xMusicHandle == NULL)
else if(game.timerValue == 0 && xMusicHandle == NULL)
{ {
xTaskCreate(vTaskOvertime, "vTaskOvertime", configMINIMAL_STACK_SIZE, NULL, 1, &xMusicHandle); xTaskCreate(vTaskOvertime, "vTaskOvertime", configMINIMAL_STACK_SIZE, NULL, 1, &xMusicHandle);
} }

Loading…
Cancel
Save