aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2025-12-07 13:04:02 -0700
committerJosh Rahm <joshuarahm@gmail.com>2025-12-07 13:04:02 -0700
commit42f4c42676d42619d530db27e7a2a0b76fbf9253 (patch)
tree01ebd66f55aeb9a7c2113ebde3508a2cb1f01f5a /include
parent3f8b6e6f34275bdba501e3b1cddab43331b6f569 (diff)
downloadesp32-ws2812b-42f4c42676d42619d530db27e7a2a0b76fbf9253.tar.gz
esp32-ws2812b-42f4c42676d42619d530db27e7a2a0b76fbf9253.tar.bz2
esp32-ws2812b-42f4c42676d42619d530db27e7a2a0b76fbf9253.zip
Clean up how parameters work.
Formalize a poor-man's Parameter "typeclass" and create "instances". This makes things way less ad-hoc.
Diffstat (limited to 'include')
-rw-r--r--include/param.h27
-rw-r--r--include/sockbuf.h6
-rw-r--r--include/ws2812b_writer.h4
3 files changed, 34 insertions, 3 deletions
diff --git a/include/param.h b/include/param.h
new file mode 100644
index 0000000..b66b1b1
--- /dev/null
+++ b/include/param.h
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <stdint.h>
+#include "sockbuf.h"
+
+typedef struct httpd_req httpd_req_t;
+
+typedef uint32_t color_int_t;
+
+#define DECL_PARAMETER_INSTANCE(ty) \
+ void handle_option__##ty(const char* attr, sockbuf_t* sockbuf, ty* ptr); \
+ size_t serialize_to_json__##ty( \
+ char** out, size_t len, const char* attr, const char* display_name, \
+ ty value); \
+ void http_handle__##ty(httpd_req_t* req, ty* val); \
+ void print__##ty(sockbuf_t* sockbuf, const char* attr, ty v);
+
+#define cmd_handle(ty) handle_option__##ty
+#define http_handle(ty) http_handle__##ty
+#define serialize_to_json(ty) serialize_to_json__##ty
+#define print(ty) print__##ty
+
+DECL_PARAMETER_INSTANCE(uint8_t);
+DECL_PARAMETER_INSTANCE(bool);
+DECL_PARAMETER_INSTANCE(uint32_t);
+DECL_PARAMETER_INSTANCE(color_int_t);
+DECL_PARAMETER_INSTANCE(int);
diff --git a/include/sockbuf.h b/include/sockbuf.h
index 664e134..0a11c4f 100644
--- a/include/sockbuf.h
+++ b/include/sockbuf.h
@@ -3,6 +3,7 @@
#define SOCKBUF_H_
#include <inttypes.h>
+#include <stdlib.h>
#define SOCKBUF_BUFLEN 128
#define SOCKBUF_CLOSED 1
@@ -36,4 +37,9 @@ int peek_char(sockbuf_t* sockbuf);
*/
int get_char(sockbuf_t* sockbuf);
+/*
+ * Reads a token from the sockbuf. Tokens are separated by spaces.
+ */
+char* read_token(sockbuf_t* sockbuf, char* into, size_t sz);
+
#endif /* SOCKBUF_H_ */
diff --git a/include/ws2812b_writer.h b/include/ws2812b_writer.h
index b750da6..b0e53d8 100644
--- a/include/ws2812b_writer.h
+++ b/include/ws2812b_writer.h
@@ -3,15 +3,13 @@
#define WS2812B_WRITER_H_
#include "drv/ws2812b.h"
+#include "param.h"
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
-
extern const int NUMBER_PARAMS;
-typedef uint32_t color_int_t;
-
typedef struct {
#define STATE_PARAM(t, n, ...) t n;
#include "state_params.i"