From e3061bc44382205fc0cd9501ec796b731881bbc3 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Sat, 21 Feb 2026 15:54:45 -0600 Subject: [PATCH 1/3] SystemK bugfix. --- components/SystemK | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/SystemK b/components/SystemK index 45df6f9..866f484 160000 --- a/components/SystemK +++ b/components/SystemK @@ -1 +1 @@ -Subproject commit 45df6f952abb82c2825a8bb16783c10a150adeba +Subproject commit 866f484b008b5b8dd0df0bac26bf0cd38b2d5b4e -- 2.47.3 From 8547b74c3e28b39938dc5593a52d7c9f57082167 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Sun, 1 Mar 2026 16:09:51 -0600 Subject: [PATCH 2/3] Added KEvent console command. --- components/Serial_Console/CMakeLists.txt | 1 + .../Serial_Console/Commands/KEvent_Command.c | 97 +++++++++++++++++++ .../Serial_Console/Commands/KEvent_Command.h | 23 +++++ components/Serial_Console/Console.c | 2 + components/SystemK | 2 +- 5 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 components/Serial_Console/Commands/KEvent_Command.c create mode 100644 components/Serial_Console/Commands/KEvent_Command.h diff --git a/components/Serial_Console/CMakeLists.txt b/components/Serial_Console/CMakeLists.txt index 94c73e9..e2c861d 100644 --- a/components/Serial_Console/CMakeLists.txt +++ b/components/Serial_Console/CMakeLists.txt @@ -2,6 +2,7 @@ idf_component_register( SRCS "Console.c" "Commands/Log_Command.c" + "Commands/KEvent_Command.c" "Commands/System_Command.c" INCLUDE_DIRS "." diff --git a/components/Serial_Console/Commands/KEvent_Command.c b/components/Serial_Console/Commands/KEvent_Command.c new file mode 100644 index 0000000..4c540fa --- /dev/null +++ b/components/Serial_Console/Commands/KEvent_Command.c @@ -0,0 +1,97 @@ +/* + * This program source code file is part of the KTag project, a DIY laser tag + * game with customizable features and wide interoperability. + * + * 🛡 🃞 + * + * Copyright © 2026 Joseph P. Kearney and the KTag developers. + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more + * details. + * + * There should be a copy of the GNU Affero General Public License in the LICENSE + * file in the root of this repository. If not, see . + */ + +#include +#include +#include +#include +#include +#include "esp_console.h" +#include "esp_log.h" +#include "SystemK.h" + +uint32_t parse_uint32(const char *str, bool *ok) { + char *end; + errno = 0; + unsigned long val = strtoul(str, &end, 10); + + if (errno != 0 || end == str || *end != '\0' || val > UINT32_MAX) { + *ok = false; + return 0; + } + + *ok = true; + return (uint32_t)val; +} + +static void print_usage(void) +{ + printf( + "Usage:\n" + " KEvent \n" + " (Note that IDs may be SystemK version-dependant.)\n"); +} + +static int cmd_KEvent(int argc, char **argv) +{ + KEvent_T event; + uint32_t data; + + if (argc < 2) + { + print_usage(); + return 0; + } + + if (Parse_KEvent_ID(argv[1], &event) == SYSTEMK_RESULT_SUCCESS) + { + bool ok; + data = parse_uint32(argv[2], &ok); + if (ok == true) + { + event.Data = (void *)data; + Post_KEvent(&event); + return 0; + } + else + { + printf("ERROR: Couldn't parse data!"); + return(-1); + } + } + else + { + printf("ERROR: Couldn't parse SystemK event!"); + return(-1); + } +} + +void Register_KEvent_Command(void) +{ + const esp_console_cmd_t cmd = { + .command = "KEvent", + .help = "Send arbitrary KEvents by ID", + .func = &cmd_KEvent, + }; + + ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); +} \ No newline at end of file diff --git a/components/Serial_Console/Commands/KEvent_Command.h b/components/Serial_Console/Commands/KEvent_Command.h new file mode 100644 index 0000000..6983267 --- /dev/null +++ b/components/Serial_Console/Commands/KEvent_Command.h @@ -0,0 +1,23 @@ +/* + * This program source code file is part of the KTag project, a DIY laser tag + * game with customizable features and wide interoperability. + * + * 🛡 🃞 + * + * Copyright © 2026 Joseph P. Kearney and the KTag developers. + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more + * details. + * + * There should be a copy of the GNU Affero General Public License in the LICENSE + * file in the root of this repository. If not, see . + */ + +void Register_KEvent_Command(void); diff --git a/components/Serial_Console/Console.c b/components/Serial_Console/Console.c index 80e59d5..17ba64d 100644 --- a/components/Serial_Console/Console.c +++ b/components/Serial_Console/Console.c @@ -21,11 +21,13 @@ */ #include "esp_console.h" +#include #include #include static void register_commands() { + Register_KEvent_Command(); Register_Log_Command(); Register_System_Command(); esp_console_register_help_command(); diff --git a/components/SystemK b/components/SystemK index 866f484..5aeffbc 160000 --- a/components/SystemK +++ b/components/SystemK @@ -1 +1 @@ -Subproject commit 866f484b008b5b8dd0df0bac26bf0cd38b2d5b4e +Subproject commit 5aeffbcbc998ab13d2a14a1a53ddc335750e6f12 -- 2.47.3 From a65c53f4b2f2c61adc2621cd1ad384d58dde2b06 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Sun, 1 Mar 2026 16:17:04 -0600 Subject: [PATCH 3/3] Cleanup --- components/Serial_Console/Commands/KEvent_Command.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/components/Serial_Console/Commands/KEvent_Command.c b/components/Serial_Console/Commands/KEvent_Command.c index 4c540fa..455b41b 100644 --- a/components/Serial_Console/Commands/KEvent_Command.c +++ b/components/Serial_Console/Commands/KEvent_Command.c @@ -29,12 +29,14 @@ #include "esp_log.h" #include "SystemK.h" -uint32_t parse_uint32(const char *str, bool *ok) { +static uint32_t parse_uint32(const char *str, bool *ok) +{ char *end; errno = 0; unsigned long val = strtoul(str, &end, 10); - if (errno != 0 || end == str || *end != '\0' || val > UINT32_MAX) { + if (errno != 0 || end == str || *end != '\0' || val > UINT32_MAX) + { *ok = false; return 0; } @@ -48,7 +50,7 @@ static void print_usage(void) printf( "Usage:\n" " KEvent \n" - " (Note that IDs may be SystemK version-dependant.)\n"); + " (Note that IDs may be SystemK version-dependent.)\n"); } static int cmd_KEvent(int argc, char **argv) @@ -75,13 +77,13 @@ static int cmd_KEvent(int argc, char **argv) else { printf("ERROR: Couldn't parse data!"); - return(-1); + return (-1); } } else { printf("ERROR: Couldn't parse SystemK event!"); - return(-1); + return (-1); } } -- 2.47.3