From 529fb413f1d01174dfb0cef1aee35e70bad763bf Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 26 Jun 2024 00:03:50 +0100 Subject: [PATCH] implement toggle --- include/vmr.h | 2 ++ src/vmrcli.c | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/vmr.h b/include/vmr.h index 9b87aa1..95b1f0c 100644 --- a/include/vmr.h +++ b/include/vmr.h @@ -21,6 +21,8 @@ long version(T_VBVMR_INTERFACE *iVMR, long *version); bool pdirty(T_VBVMR_INTERFACE *iVMR); long get_parameter_float(T_VBVMR_INTERFACE *iVMR, char *param, float *f); long get_parameter_string(T_VBVMR_INTERFACE *iVMR, char *param, char *s); +long set_parameter_float(T_VBVMR_INTERFACE *iVMR, char *param, float val); +long set_parameter_string(T_VBVMR_INTERFACE *iVMR, char *param, char *s); long set_parameters(T_VBVMR_INTERFACE *iVMR, char *command); bool mdirty(T_VBVMR_INTERFACE *iVMR); diff --git a/src/vmrcli.c b/src/vmrcli.c index 2d7a3df..e191256 100644 --- a/src/vmrcli.c +++ b/src/vmrcli.c @@ -168,10 +168,16 @@ void interactive(T_VBVMR_INTERFACE *vmr) void parse_command(T_VBVMR_INTERFACE *vmr, char *command) { - printf("Parsing %s\n", command); if (command[0] == '!') /* toggle */ { - puts("Toggle"); + command++; + struct result res = {.type = FLOAT_T}; + + get(vmr, command, &res); + if (res.type == FLOAT_T) + { + set_parameter_float(vmr, command, 1 - res.val.f); + } return; } @@ -190,10 +196,10 @@ void parse_command(T_VBVMR_INTERFACE *vmr, char *command) printf("%.2f\n", res.val.f); break; case STRING_T: - printf("%s\n", res.val.s); + puts(res.val.s); break; default: - printf("Unknown result..."); + fputs("Unknown result...", stderr); break; } } @@ -201,6 +207,7 @@ void parse_command(T_VBVMR_INTERFACE *vmr, char *command) struct result *get(T_VBVMR_INTERFACE *vmr, char *command, struct result *res) { + clear_dirty(vmr); if (get_parameter_float(vmr, command, &res->val.f) != 0) { res->type = STRING_T;