better blink

This commit is contained in:
2021-03-03 19:16:22 +01:00
parent fe1bc101a3
commit 6611220851
4 changed files with 18 additions and 3 deletions

View File

@ -12,7 +12,7 @@ typedef enum {
LED_BLUE LED_BLUE
} signalPin_t; } signalPin_t;
typedef enum { ON, OFF, TOGGLE, BLINK } signalAction_t; typedef enum { ON, OFF, TOGGLE, BLINK, BLINK_FAST } signalAction_t;
void showInit(); void showInit();
void show(signalPin_t signalPin, signalAction_t action); void show(signalPin_t signalPin, signalAction_t action);

View File

@ -3,6 +3,7 @@
#include <iwdg.h> #include <iwdg.h>
#include <logger.h> #include <logger.h>
#include <sinkStruct.h> #include <sinkStruct.h>
#include <show.h>
#include <config.h> #include <config.h>
#include <networkAbstractionLayer_impl.h> #include <networkAbstractionLayer_impl.h>
@ -28,6 +29,7 @@ static void networkSecondsHandler(void *handle) {
seconds.seconds = tmpSeconds; seconds.seconds = tmpSeconds;
seconds.missedUpdates = 0; seconds.missedUpdates = 0;
seconds.valid = true; seconds.valid = true;
show(LED_GREEN, ON);
} else { } else {
coloredMsg(LOG_YELLOW, "nsh, failed"); coloredMsg(LOG_YELLOW, "nsh, failed");
seconds.missedUpdates += 1; seconds.missedUpdates += 1;
@ -39,6 +41,7 @@ static void networkSecondsHandler(void *handle) {
coloredMsg(LOG_YELLOW, "nsh, success, network time is %lu", tmpSeconds); coloredMsg(LOG_YELLOW, "nsh, success, network time is %lu", tmpSeconds);
seconds.missedUpdates = 0; seconds.missedUpdates = 0;
tryAgain = false; tryAgain = false;
show(LED_GREEN, ON);
if (seconds.seconds != tmpSeconds) { if (seconds.seconds != tmpSeconds) {
coloredMsg(LOG_YELLOW, "nsh, local time updated"); coloredMsg(LOG_YELLOW, "nsh, local time updated");
seconds.seconds = tmpSeconds; seconds.seconds = tmpSeconds;

View File

@ -1,6 +1,7 @@
#include <main.h> #include <main.h>
#include <show.h> #include <show.h>
#include <PontCoopScheduler.h> #include <PontCoopScheduler.h>
#include <show.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@ -24,9 +25,20 @@ showElement_t showElement[] = {
}; };
static void showHandler(void *handle) { static void showHandler(void *handle) {
const uint8_t MAX_CNT = 3;
static uint8_t cnt = 0;
cnt += 1;
if (cnt > MAX_CNT) {
cnt = 0;
}
uint8_t idx = 0; uint8_t idx = 0;
while (showElement[idx].port) { while (showElement[idx].port) {
if (showElement[idx].currentState == BLINK) { if (showElement[idx].currentState == BLINK) {
if (cnt == MAX_CNT) {
HAL_GPIO_TogglePin(showElement[idx].port, showElement[idx].pin);
}
} else if (showElement[idx].currentState == BLINK_FAST) {
HAL_GPIO_TogglePin(showElement[idx].port, showElement[idx].pin); HAL_GPIO_TogglePin(showElement[idx].port, showElement[idx].pin);
} }
idx++; idx++;
@ -43,5 +55,5 @@ void show(signalPin_t signalPin, signalAction_t action) {
} }
void showInit() { void showInit() {
schAdd(showHandler, NULL, 0, 250); schAdd(showHandler, NULL, 0, 100);
} }

View File

@ -86,7 +86,7 @@ static void wizDHCPAssign() {
coloredMsg(LOG_BLUE, "wizda, set netinfo again"); coloredMsg(LOG_BLUE, "wizda, set netinfo again");
networkAvailable = true; networkAvailable = true;
show(LED_GREEN, ON); show(LED_GREEN, BLINK_FAST);
coloredMsg(LOG_BLUE, "wizda, network is available"); coloredMsg(LOG_BLUE, "wizda, network is available");
} }