diff options
Diffstat (limited to 'zumo')
-rw-r--r-- | zumo/.gitignore | 1 | ||||
-rw-r--r-- | zumo/pidtest/.gitignore | 1 | ||||
-rw-r--r-- | zumo/pidtest/makefile (renamed from zumo/pidtest.mk) | 4 | ||||
-rw-r--r-- | zumo/pidtest/pidtest.cpp (renamed from zumo/pidtest.cpp) | 2 | ||||
-rw-r--r-- | zumo/protocol.cpp | 18 | ||||
-rw-r--r-- | zumo/protocol.h | 3 | ||||
-rw-r--r-- | zumo/zumo.ino | 3 |
7 files changed, 24 insertions, 8 deletions
diff --git a/zumo/.gitignore b/zumo/.gitignore index e45f7a2..5761abc 100644 --- a/zumo/.gitignore +++ b/zumo/.gitignore @@ -1,2 +1 @@ *.o -pidtest diff --git a/zumo/pidtest/.gitignore b/zumo/pidtest/.gitignore new file mode 100644 index 0000000..41dc46e --- /dev/null +++ b/zumo/pidtest/.gitignore @@ -0,0 +1 @@ +pidtest diff --git a/zumo/pidtest.mk b/zumo/pidtest/makefile index 5ffe1e1..832d60b 100644 --- a/zumo/pidtest.mk +++ b/zumo/pidtest/makefile @@ -5,8 +5,8 @@ CFLAGS = LFLAGS = TARGET = pidtest -SRCS := pidtest.cpp pid.cpp -OBJS := pidtest.o pid.o +SRCS := pidtest.cpp ../pid.cpp +OBJS := pidtest.o ../pid.o all: pidtest diff --git a/zumo/pidtest.cpp b/zumo/pidtest/pidtest.cpp index b9ce50b..4d047fb 100644 --- a/zumo/pidtest.cpp +++ b/zumo/pidtest/pidtest.cpp @@ -1,7 +1,7 @@ #include <cstdio> #include <random> -#include "pid.h" +#include "../pid.h" int main() { float P, I, D; diff --git a/zumo/protocol.cpp b/zumo/protocol.cpp index fea8a00..f11827c 100644 --- a/zumo/protocol.cpp +++ b/zumo/protocol.cpp @@ -1,4 +1,6 @@ #include <Zumo32U4Motors.h> +#include <Arduino.h> +#include <Wire.h> #include "protocol.h" @@ -34,6 +36,20 @@ void apply_state(dui_state_t *state) { // TODO: print sign on OLED screen } +inline bool rx() { return !digitalRead(DUI_PINOUT_NICLA_RX); } + unsigned char uart_read() { - return 0x00; + if (rx() == true) return 0x00; // return immediately if line is idle + + delayMicroseconds(1500); // wait out start bit + + unsigned char byte = 0x00; + for (unsigned int i = 0; i < 8; i++) { + byte = (byte << 1) | rx(); + delayMicroseconds(1000); + } + + delayMicroseconds(1000); // wait out stop bit + + return byte; } diff --git a/zumo/protocol.h b/zumo/protocol.h index 662a5ce..9db7902 100644 --- a/zumo/protocol.h +++ b/zumo/protocol.h @@ -1,5 +1,8 @@ #pragma once +#define DUI_PINOUT_NICLA_TX 13 +#define DUI_PINOUT_NICLA_RX 14 + typedef enum { DUI_CMD_NULL, DUI_CMD_SIGN, diff --git a/zumo/zumo.ino b/zumo/zumo.ino index c65c2f9..e53513b 100644 --- a/zumo/zumo.ino +++ b/zumo/zumo.ino @@ -5,9 +5,6 @@ #include "protocol.h" #include "pid.h" -#define DUI_PINOUT_NICLA_TX 13 -#define DUI_PINOUT_NICLA_RX 14 - dui_state_t g_dui_target_state = { .steer = 1.0f, .speed = 1.0f, |