summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-05-29 22:35:04 +0200
committerlonkaars <loek@pipeframe.xyz>2022-05-29 22:35:04 +0200
commit555e5d2c0ce77dd1e031690c98ec9a1366182347 (patch)
tree69a505a23ae6ca5d0951e8f832f9895fcbb88b83
parent87d8b0ceb349e101b693cf43336a98647f4b92dc (diff)
`make format`
-rw-r--r--client/i18n.h1
-rw-r--r--client/serial.c4
-rw-r--r--client/term.h1
-rw-r--r--client/term_linux.c8
-rw-r--r--client/ui.c53
-rw-r--r--client/ui.h4
-rw-r--r--robot/hypervisor.c5
-rw-r--r--robot/modes.c2
-rw-r--r--robot/sercomm.c18
-rw-r--r--shared/bin.h13
10 files changed, 51 insertions, 58 deletions
diff --git a/client/i18n.h b/client/i18n.h
index 11fd576..06febee 100644
--- a/client/i18n.h
+++ b/client/i18n.h
@@ -4,4 +4,3 @@
#define W2_LANG_DEFAULT
#include "i18n/en_us.h"
#endif
-
diff --git a/client/serial.c b/client/serial.c
index 9efb966..78f5631 100644
--- a/client/serial.c
+++ b/client/serial.c
@@ -1,9 +1,9 @@
#include <memory.h>
-#include "serial.h"
#include "../shared/protocol.h"
#include "../shared/serial_parse.h"
#include "main.h"
+#include "serial.h"
#include "time.h"
void w2_serial_main() {
@@ -16,7 +16,7 @@ void w2_cmd_ping_tx(w2_s_bin *data) {
if (g_w2_state.ping_received) return;
if (g_w2_state.ping_id != cast->id) return;
- g_w2_state.ping = w2_timer_end(W2_TIMER_PING);
+ g_w2_state.ping = w2_timer_end(W2_TIMER_PING);
g_w2_state.ping_received = true;
printf("ping measured, %ims\n", g_w2_state.ping);
diff --git a/client/term.h b/client/term.h
index a60dc2c..8212149 100644
--- a/client/term.h
+++ b/client/term.h
@@ -4,4 +4,3 @@
void w2_term_raw_mode();
/** set ui canvas props */
void w2_term_props();
-
diff --git a/client/term_linux.c b/client/term_linux.c
index 2a88d6c..cdab99d 100644
--- a/client/term_linux.c
+++ b/client/term_linux.c
@@ -1,9 +1,9 @@
#ifdef W2_HOST_LINUX
#include <fcntl.h>
-#include <unistd.h>
-#include <termios.h>
#include <sys/ioctl.h>
+#include <termios.h>
+#include <unistd.h>
#include "term.h"
#include "ui.h"
@@ -14,7 +14,7 @@ void w2_term_raw_mode() {
tcgetattr(STDIN_FILENO, &term);
term.c_lflag &= ~(ECHO | ICANON);
term.c_cc[VTIME] = 0;
- term.c_cc[VMIN] = 1;
+ term.c_cc[VMIN] = 1;
tcsetattr(STDIN_FILENO, 0, &term);
}
@@ -22,7 +22,7 @@ void w2_term_props() {
struct winsize window;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &window);
- g_w2_ui_canvas.width = window.ws_col;
+ g_w2_ui_canvas.width = window.ws_col;
g_w2_ui_canvas.height = window.ws_row;
}
diff --git a/client/ui.c b/client/ui.c
index 84408bb..1f42db5 100644
--- a/client/ui.c
+++ b/client/ui.c
@@ -1,11 +1,11 @@
#include <string.h>
-#include "../shared/util.h"
#include "../shared/bin.h"
+#include "../shared/util.h"
#include "i18n.h"
#include "main.h"
-#include "ui.h"
#include "term.h"
+#include "ui.h"
w2_s_ui_tty_canvas g_w2_ui_canvas;
@@ -14,63 +14,61 @@ void w2_ui_main() {
w2_ui_paint();
}
-void w2_ui_update() {
- w2_term_props();
-}
+void w2_ui_update() { w2_term_props(); }
-void w2_ui_paint() {
- w2_ui_paint_statusbar();
-}
+void w2_ui_paint() { w2_ui_paint_statusbar(); }
-void w2_ui_align(char* text, w2_e_alignment align, unsigned int length) {
+void w2_ui_align(char *text, w2_e_alignment align, unsigned int length) {
unsigned int padding = 0;
- switch(align) {
+ switch (align) {
case W2_UI_ALIGN_LEFT: {
break;
}
case W2_UI_ALIGN_CENTER: {
unsigned int middle = length / 2;
unsigned int offset = strlen(text) / 2;
- padding = W2_MAX(0, middle - offset);
+ padding = W2_MAX(0, middle - offset);
break;
}
case W2_UI_ALIGN_RIGHT: {
- unsigned int right = length;
+ unsigned int right = length;
unsigned int offset = strlen(text);
- padding = W2_MAX(0, right - offset);
+ padding = W2_MAX(0, right - offset);
break;
}
}
- char* temp = calloc(length, 1);
+ char *temp = calloc(length, 1);
sprintf(temp, "%*s%s", padding, "", text);
memcpy(text, temp, length);
free(temp);
}
-char* w2_ui_pt_sb_con_sts() {
- char* connected = g_w2_state.connected ? W2_UI_CONN_STAT_CONNECTED : W2_UI_CONN_STAT_DISCONNECTED;
- char* out = calloc(g_w2_ui_canvas.width, 1);
+char *w2_ui_pt_sb_con_sts() {
+ char *connected =
+ g_w2_state.connected ? W2_UI_CONN_STAT_CONNECTED : W2_UI_CONN_STAT_DISCONNECTED;
+ char *out = calloc(g_w2_ui_canvas.width, 1);
sprintf(out, "%s, %ims %s", connected, g_w2_state.ping, W2_UI_CONN_STAT_PING);
w2_ui_align(out, W2_UI_ALIGN_LEFT, g_w2_ui_canvas.width);
return out;
}
-char* w2_ui_pt_sb_ver_num() {
- char* out = calloc(g_w2_ui_canvas.width, 1);
+char *w2_ui_pt_sb_ver_num() {
+ char *out = calloc(g_w2_ui_canvas.width, 1);
sprintf(out, "(%s)", g_w2_state.info.build_str);
w2_ui_align(out, W2_UI_ALIGN_CENTER, g_w2_ui_canvas.width);
return out;
}
-char* w2_ui_pt_sb_bat_sts() {
- char* out = calloc(g_w2_ui_canvas.width, 1);
+char *w2_ui_pt_sb_bat_sts() {
+ char *out = calloc(g_w2_ui_canvas.width, 1);
sprintf(out, "%s %i%%", W2_UI_BATT_STAT_BATTERY, g_w2_state.battery_level);
w2_ui_align(out, W2_UI_ALIGN_RIGHT, g_w2_ui_canvas.width);
return out;
}
-void w2_ui_nullsub(char* str, unsigned int length) {
- for (int i = 0; i < length; i++) if (str[i] == 0x00) str[i] = ' ';
+void w2_ui_nullsub(char *str, unsigned int length) {
+ for (int i = 0; i < length; i++)
+ if (str[i] == 0x00) str[i] = ' ';
}
void w2_ui_overlay(char *bottom, char *top, unsigned int length) {
@@ -100,9 +98,9 @@ void w2_ui_overlay(char *bottom, char *top, unsigned int length) {
void w2_ui_paint_statusbar() {
char top_row[g_w2_ui_canvas.width];
- char* con_sts = w2_ui_pt_sb_con_sts();
- char* ver_num = w2_ui_pt_sb_ver_num();
- char* bat_sts = w2_ui_pt_sb_bat_sts();
+ char *con_sts = w2_ui_pt_sb_con_sts();
+ char *ver_num = w2_ui_pt_sb_ver_num();
+ char *bat_sts = w2_ui_pt_sb_bat_sts();
w2_ui_overlay(top_row, con_sts, g_w2_ui_canvas.width);
w2_ui_overlay(top_row, ver_num, g_w2_ui_canvas.width);
@@ -113,10 +111,9 @@ void w2_ui_paint_statusbar() {
free(con_sts);
free(ver_num);
free(bat_sts);
-
+
// w2_ui_pt_sb_connection_status();
// w2_ui_pt_sb_connection_status();
// w2_ui_pt_sb_connection_status();
printf("\n");
}
-
diff --git a/client/ui.h b/client/ui.h
index 36266ba..610e3fc 100644
--- a/client/ui.h
+++ b/client/ui.h
@@ -43,9 +43,9 @@ void w2_ui_paint_statusbar();
void w2_ui_main();
/** get ansi color code for foreground color */
-char* w2_ui_set_fg(w2_e_colors color);
+char *w2_ui_set_fg(w2_e_colors color);
/** get ansi color code for background color */
-char* w2_ui_set_bg(w2_e_colors color);
+char *w2_ui_set_bg(w2_e_colors color);
/** align `text` `align` with `text` buffer length `length` */
void w2_ui_align(char *text, w2_e_alignment align, unsigned int length);
diff --git a/robot/hypervisor.c b/robot/hypervisor.c
index 3359bf6..4f994a8 100644
--- a/robot/hypervisor.c
+++ b/robot/hypervisor.c
@@ -1,6 +1,6 @@
#include "hypervisor.h"
-#include "../shared/util.h"
#include "../shared/errcatch.h"
+#include "../shared/util.h"
#include "io.h"
#include "modes.h"
#include "orangutan_shim.h"
@@ -46,8 +46,7 @@ void w2_hypervisor_main() {
if (DBG_ENABLE_CYCLEINFO) siminfo("cycle end\n");
if (DBG_CYCLE_DELAY > 0) usleep(DBG_CYCLE_DELAY);
- if (DBG_MAX_CYCLES > -1 && g_w2_hypervisor_cycles > DBG_MAX_CYCLES)
- exit(0);
+ if (DBG_MAX_CYCLES > -1 && g_w2_hypervisor_cycles > DBG_MAX_CYCLES) exit(0);
#endif
g_w2_hypervisor_cycles++;
diff --git a/robot/modes.c b/robot/modes.c
index 55bb1d4..928e2b4 100644
--- a/robot/modes.c
+++ b/robot/modes.c
@@ -1,7 +1,7 @@
#include "modes.h"
+#include "../shared/errcatch.h"
#include "../shared/protocol.h"
#include "../shared/util.h"
-#include "../shared/errcatch.h"
#include "sercomm.h"
/** function pointer to current mode */
diff --git a/robot/sercomm.c b/robot/sercomm.c
index 5ac9a87..2317d89 100644
--- a/robot/sercomm.c
+++ b/robot/sercomm.c
@@ -2,8 +2,8 @@
#include <string.h>
#include "../shared/bin.h"
-#include "../shared/serial_parse.h"
#include "../shared/errcatch.h"
+#include "../shared/serial_parse.h"
#include "hypervisor.h"
#include "io.h"
#include "mode_dirc.h"
@@ -65,8 +65,8 @@ void w2_cmd_ping_rx(w2_s_bin *data) {
W2_CAST_BIN(w2_s_cmd_ping_rx, data, req);
W2_CREATE_MSG_BIN(w2_s_cmd_ping_tx, res_msg, res_bin);
- res_msg->opcode = W2_CMD_PING | W2_CMDDIR_TX;
- res_msg->id = req->id;
+ res_msg->opcode = W2_CMD_PING | W2_CMDDIR_TX;
+ res_msg->id = req->id;
w2_sercomm_append_msg(res_bin);
free(res_bin);
@@ -112,7 +112,7 @@ void w2_cmd_mcfg_rx(w2_s_bin *data) { return; }
void w2_cmd_sens_rx(w2_s_bin *data) {
W2_CREATE_MSG_BIN(w2_s_cmd_sens_tx, res_msg, res_bin);
- res_msg->opcode = W2_CMD_SENS | W2_CMDDIR_TX;
+ res_msg->opcode = W2_CMD_SENS | W2_CMDDIR_TX;
memcpy((uint8_t *)&res_msg->io, (uint8_t *)&g_w2_io, sizeof(w2_s_io_all));
for (int i = 0; i < 5; i++) w2_bin_repl_hton16(&res_msg->io.qtr[i].range);
@@ -128,13 +128,13 @@ void w2_cmd_sens_rx(w2_s_bin *data) {
void w2_cmd_info_rx(w2_s_bin *data) {
W2_CREATE_MSG_BIN(w2_s_cmd_info_tx, res_msg, res_bin);
- res_msg->opcode = W2_CMD_INFO | W2_CMDDIR_TX;
+ res_msg->opcode = W2_CMD_INFO | W2_CMDDIR_TX;
strncpy((char *)res_msg->build_str, W2_BUILD_STR, sizeof(res_msg->build_str));
res_msg->errcatch_ms = (uint8_t)g_w2_hypervisor_ema_errcatch_ms;
- res_msg->io_ms = (uint8_t)g_w2_hypervisor_ema_io_ms;
- res_msg->sercomm_ms = (uint8_t)g_w2_hypervisor_ema_sercomm_ms;
- res_msg->mode_ms = (uint8_t)g_w2_hypervisor_ema_mode_ms;
- res_msg->uptime_s = w2_bin_hton32((uint32_t)(g_w2_hypervisor_uptime_ms / 1e3));
+ res_msg->io_ms = (uint8_t)g_w2_hypervisor_ema_io_ms;
+ res_msg->sercomm_ms = (uint8_t)g_w2_hypervisor_ema_sercomm_ms;
+ res_msg->mode_ms = (uint8_t)g_w2_hypervisor_ema_mode_ms;
+ res_msg->uptime_s = w2_bin_hton32((uint32_t)(g_w2_hypervisor_uptime_ms / 1e3));
w2_sercomm_append_msg(res_bin);
free(res_bin);
diff --git a/shared/bin.h b/shared/bin.h
index a849d53..4f7db81 100644
--- a/shared/bin.h
+++ b/shared/bin.h
@@ -13,13 +13,12 @@
extern uint8_t g_w2_endianness;
-#define W2_CAST_BIN(type, in, out) type *out = (type*) &in->data;
-#define W2_CREATE_MSG_BIN(type, normal, bin) \
- W2_CREATE_MSG_SIZE_BIN(type, sizeof(type), normal, bin)
-#define W2_CREATE_MSG_SIZE_BIN(type, size, normal, bin) \
- w2_s_bin* bin = malloc(sizeof(w2_s_bin) + size); \
- bin->bytes = size; \
- type* normal = (type*) &bin->data;
+#define W2_CAST_BIN(type, in, out) type *out = (type *)&in->data;
+#define W2_CREATE_MSG_BIN(type, normal, bin) W2_CREATE_MSG_SIZE_BIN(type, sizeof(type), normal, bin)
+#define W2_CREATE_MSG_SIZE_BIN(type, size, normal, bin) \
+ w2_s_bin *bin = malloc(sizeof(w2_s_bin) + size); \
+ bin->bytes = size; \
+ type *normal = (type *)&bin->data;
typedef struct {
uint16_t bytes;