aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-06-02 19:14:08 +0200
committerlonkaars <loek@pipeframe.xyz>2022-06-02 19:14:08 +0200
commit595763efb64ee861f3ccf458ff35992b94f2fa3a (patch)
tree428ae0f7b474b8cb644fadcb4491ed7d8e4baffa /client
parent14779cb187dac9ed4a0b6e7645e76e78587ad024 (diff)
[WIP] stop on connection lost in dirc
Diffstat (limited to 'client')
-rw-r--r--client/main.c19
-rw-r--r--client/serial.c10
-rw-r--r--client/ui_dirc.c7
3 files changed, 18 insertions, 18 deletions
diff --git a/client/main.c b/client/main.c
index 00f686a..b5af0e8 100644
--- a/client/main.c
+++ b/client/main.c
@@ -1,15 +1,13 @@
#include "main.h"
-#include "../shared/errcatch.h"
#include "../shared/consts.h"
+#include "../shared/errcatch.h"
+#include "commands.h"
#include "serial.h"
#include "setup.h"
-#include "ui.h"
#include "time.h"
-#include "commands.h"
+#include "ui.h"
-w2_s_client_state g_w2_state = {
- .ping_received = true
-};
+w2_s_client_state g_w2_state = {.ping_received = true};
int main(int argc, char **argv) {
w2_client_setup(argc, argv);
@@ -21,12 +19,13 @@ int main(int argc, char **argv) {
if (!g_w2_state.ping_received && w2_timer_end(W2_TIMER_PING) > W2_PING_TIMEOUT) {
g_w2_state.ping_timeout = true;
- g_w2_state.connected = false;
+ g_w2_state.connected = false;
w2_errcatch_throw(W2_E_WARN_PING_TIMEOUT);
}
-
- if ((g_w2_state.ping_received && w2_timer_end(W2_TIMER_PING) > W2_PING_FREQUENCY) || g_w2_state.ping_timeout) {
- g_w2_state.ping_timeout = false;
+
+ if ((g_w2_state.ping_received && w2_timer_end(W2_TIMER_PING) > W2_PING_FREQUENCY) ||
+ g_w2_state.ping_timeout) {
+ g_w2_state.ping_timeout = false;
g_w2_state.ping_received = false;
w2_send_ping();
}
diff --git a/client/serial.c b/client/serial.c
index 743fe76..112fd81 100644
--- a/client/serial.c
+++ b/client/serial.c
@@ -2,10 +2,10 @@
#include "../shared/protocol.h"
#include "../shared/serial_parse.h"
+#include "commands.h"
#include "main.h"
#include "serial.h"
#include "time.h"
-#include "commands.h"
void w2_serial_main() {
int temp;
@@ -20,13 +20,11 @@ void w2_cmd_ping_rx(w2_s_bin *data) {
g_w2_state.ping = w2_timer_end(W2_TIMER_PING);
g_w2_state.ping_received = true;
- g_w2_state.ping_timeout = false;
- g_w2_state.connected = true;
+ g_w2_state.ping_timeout = false;
+ g_w2_state.connected = true;
}
-void w2_cmd_ping_tx(w2_s_bin *data) {
- w2_send_bin(data);
-}
+void w2_cmd_ping_tx(w2_s_bin *data) { w2_send_bin(data); }
void w2_cmd_expt_tx(w2_s_bin *data) {}
void w2_cmd_mode_tx(w2_s_bin *data) {
diff --git a/client/ui_dirc.c b/client/ui_dirc.c
index 675913a..ed69cd2 100644
--- a/client/ui_dirc.c
+++ b/client/ui_dirc.c
@@ -81,7 +81,9 @@ void w2_ui_dirc_paint(int left, int right) {
"\n"
" <q> <w> <e> forward\n"
" <a> <s> <d> backward\n"
- "left both right\n");
+ "left both right\n"
+ "\n"
+ "<space> send dirc mode command");
}
void w2_ui_dirc(bool first) {
@@ -96,6 +98,7 @@ void w2_ui_dirc(bool first) {
if (ch == 'd' || ch == 's') lb++;
if (ch == 'q' || ch == 'w') rf++;
if (ch == 'a' || ch == 's') rb++;
+ if (ch == ' ') w2_send_mode(W2_M_DIRC);
}
int drive_l = w2_dirc_motor_l(lf, lb);
@@ -104,6 +107,6 @@ void w2_ui_dirc(bool first) {
drive_l += drive_r * W2_DIRC_STP;
drive_r += drive_l * W2_DIRC_STP;
- // w2_send_dirc(drive_l, drive_r);
+ w2_send_dirc(drive_l, drive_r);
w2_ui_dirc_paint(drive_l, drive_r);
}