summaryrefslogtreecommitdiff
path: root/client/ui_dirc.c
diff options
context:
space:
mode:
Diffstat (limited to 'client/ui_dirc.c')
-rw-r--r--client/ui_dirc.c68
1 files changed, 38 insertions, 30 deletions
diff --git a/client/ui_dirc.c b/client/ui_dirc.c
index ed69cd2..db91661 100644
--- a/client/ui_dirc.c
+++ b/client/ui_dirc.c
@@ -1,8 +1,14 @@
#include "../shared/protocol.h"
#include "../shared/util.h"
#include "commands.h"
+#include "errcatch.h"
#include "ui.h"
+unsigned int g_w2_lb = 0;
+unsigned int g_w2_lf = 0;
+unsigned int g_w2_rb = 0;
+unsigned int g_w2_rf = 0;
+
/** decay modifier */
#define W2_DIRC_MOD ((double)0.95)
/** add value per key press */
@@ -50,7 +56,7 @@ void w2_ui_bar_graph(unsigned int y, unsigned int x, unsigned int width, double
temp[width - 1] = '|';
for (unsigned int i = 0; i < width - 2; i++) temp[i + 1] = i < width * value ? '*' : ' ';
- mvaddnstr(y, x, temp, width);
+ w2_wmvaddnstr(g_w2_ui_pad_body, y, x, temp, width);
}
void w2_ui_bar_graph_pm(unsigned int y, unsigned int x, unsigned int width, double value) {
@@ -67,46 +73,48 @@ void w2_ui_bar_graph_pm(unsigned int y, unsigned int x, unsigned int width, doub
temp[i + 1] = i > hw ? ' ' : (hw - i) < -(hw * value) ? '*' : ' ';
}
- mvaddnstr(y, x, temp, width + 2);
+ w2_wmvaddnstr(g_w2_ui_pad_body, y, x, temp, width + 2);
}
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 - 13, (double)left / 255);
- mvaddstr(5, 0, "right drive: ");
- w2_ui_bar_graph_pm(5, 13, g_w2_ui_width - 13, (double)right / 255);
-
- mvaddstr(7, 0,
- " controls:\n"
- "\n"
- " <q> <w> <e> forward\n"
- " <a> <s> <d> backward\n"
- "left both right\n"
- "\n"
- "<space> send dirc mode command");
+ w2_wmvaddstr(g_w2_ui_pad_body, 0, 0, "left drive: ");
+ w2_ui_bar_graph_pm(0, 13, g_w2_ui_width - 13, (double)left / 255);
+ w2_wmvaddstr(g_w2_ui_pad_body, 1, 0, "right drive: ");
+ w2_ui_bar_graph_pm(1, 13, g_w2_ui_width - 13, (double)right / 255);
+
+ w2_wmvaddstr(g_w2_ui_pad_body, 3, 0,
+ " controls:\n"
+ "\n"
+ " <q> <w> <e> forward\n"
+ " <a> <s> <d> backward\n"
+ "left both right\n"
+ "\n"
+ "<space> send dirc mode command");
+}
+
+void w2_ui_onkey_dirc(int ch) {
+ if (ch == 'e' || ch == 'w') g_w2_lf++;
+ if (ch == 'd' || ch == 's') g_w2_lb++;
+ if (ch == 'q' || ch == 'w') g_w2_rf++;
+ if (ch == 'a' || ch == 's') g_w2_rb++;
+ if (ch == ' ') w2_send_mode(W2_M_DIRC);
}
-void w2_ui_dirc(bool first) {
+void w2_ui_tab_dirc(bool first) {
+ g_w2_ui_pad_body_scroll = 0;
if (first) w2_ui_dirc_init();
- int ch = 0;
- unsigned int lb = 0;
- unsigned int lf = 0;
- unsigned int rb = 0;
- unsigned int rf = 0;
- while ((ch = getch()) != -1) {
- if (ch == 'e' || ch == 'w') lf++;
- 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);
- int drive_r = w2_dirc_motor_r(rf, rb);
+ int drive_l = w2_dirc_motor_l(g_w2_lf, g_w2_lb);
+ int drive_r = w2_dirc_motor_r(g_w2_rf, g_w2_rb);
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);
+
+ g_w2_lb = 0;
+ g_w2_lf = 0;
+ g_w2_rb = 0;
+ g_w2_rf = 0;
}