summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/errcatch.c27
-rw-r--r--client/errcatch.h8
-rw-r--r--client/i18n/en_us.h2
-rw-r--r--client/serial.c7
-rw-r--r--client/setup.c4
-rw-r--r--client/strings.c5
-rw-r--r--client/ui.c4
-rw-r--r--client/ui.h9
-rw-r--r--client/ui_dirc.c1
-rw-r--r--client/ui_errcatch.c27
-rw-r--r--client/ui_start.c1
-rw-r--r--client/ui_tabbar.c5
12 files changed, 75 insertions, 25 deletions
diff --git a/client/errcatch.c b/client/errcatch.c
index 5e39b00..c39544c 100644
--- a/client/errcatch.c
+++ b/client/errcatch.c
@@ -1,18 +1,15 @@
-#include "../shared/errcatch.h"
+#include <stdlib.h>
-void w2_errcatch_handle_error(w2_s_error *error) {
- // TODO: handle more error types
- switch (error->code) {
- case W2_E_WARN_UNCAUGHT_ERROR: {
- break;
- }
- default: {
- g_w2_error_uncaught = true;
-#ifdef W2_SIM
- simwarn("Uncaught/unhandled error found with code 0x%02x\n", error->code);
-#endif
- }
- }
+#include "errcatch.h"
- return;
+w2_s_error *g_w2_error_log[W2_ERRCATCH_LOG_SIZE] = {NULL};
+unsigned int g_w2_error_log_index = 0;
+
+void w2_errcatch_log_error(w2_s_error *error) {
+ if (g_w2_error_log[g_w2_error_log_index] != NULL) free(g_w2_error_log[g_w2_error_log_index]);
+ g_w2_error_log[g_w2_error_log_index] =
+ w2_alloc_error(error->code, error->message_length, error->message);
+ g_w2_error_log_index = (g_w2_error_log_index + 1) % W2_ERRCATCH_LOG_SIZE;
}
+
+void w2_errcatch_handle_error(w2_s_error *error) { w2_errcatch_log_error(error); }
diff --git a/client/errcatch.h b/client/errcatch.h
new file mode 100644
index 0000000..71eb56d
--- /dev/null
+++ b/client/errcatch.h
@@ -0,0 +1,8 @@
+#pragma once
+
+#include "../shared/errcatch.h"
+
+#define W2_ERRCATCH_LOG_SIZE 256
+
+extern w2_s_error *g_w2_error_log[W2_ERRCATCH_LOG_SIZE];
+extern unsigned int g_w2_error_log_index;
diff --git a/client/i18n/en_us.h b/client/i18n/en_us.h
index ff3ae91..fccfaa3 100644
--- a/client/i18n/en_us.h
+++ b/client/i18n/en_us.h
@@ -30,7 +30,7 @@
"this application is functionally similar to a BIOS.\n" \
"here's a brief summary of keyboard commands:\n" \
"\n" \
- "<left>/<right>, <h>/<l> switch tabs\n" \
+ "<tab> switch to next tab\n" \
"<up>/<down>, <j>/<k> select option\n" \
"<enter>, <i> edit option\n" \
"<home>, <g> scroll to top\n" \
diff --git a/client/serial.c b/client/serial.c
index 112fd81..044b636 100644
--- a/client/serial.c
+++ b/client/serial.c
@@ -3,6 +3,7 @@
#include "../shared/protocol.h"
#include "../shared/serial_parse.h"
#include "commands.h"
+#include "errcatch.h"
#include "main.h"
#include "serial.h"
#include "time.h"
@@ -26,7 +27,11 @@ void w2_cmd_ping_rx(w2_s_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_expt_tx(w2_s_bin *data) {
+ W2_CAST_BIN(w2_s_cmd_expt_tx, data, cast);
+ w2_errcatch_throw_msg(cast->error, cast->length, (char *)cast->message);
+}
+
void w2_cmd_mode_tx(w2_s_bin *data) {
W2_CAST_BIN(w2_s_cmd_mode_tx, data, cast);
g_w2_state.mode = cast->mode;
diff --git a/client/setup.c b/client/setup.c
index e51965f..41a987d 100644
--- a/client/setup.c
+++ b/client/setup.c
@@ -10,6 +10,8 @@
#include "strings.h"
#include "ui.h"
+#include "errcatch.h"
+
// pointers for endianness check
static const uint16_t _test = 1;
static const uint8_t *_ptest = (uint8_t *)&_test;
@@ -47,6 +49,8 @@ void w2_client_setup(int argc, char **argv) {
g_w2_ui_pad_body = newpad(g_w2_ui_height - 5, g_w2_ui_width);
scrollok(g_w2_ui_pad_body, true);
+ w2_errcatch_throw(W2_E_CRIT_COM_UNAVAILABLE);
+
// check endianness
g_w2_endianness = *_ptest;
}
diff --git a/client/strings.c b/client/strings.c
index 5dbb6bd..4dda1c8 100644
--- a/client/strings.c
+++ b/client/strings.c
@@ -14,8 +14,9 @@ void w2_strings_modes_init() {
}
void w2_strings_tabs_init() {
- g_w2_tab_strings[W2_UI_TAB_START] = W2_UI_TAB_LABEL_START;
- g_w2_tab_strings[W2_UI_TAB_DIRC] = W2_UI_TAB_LABEL_DIRC;
+ g_w2_tab_strings[W2_UI_TAB_START] = W2_UI_TAB_LABEL_START;
+ g_w2_tab_strings[W2_UI_TAB_ERRCATCH] = W2_UI_TAB_LABEL_ERRCATCH;
+ g_w2_tab_strings[W2_UI_TAB_DIRC] = W2_UI_TAB_LABEL_DIRC;
}
void w2_strings_init() {
diff --git a/client/ui.c b/client/ui.c
index 10e1814..41a392f 100644
--- a/client/ui.c
+++ b/client/ui.c
@@ -13,6 +13,7 @@
WINDOW *g_w2_ui_win;
WINDOW *g_w2_ui_pad_tabbar;
WINDOW *g_w2_ui_pad_body;
+int g_w2_ui_pad_body_scroll = 0;
unsigned int g_w2_ui_width = 0;
unsigned int g_w2_ui_height = 0;
w2_e_ui_tabs g_w2_ui_current_tab = W2_UI_TAB_START;
@@ -43,7 +44,8 @@ void w2_ui_paint() {
w2_timer_start(W2_TIMER_UPDATE);
}
prefresh(g_w2_ui_pad_tabbar, 0, 0, 2, 0, 2, g_w2_ui_width - 1);
- prefresh(g_w2_ui_pad_body, 0, 0, 4, 0, g_w2_ui_height - 2, g_w2_ui_width - 1);
+ prefresh(g_w2_ui_pad_body, W2_MAX(0, g_w2_ui_pad_body_scroll), 0,
+ 4 - W2_MIN(0, g_w2_ui_pad_body_scroll), 0, g_w2_ui_height - 2, g_w2_ui_width - 1);
// wrefresh(g_w2_ui_win);
}
diff --git a/client/ui.h b/client/ui.h
index ccab75d..bc74144 100644
--- a/client/ui.h
+++ b/client/ui.h
@@ -5,15 +5,17 @@
#define W2_UI_UPDATE_FPS (60)
-#define W2_UI_TAB_COUNT 2
+#define W2_UI_TAB_COUNT 3
typedef enum {
- W2_UI_TAB_START = 0,
- W2_UI_TAB_DIRC = 1,
+ W2_UI_TAB_START = 0,
+ W2_UI_TAB_ERRCATCH = 1,
+ W2_UI_TAB_DIRC = 2,
} w2_e_ui_tabs;
extern WINDOW *g_w2_ui_win;
extern WINDOW *g_w2_ui_pad_tabbar;
extern WINDOW *g_w2_ui_pad_body;
+extern int g_w2_ui_pad_body_scroll;
extern unsigned int g_w2_ui_width;
extern unsigned int g_w2_ui_height;
extern void (*g_w2_tab_ptrs[W2_UI_TAB_COUNT])(bool first);
@@ -37,6 +39,7 @@ void w2_ui_tabbar_init();
void w2_ui_tab_dirc(bool first);
void w2_ui_tab_start(bool first);
+void w2_ui_tab_errcatch(bool first);
void w2_wmvaddstr(WINDOW *win, unsigned int y, unsigned int x, char *str);
void w2_wmvaddnstr(WINDOW *win, unsigned int y, unsigned int x, char *str, unsigned int len);
diff --git a/client/ui_dirc.c b/client/ui_dirc.c
index d394f8d..63adad1 100644
--- a/client/ui_dirc.c
+++ b/client/ui_dirc.c
@@ -87,6 +87,7 @@ void w2_ui_dirc_paint(int left, int right) {
}
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;
diff --git a/client/ui_errcatch.c b/client/ui_errcatch.c
new file mode 100644
index 0000000..d2c32b2
--- /dev/null
+++ b/client/ui_errcatch.c
@@ -0,0 +1,27 @@
+#include <stdlib.h>
+
+#include "errcatch.h"
+#include "ui.h"
+
+char *w2_err_format(w2_s_error *error) {
+ char *ret_str = malloc(32);
+ sprintf(ret_str, "hai, 0x%02x", error->code);
+ return ret_str;
+}
+
+void w2_ui_tab_errcatch(bool first) {
+ g_w2_ui_pad_body_scroll = 5 - g_w2_ui_height;
+ unsigned int line = 0;
+ for (unsigned int x = 0; x < W2_ERRCATCH_LOG_SIZE; x++) {
+ unsigned int i = (x + g_w2_error_log_index) % W2_ERRCATCH_LOG_SIZE;
+ if (g_w2_error_log[i] == NULL) continue;
+
+ wmove(g_w2_ui_pad_body, line, 0);
+ char *err_str = w2_err_format(g_w2_error_log[i]);
+ waddstr(g_w2_ui_pad_body, err_str);
+ free(err_str);
+
+ line++;
+ }
+ g_w2_ui_pad_body_scroll += line;
+}
diff --git a/client/ui_start.c b/client/ui_start.c
index 7608792..118bc01 100644
--- a/client/ui_start.c
+++ b/client/ui_start.c
@@ -2,6 +2,7 @@
#include "ui.h"
void w2_ui_tab_start(bool first) {
+ g_w2_ui_pad_body_scroll = 0;
refresh();
w2_wmvaddstr(g_w2_ui_pad_body, 0, 0, W2_UI_TAB_START_MESSAGE);
}
diff --git a/client/ui_tabbar.c b/client/ui_tabbar.c
index 9f5707a..91d476f 100644
--- a/client/ui_tabbar.c
+++ b/client/ui_tabbar.c
@@ -9,8 +9,9 @@ unsigned int g_w2_ui_tabbar_lengths[W2_UI_TAB_COUNT];
void (*g_w2_tab_ptrs[W2_UI_TAB_COUNT])(bool first);
void w2_ui_tabbar_init() {
- g_w2_tab_ptrs[W2_UI_TAB_START] = &w2_ui_tab_start;
- g_w2_tab_ptrs[W2_UI_TAB_DIRC] = &w2_ui_tab_dirc;
+ g_w2_tab_ptrs[W2_UI_TAB_START] = &w2_ui_tab_start;
+ g_w2_tab_ptrs[W2_UI_TAB_ERRCATCH] = &w2_ui_tab_errcatch;
+ g_w2_tab_ptrs[W2_UI_TAB_DIRC] = &w2_ui_tab_dirc;
}
void w2_ui_switch_tab(w2_e_ui_tabs next_tab) {