Сделан настраиваемый дебаунс для кнопок

Убрал дебаунс на игру "реакция" и сделал задержку перед началом игры чуть побольше

Скорректированны текст пунктов меню
This commit is contained in:
2026-04-22 14:51:19 +03:00
parent 357d4e5454
commit 34fe767338
6 changed files with 109 additions and 94 deletions

View File

@@ -166,7 +166,7 @@ static void Timer_OnButton(Button_Type btn, bool longPress) {
// NODES
MenuNode g_clockNode = {
.name = "CLOC",
.name = "CLOCH",
.parent = NULL,
.children = NULL,
.childCount = 0,
@@ -194,7 +194,7 @@ MenuNode g_stopwatchNode = {
};
MenuNode g_timerNode = {
.name = "TIMER",
.name = "TIHER",
.parent = NULL,
.children = NULL,
.childCount = 0,

View File

@@ -133,6 +133,7 @@ static void Display_Reaction(void) {
static void OnEnter_Reaction(void) {
g_gameReaction.state = 0;
g_ctx.debounceTime = 0;
Menu_Refresh();
}
@@ -144,13 +145,14 @@ static void Reaction_OnButton(Button_Type btn, bool longPress) {
if (btn == BUTTON_BACK) {
Menu_GoBack();
g_ctx.debounceTime = 30;
}
uint32_t tick = HAL_GetTick();
if (g_gameReaction.state == 0 && btn == BUTTON_SELECT) {
g_gameReaction.state = 1;
g_gameReaction.waitStart = tick;
g_gameReaction.ledOnTime = 500 + (rand() % 2000);
g_gameReaction.ledOnTime = 1200 + (rand() % 2000);
Menu_Refresh();
}
else if (g_gameReaction.state == 1 && btn == BUTTON_SELECT) {
@@ -165,7 +167,10 @@ static void Reaction_OnButton(Button_Type btn, bool longPress) {
}
else if ((g_gameReaction.state >= 3) && (btn == BUTTON_SELECT))
{
g_gameReaction.state = 0;
g_gameReaction.state = 1;
g_gameReaction.state = 1;
g_gameReaction.waitStart = tick;
g_gameReaction.ledOnTime = 500 + (rand() % 2000);
}
}

View File

@@ -15,7 +15,7 @@ void Menu_Init(MenuNode* startNode) {
g_ctx.currentNode = startNode;
g_ctx.needsRedraw = true;
g_ctx.lastTick = 0;
g_ctx.debounceTime = 30;
if (startNode && startNode->onEnter) {
startNode->onEnter();
}
@@ -116,7 +116,7 @@ void Menu_Process(void) {
g_ctx.lastDebounceTime[i] = tick;
}
if ((tick - g_ctx.lastDebounceTime[i]) > 30) { // DEBOUNCE_MS = 30
if ((tick - g_ctx.lastDebounceTime[i]) >= g_ctx.debounceTime) { // DEBOUNCE_MS = 30
if (reading != g_ctx.buttonState[i]) {
g_ctx.buttonState[i] = reading;

View File

@@ -42,7 +42,7 @@ typedef struct {
uint32_t lastTick;
bool needsRedraw;
int32_t debounceTime;
uint32_t lastDebounceTime[BUTTON_COUNT];
uint8_t lastButtonState[BUTTON_COUNT];
uint8_t buttonState[BUTTON_COUNT];

File diff suppressed because one or more lines are too long

View File

@@ -224,6 +224,10 @@
<pSingCmdsp></pSingCmdsp>
<pMultCmdsp></pMultCmdsp>
<SystemViewers>
<Entry>
<Name>System Viewer\EXTI</Name>
<WinId>35902</WinId>
</Entry>
<Entry>
<Name>System Viewer\GPIOB</Name>
<WinId>35905</WinId>