aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-05-27 08:23:21 +0200
committerlonkaars <loek@pipeframe.xyz>2024-05-27 08:23:21 +0200
commitf4868604384908a7477cbb4b544c6ee7aac2a883 (patch)
tree53b7df9dd58d49db5d3640f01a4cc600d088f655
parentfb37e47bc13912a8d94bf1b3b7aa8456601f317a (diff)
quickly implement some pseudo handlers for the remaining commands
-rw-r--r--client/cmd.cpp30
-rw-r--r--client/cmd.h30
-rw-r--r--proto/puzbusv1.h19
-rw-r--r--shared/busaddr.h20
4 files changed, 84 insertions, 15 deletions
diff --git a/client/cmd.cpp b/client/cmd.cpp
index a098a14..736cf12 100644
--- a/client/cmd.cpp
+++ b/client/cmd.cpp
@@ -3,9 +3,12 @@
#include <string.h>
#include "cmd.h"
+#include "puzbusv1.h"
#include "sock.h"
#include "parse.h"
+#include "../shared/busaddr.h"
+
char* consume_token(char* input, const char* ifs) {
strtok(input, ifs);
return strtok(NULL, "\0");
@@ -61,3 +64,30 @@ void cmd_send(char* addr_str) {
free(data);
}
+void cmd_status(char*) {
+ const char msg[] = {
+ PB_CMD_READ,
+ 0x00, // addr 0 = global state
+ };
+ i2c_send(BUSADDR_MAIN, msg, sizeof(msg));
+ // NOTE: the reply handler will automatically print the state once it's
+ // received
+}
+
+void cmd_reset(char*) {
+ const char msg[] = {
+ PB_CMD_WRITE,
+ 0x00,
+ PB_GS_IDLE,
+ };
+ i2c_send(BUSADDR_MAIN, msg, sizeof(msg));
+}
+
+void cmd_ls(char*) {
+ return;
+ const char msg[] = {
+ PB_CMD_READ,
+ // TODO: which address is this?
+ };
+ i2c_send(BUSADDR_MAIN, msg, sizeof(msg));
+}
diff --git a/client/cmd.h b/client/cmd.h
index 9d20328..30bcbeb 100644
--- a/client/cmd.h
+++ b/client/cmd.h
@@ -40,21 +40,21 @@ static const struct cmd cmds[] = {
.name = "send",
.info = "[debug] send raw message",
},
- // {
- // .handle = cmd_status,
- // .name = "status",
- // .info = "show global puzzle box state (main controller state)",
- // },
- // {
- // .handle = cmd_reset,
- // .name = "reset",
- // .info = "reset entire game state",
- // },
- // {
- // .handle = cmd_ls,
- // .name = "ls",
- // .info = "list connected puzzle modules",
- // },
+ {
+ .handle = cmd_status,
+ .name = "status",
+ .info = "show global puzzle box state (main controller state)",
+ },
+ {
+ .handle = cmd_reset,
+ .name = "reset",
+ .info = "reset entire game state",
+ },
+ {
+ .handle = cmd_ls,
+ .name = "ls",
+ .info = "list connected puzzle modules",
+ },
};
static const size_t cmds_length = sizeof(cmds) / sizeof(cmds[0]);
diff --git a/proto/puzbusv1.h b/proto/puzbusv1.h
index 0985b2b..9f4f8e5 100644
--- a/proto/puzbusv1.h
+++ b/proto/puzbusv1.h
@@ -64,6 +64,25 @@ void pb_read_reset(struct pb_msg * target);
*/
bool pb_write(const struct pb_msg * target, char ** buf, size_t * buf_sz);
+/**
+ * \brief I^2^C puzzle bus command types
+ *
+ * The first byte of a puzzle bus message's data indicates the command type.
+ */
+enum pb_cmd {
+ PB_CMD_READ, //!< read a puzzle module property
+ PB_CMD_WRITE, //!< write to a puzzle module property
+ // PB_CMD_UPDATE, //!< request an update
+};
+
+/** \brief Puzzle bus global states */
+enum pb_global_state {
+ PB_GS_NOINIT, //!< uninitialized (only used by puzzle modules)
+ PB_GS_IDLE, //!< puzzle not started yet
+ PB_GS_PLAYING, //!< puzzle actively being solved
+ PB_GS_SOLVED, //!< puzzle completed
+};
+
#ifdef __cplusplus
}
#endif
diff --git a/shared/busaddr.h b/shared/busaddr.h
new file mode 100644
index 0000000..5879afe
--- /dev/null
+++ b/shared/busaddr.h
@@ -0,0 +1,20 @@
+#pragma once
+
+/** \file bus address reference */
+
+// Adafruit NeoTrellis modules
+#define BUSADDR_ADA_NEO_1 0x2E
+#define BUSADDR_ADA_NEO_2 0x2F
+#define BUSADDR_ADA_NEO_3 0x30
+#define BUSADDR_ADA_NEO_4 0x32
+
+// TODO: ???
+#define BUSADDR_MOD_NEOTRELLIS 0
+#define BUSADDR_MOD_SOFTWARE 0
+#define BUSADDR_MOD_HARDWARE 0
+#define BUSADDR_MOD_VAULT 0
+#define BUSADDR_MOD_AUTOMATION 0
+
+// main controller
+#define BUSADDR_MAIN 0x00
+