first working version
This commit is contained in:
14
test/cmd_parser/helpers/inc/led_cmd.h
Normal file
14
test/cmd_parser/helpers/inc/led_cmd.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "main.h"
|
||||
#include "cmd_parser.h"
|
||||
|
||||
/*
|
||||
Usage: led set|get [-p PNUM | --power=PNUM] [-w CHOICES | --which=CHOICES] [-m COICES | --mode=CHOICES]
|
||||
-p, --power set or get power 0-100
|
||||
-w, --which set or get specific leds [Atop, Abot, Btop, Bbot, Ctop, Cbot, all]
|
||||
-m, --mode set or get mode of operation [allways_on, scan]
|
||||
*/
|
||||
// cmd_parser_t led_cmd;
|
||||
|
||||
result_t parse_callback(char key, char *arg);
|
||||
@@ -1,42 +0,0 @@
|
||||
#include "main.h"
|
||||
#include "cmd_parser.h"
|
||||
|
||||
/*
|
||||
Usage: led set|get [-p PNUM | --power=PNUM] [-w CHOICES | --which=CHOICES] [-m COICES | --mode=CHOICES]
|
||||
-p, --power set or get power 0-100
|
||||
-w, --which set or get specific leds [Atop, Abot, Btop, Bbot, Ctop, Cbot, all]
|
||||
-m, --mode set or get mode of operation [allways_on, scan]
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
get,
|
||||
set,
|
||||
} led_action_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
Atop = (1 << 0),
|
||||
Abot = (1 << 1),
|
||||
Btop = (1 << 2),
|
||||
Bbot = (1 << 3),
|
||||
Ctop = (1 << 4),
|
||||
Cbot = (1 << 5),
|
||||
all = 0xFF,
|
||||
} led_leds_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
allways_on,
|
||||
scan,
|
||||
} led_mode_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
led_action_t action;
|
||||
uint8_t power;
|
||||
led_leds_t leds;
|
||||
led_mode_t mode;
|
||||
} led_option_t;
|
||||
|
||||
void led_parse_callback(char key, const char *text);
|
||||
62
test/cmd_parser/helpers/src/led_cmd.c
Normal file
62
test/cmd_parser/helpers/src/led_cmd.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "led_cmd.h"
|
||||
|
||||
enum {set, get};
|
||||
|
||||
option_t set_options[] = {
|
||||
{
|
||||
.opt_id = 'p',
|
||||
.name = "power",
|
||||
.flags = SINGLE_VALE,
|
||||
.description = "sets the power of the light",
|
||||
},
|
||||
|
||||
{
|
||||
.opt_id = 'l',
|
||||
.name = "led",
|
||||
.flags = MULTI_VALUE,
|
||||
.description = "diode selection. OPTIONS = [Atop, Abot, Btop, Bbot, Ctop, Cbot, all]",
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
option_t get_options[] = {
|
||||
{
|
||||
.opt_id = 'p',
|
||||
.name = "power",
|
||||
.flags = NO_VALUE,
|
||||
.description = "gets the power of the light",
|
||||
},
|
||||
|
||||
{
|
||||
.opt_id = 'l',
|
||||
.name = "led",
|
||||
.flags = MULTI_VALUE,
|
||||
.description = "diode selection. OPTIONS = [Atop, Abot, Btop, Bbot, Ctop, Cbot, all]",
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
argument_t arguments[] = {
|
||||
{
|
||||
.name = "set",
|
||||
.arg_id = set,
|
||||
.options = set_options,
|
||||
.opt_num = sizeof(set_options) / (sizeof(set_options[0])),
|
||||
.description = "allows to set operating parameters",
|
||||
},
|
||||
{
|
||||
.name = "get",
|
||||
.arg_id = get,
|
||||
.options = get_options,
|
||||
.opt_num = sizeof(get_options) / (sizeof(get_options[0])),
|
||||
.description = "allows to get operating parameters",
|
||||
},
|
||||
};
|
||||
|
||||
cmd_parser_t led_cmd = {
|
||||
.name = "led",
|
||||
.arguments = arguments,
|
||||
.arg_num = sizeof(arguments) / sizeof(arguments[0]),
|
||||
.description = "allows to controll and check leds",
|
||||
.cmd_parser = parse_callback,
|
||||
};
|
||||
Reference in New Issue
Block a user