summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/commands.c33
-rw-r--r--client/commands.h8
-rw-r--r--client/ui_dirc.c69
3 files changed, 72 insertions, 38 deletions
diff --git a/client/commands.c b/client/commands.c
index 18373f6..778e9c1 100644
--- a/client/commands.c
+++ b/client/commands.c
@@ -15,42 +15,41 @@ void w2_send_bin(w2_s_bin *data) {
}
}
-w2_s_bin *w2_send_mode(w2_e_mode mode) {
- W2_CREATE_MSG_BIN(w2_s_cmd_mode_rx, msg, msg_bin);
-
- msg->opcode = W2_CMD_MODE | W2_CMDDIR_RX;
- msg->mode = mode;
+void w2_send_info() {
+ W2_CREATE_MSG_BIN(w2_s_cmd_info_rx, msg, msg_bin);
+ msg->opcode = W2_CMD_INFO | W2_CMDDIR_RX;
w2_send_bin(msg_bin);
free(msg_bin);
- return NULL;
}
-w2_s_bin *w2_send_dirc(uint16_t left, uint16_t right) {
+void w2_send_dirc(uint16_t left, uint16_t right) {
W2_CREATE_MSG_BIN(w2_s_cmd_dirc_rx, msg, msg_bin);
msg->opcode = W2_CMD_DIRC | W2_CMDDIR_RX;
msg->left = w2_bin_hton16(left);
msg->right = w2_bin_hton16(right);
- w2_send_bin(msg_bin);
- free(msg_bin);
- return NULL;
-}
-w2_s_bin *w2_send_info() {
- W2_CREATE_MSG_BIN(w2_s_cmd_info_rx, msg, msg_bin);
- msg->opcode = W2_CMD_INFO | W2_CMDDIR_RX;
w2_send_bin(msg_bin);
free(msg_bin);
- return NULL;
}
-w2_s_bin *w2_send_ping() {
+void w2_send_ping() {
+ g_w2_state.ping_id = (uint8_t)rand();
W2_CREATE_MSG_BIN(w2_s_cmd_ping_rx, msg, msg_bin);
msg->opcode = W2_CMD_PING | W2_CMDDIR_RX;
msg->id = g_w2_state.ping_id;
+
w2_send_bin(msg_bin);
free(msg_bin);
w2_timer_start(W2_TIMER_PING);
- return NULL;
+}
+
+void w2_send_mode(w2_e_mode mode) {
+ W2_CREATE_MSG_BIN(w2_s_cmd_mode_rx, msg, msg_bin);
+ msg->opcode = W2_CMD_MODE | W2_CMDDIR_RX;
+ msg->mode = mode;
+
+ w2_send_bin(msg_bin);
+ free(msg_bin);
}
diff --git a/client/commands.h b/client/commands.h
index cb01189..5a12424 100644
--- a/client/commands.h
+++ b/client/commands.h
@@ -4,7 +4,7 @@
#include "../shared/modes.h"
#include "serial.h"
-w2_s_bin *w2_send_mode(w2_e_mode mode);
-w2_s_bin *w2_send_dirc(uint16_t left, uint16_t right);
-w2_s_bin *w2_send_info();
-w2_s_bin *w2_send_ping();
+void w2_send_info();
+void w2_send_ping();
+void w2_send_mode(w2_e_mode mode);
+void w2_send_dirc(uint16_t left, uint16_t right);
diff --git a/client/ui_dirc.c b/client/ui_dirc.c
index dcd4423..7720a4c 100644
--- a/client/ui_dirc.c
+++ b/client/ui_dirc.c
@@ -3,21 +3,16 @@
#include "commands.h"
#include "ui.h"
-void w2_ui_bar_graph(unsigned int percent) {
- unsigned int width = g_w2_ui_width - 7;
- char bar[width];
- for (unsigned int i = 0; i < width - 2; i++) {
- bar[i + 1] = i > (width - 2) * percent / 100 ? ' ' : '*';
- }
- bar[0] = '|';
- bar[width - 1] = '|';
- mvaddnstr(4, 7, bar, width);
-}
-
+/** decay modifier */
#define W2_DIRC_MOD ((double)0.95)
-#define W2_DIRC_ADD ((double)13.0)
-#define W2_DIRC_PAD ((double)1.10)
-#define W2_DIRC_SPL ((unsigned int)20)
+/** add value per key press */
+#define W2_DIRC_ADD ((double)17.0)
+/** padding */
+#define W2_DIRC_PAD ((double)3.00)
+/** average samples */
+#define W2_DIRC_SPL ((unsigned int)14)
+/** steering padding */
+#define W2_DIRC_STP ((double)0.2)
int w2_avg(int *samples, unsigned int sample_count) {
double total = 0;
@@ -49,6 +44,46 @@ W2_DIRC_MOTOR_DRIVER(r);
void w2_ui_dirc_init() { w2_send_mode(W2_M_DIRC); }
+void w2_ui_bar_graph(unsigned int y, unsigned int x, unsigned int width, double value) {
+ char temp[width];
+ temp[0] = '|';
+ temp[width - 1] = '|';
+ for (unsigned int i = 0; i < width - 2; i++) temp[i + 1] = i < width * value ? '*' : ' ';
+
+ mvaddnstr(y, x, temp, width);
+}
+
+void w2_ui_bar_graph_pm(unsigned int y, unsigned int x, unsigned int width, double value) {
+ char temp[width];
+ temp[0] = '|';
+ temp[width - 1] = '|';
+ width -= 2;
+ unsigned int hw = width / 2;
+ if (value >= 0) {
+ for (unsigned int i = 0; i < width; i++)
+ temp[i + 1] = i < hw ? ' ' : (i - hw) < (hw * value) ? '*' : ' ';
+ } else {
+ for (unsigned int i = 0; i < width; i++)
+ temp[i + 1] = i < hw ? ' ' : (i - hw) < (hw * value) ? '*' : ' ';
+ }
+
+ mvaddnstr(y, x, temp, width);
+}
+
+void w2_ui_dirc_paint(int left, int right) {
+ mvaddstr(4, 0, "left drive: ");
+ w2_ui_bar_graph_pm(4, 13, g_w2_ui_width - 14, (double)left / 255);
+ mvaddstr(5, 0, "right drive: ");
+ w2_ui_bar_graph_pm(5, 13, g_w2_ui_width - 14, (double)right / 255);
+
+ mvaddstr(7, 0,
+ " controls:\n"
+ "\n"
+ " <q> <w> <e> forward\n"
+ " <a> <s> <d> backward\n"
+ "left both right\n");
+}
+
void w2_ui_dirc(bool first) {
if (first) w2_ui_dirc_init();
int ch = 0;
@@ -66,9 +101,9 @@ void w2_ui_dirc(bool first) {
int drive_l = w2_dirc_motor_l(lf, lb);
int drive_r = w2_dirc_motor_r(rf, rb);
- char temp[32] = {0};
- sprintf(temp, "l: %04i, r: %04i", drive_l, drive_r);
- mvaddstr(4, 0, temp);
+ drive_l += drive_r * W2_DIRC_STP;
+ drive_r += drive_l * W2_DIRC_STP;
w2_send_dirc(drive_l, drive_r);
+ w2_ui_dirc_paint(drive_l, drive_r);
}