Added the "KEvent" console command. #17
5 changed files with 124 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ idf_component_register(
|
||||||
SRCS
|
SRCS
|
||||||
"Console.c"
|
"Console.c"
|
||||||
"Commands/Log_Command.c"
|
"Commands/Log_Command.c"
|
||||||
|
"Commands/KEvent_Command.c"
|
||||||
"Commands/System_Command.c"
|
"Commands/System_Command.c"
|
||||||
INCLUDE_DIRS
|
INCLUDE_DIRS
|
||||||
"."
|
"."
|
||||||
|
|
|
||||||
97
components/Serial_Console/Commands/KEvent_Command.c
Normal file
97
components/Serial_Console/Commands/KEvent_Command.c
Normal file
|
|
@ -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.
|
||||||
|
*
|
||||||
|
* 🛡 <https://ktag.clubk.club> 🃞
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#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 <Event ID> <Event Data>\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));
|
||||||
|
}
|
||||||
23
components/Serial_Console/Commands/KEvent_Command.h
Normal file
23
components/Serial_Console/Commands/KEvent_Command.h
Normal file
|
|
@ -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.
|
||||||
|
*
|
||||||
|
* 🛡 <https://ktag.clubk.club> 🃞
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void Register_KEvent_Command(void);
|
||||||
|
|
@ -21,11 +21,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "esp_console.h"
|
#include "esp_console.h"
|
||||||
|
#include <KEvent_Command.h>
|
||||||
#include <Log_Command.h>
|
#include <Log_Command.h>
|
||||||
#include <System_Command.h>
|
#include <System_Command.h>
|
||||||
|
|
||||||
static void register_commands()
|
static void register_commands()
|
||||||
{
|
{
|
||||||
|
Register_KEvent_Command();
|
||||||
Register_Log_Command();
|
Register_Log_Command();
|
||||||
Register_System_Command();
|
Register_System_Command();
|
||||||
esp_console_register_help_command();
|
esp_console_register_help_command();
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 866f484b008b5b8dd0df0bac26bf0cd38b2d5b4e
|
Subproject commit 5aeffbcbc998ab13d2a14a1a53ddc335750e6f12
|
||||||
Loading…
Add table
Add a link
Reference in a new issue