summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-05-27 11:40:05 +0200
committerlonkaars <loek@pipeframe.xyz>2022-05-27 11:40:05 +0200
commit3bbe41a04b6053a3a3a902384850cfcbd38b0686 (patch)
tree1385ae4d9ee438a888e1abf4e4e6ac1d6e1801f5
parentbfa494588da0def96c42577e284c6d8990eb31f2 (diff)
move things around and add todo's to robot readme
-rw-r--r--robot/io.h2
-rw-r--r--robot/readme.md20
-rw-r--r--shared/bool.h9
-rw-r--r--shared/io.h59
-rw-r--r--shared/protocol.h56
5 files changed, 82 insertions, 64 deletions
diff --git a/robot/io.h b/robot/io.h
index be0e9b9..64ce293 100644
--- a/robot/io.h
+++ b/robot/io.h
@@ -2,7 +2,7 @@
/** @file io.h */
-#include "../shared/protocol.h"
+#include "../shared/io.h"
/** @brief i/o module main */
void w2_io_main();
diff --git a/robot/readme.md b/robot/readme.md
index b27c06f..25e730f 100644
--- a/robot/readme.md
+++ b/robot/readme.md
@@ -72,15 +72,15 @@ what they're supposed to do:
this list will probably get updated from time to time:
-- modules shouldn't create any global state variables, they should use `static`
- variables instead.
-- modules are run cyclically, so they shouldn't take more than
+- logic modules shouldn't create any global state variables if possible, they
+ should use `static` variables instead
+- logic modules are run cyclically, so they shouldn't take more than
`W2_MAX_MODULE_CYCLE_MS` to execute (this is an arbitrary number, and may be
- changed).
+ changed)
- documentation comments should follow the [javadoc-style doxygen
format](https://wiki.scilab.org/Doxygen%20documentation%20Examples) and be
- placed in header (.h) files if possible. this only applies to public members
- (e.g. no local variables or module-internal code).
+ placed in header (.h) files. this only applies to public members (e.g. no
+ local variables or module-internal code)
- code style is mostly handled by `clang-format` and `clang-tidy`, but you
should still follow these naming conventions (`<angle brackets>` indicate
placeholders):
@@ -93,15 +93,15 @@ this list will probably get updated from time to time:
|enum|`w2_e_<name>`|`w2_e_errorcodes`; `w2_e_serial_commands`|
this again only applies to public members. local variables should still have
- short descriptive names, but shouldn't be prefixed with `w2_*`.
+ short descriptive names, but shouldn't be prefixed with `w2_*`
- arbitrary numbers should be aliased to `#define` statements or `enum`s if
- part of a series.
+ part of a series
- general constants should be placed in `consts.h`
- don't import `<pololu/orangutan.h>` directly, instead use
`"orangutan_shim.h"` to keep code compatible with the simulator
- don't use `<stdbool.h>`, instead use `"../shared/protocol.h"`. this makes
sure that `bool` values are equal to `uint8_t`. they're functionally
- identical.
+ identical
## todo
@@ -119,6 +119,8 @@ global todo:
placing the robot and pressing a button (maybe make this a seperate mode)
- [ ] create labeled timer functions like nodejs `console.time()` and
`console.timeEnd()` (use for serial read timeout constraint)
+- [ ] `serial_parse` doesn't properly handle escaped `0xff` bytes in listen
+ mode
### hypervisor
diff --git a/shared/bool.h b/shared/bool.h
new file mode 100644
index 0000000..9ea97f7
--- /dev/null
+++ b/shared/bool.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include <stdint.h>
+
+/** @file bool.h */
+
+typedef uint8_t bool;
+#define false 0 /* NOLINT */
+#define true 1 /* NOLINT */
diff --git a/shared/io.h b/shared/io.h
new file mode 100644
index 0000000..584ad1e
--- /dev/null
+++ b/shared/io.h
@@ -0,0 +1,59 @@
+#pragma once
+
+#include <stdio.h>
+
+#include "bool.h"
+
+#pragma pack(push, 1)
+
+/** momentary button input struct */
+typedef struct {
+ bool pressed;
+} w2_s_i_push;
+
+/** qtr contrast sensor input struct */
+typedef struct {
+ uint16_t range;
+} w2_s_i_contrast;
+
+/** distance sensor input struct */
+typedef struct {
+ uint16_t detection;
+} w2_s_i_distance;
+
+/** battery input struct */
+typedef struct {
+ uint16_t charge_level;
+} w2_s_i_battery;
+
+/** motor output struct */
+typedef struct {
+ int16_t speed;
+} w2_s_o_motor;
+
+/** underside led output struct */
+typedef struct {
+ bool on;
+} w2_s_o_led;
+
+/** lcd output struct */
+typedef struct {
+ char text[16];
+} w2_s_o_display;
+
+/** struct containing all i/o */
+typedef struct {
+ w2_s_i_push button[5];
+ w2_s_i_contrast qtr[5];
+ w2_s_i_distance front_distance;
+ w2_s_i_distance side_distance;
+ w2_s_i_battery battery;
+
+ w2_s_o_motor motor_left;
+ w2_s_o_motor motor_right;
+ w2_s_o_led led_red;
+ w2_s_o_led led_green;
+ w2_s_o_display lcd;
+} w2_s_io_all;
+
+#pragma pack(pop)
diff --git a/shared/protocol.h b/shared/protocol.h
index 05cde03..2e1e4ea 100644
--- a/shared/protocol.h
+++ b/shared/protocol.h
@@ -6,11 +6,9 @@
#include <stdlib.h>
#include "bin.h"
+#include "bool.h"
#include "consts.h"
-
-typedef uint8_t bool;
-#define false 0 /* NOLINT */
-#define true 1 /* NOLINT */
+#include "io.h"
#define W2_SERIAL_START_BYTE 0xff
@@ -54,56 +52,6 @@ typedef enum {
#pragma pack(push, 1)
-/** momentary button input struct */
-typedef struct {
- bool pressed;
-} w2_s_i_push;
-
-/** qtr contrast sensor input struct */
-typedef struct {
- uint16_t range;
-} w2_s_i_contrast;
-
-/** distance sensor input struct */
-typedef struct {
- uint16_t detection;
-} w2_s_i_distance;
-
-/** battery input struct */
-typedef struct {
- uint16_t charge_level;
-} w2_s_i_battery;
-
-/** motor output struct */
-typedef struct {
- int16_t speed;
-} w2_s_o_motor;
-
-/** underside led output struct */
-typedef struct {
- bool on;
-} w2_s_o_led;
-
-/** lcd output struct */
-typedef struct {
- char text[16];
-} w2_s_o_display;
-
-/** struct containing all i/o */
-typedef struct {
- w2_s_i_push button[5];
- w2_s_i_contrast qtr[5];
- w2_s_i_distance front_distance;
- w2_s_i_distance side_distance;
- w2_s_i_battery battery;
-
- w2_s_o_motor motor_left;
- w2_s_o_motor motor_right;
- w2_s_o_led led_red;
- w2_s_o_led led_green;
- w2_s_o_display lcd;
-} w2_s_io_all;
-
typedef struct {
uint8_t opcode;
uint8_t id;