From 62715093e446d952bbc3fa82fdb65deacd576be2 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Wed, 1 Dec 2021 23:42:19 -0700 Subject: Add a controller shell. This adds a mini shell to the tcp server that allows the user to modify the current state. Commands are in the form: set [int_attribute] (=|+=|-=) [number] set [bool_attribute] (on|off|toggle) print end for example: set brightness += 5 set power on print end --- include/sockbuf.h | 39 +++++++++++++++++++++++++++++++++++++++ include/ws2812b_writer.h | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 include/sockbuf.h (limited to 'include') diff --git a/include/sockbuf.h b/include/sockbuf.h new file mode 100644 index 0000000..664e134 --- /dev/null +++ b/include/sockbuf.h @@ -0,0 +1,39 @@ +#pragma once +#ifndef SOCKBUF_H_ +#define SOCKBUF_H_ + +#include + +#define SOCKBUF_BUFLEN 128 +#define SOCKBUF_CLOSED 1 + +typedef struct { + uint8_t buf[SOCKBUF_BUFLEN]; + + uint8_t next; + uint8_t last; + + int socket; + uint8_t flags; +} sockbuf_t; + +/* Initialize a sockbuf from the provided file descriptor. */ +sockbuf_t* init_sockbuf(sockbuf_t* sockbuf, int socket); + +/* Writes a null-terminated string to the socket. */ +void sockbuf_write(sockbuf_t* sockbuf, const char* value); + +/* + * Return the next character of the sockbuf or -1 if EOF was reached. + * + * This does not advance the pointer. + */ +int peek_char(sockbuf_t* sockbuf); + +/* + * Return and consume the next character of the sockbuf or -1 if EOF was + * reached. + */ +int get_char(sockbuf_t* sockbuf); + +#endif /* SOCKBUF_H_ */ diff --git a/include/ws2812b_writer.h b/include/ws2812b_writer.h index 2252230..9da9345 100644 --- a/include/ws2812b_writer.h +++ b/include/ws2812b_writer.h @@ -11,7 +11,7 @@ typedef struct { struct { uint32_t time; - int32_t timetick; + int timetick; uint8_t brightness; uint8_t off; uint8_t n_snow; -- cgit