aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-01-28 23:35:59 +0100
committerLouis Burda <quent.burda@gmail.com>2023-01-28 23:35:59 +0100
commita08ae9e31873a094a5e7d47ae8cfd2edfe6a60a4 (patch)
tree9c9075631e97c21e255c3f964072fc2da412440b /src/util.c
parentc70a527d0418b4f32437873f682680f451fa4fb8 (diff)
downloadsxkbd-a08ae9e31873a094a5e7d47ae8cfd2edfe6a60a4.tar.gz
sxkbd-a08ae9e31873a094a5e7d47ae8cfd2edfe6a60a4.zip
Add led blips for warnings and on startup
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/util.c b/src/util.c
index f2ed8ab..eb8e3c3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -11,6 +11,7 @@
#include <stdio.h>
+char warnlog[512];
int loglevel = LOG_INFO;
static void
@@ -40,12 +41,20 @@ void
__attribute__ ((format (printf, 2, 3)))
stdio_log(int level, const char *fmtstr, ...)
{
- va_list ap;
+ va_list ap, cpy;
+
+ if (level == LOG_WARN) {
+ led_blip(HARD_RED);
+ va_copy(cpy, ap);
+ va_start(cpy, fmtstr);
+ vsnprintf(warnlog, sizeof(warnlog), fmtstr, cpy);
+ va_end(cpy);
+ }
- if (!tud_cdc_connected())
+ if (level > loglevel)
return;
- if (level > loglevel)
+ if (!tud_cdc_connected())
return;
va_start(ap, fmtstr);
@@ -61,17 +70,15 @@ blink_panic(uint32_t blink_ms, uint32_t rgb, const char *fmtstr, ...)
{
va_list ap;
- va_start(ap, fmtstr);
-
led_blink_ms = blink_ms;
led_rgb = rgb;
led_mode = LED_BLINK;
+ va_start(ap, fmtstr);
while (1) {
tud_task();
panic_task(fmtstr, ap, 1000);
led_task();
}
-
va_end(ap);
}