From 12e93e08211cef11ccaa108825fff19d0f7c2581 Mon Sep 17 00:00:00 2001 From: smayzy Date: Mon, 6 Apr 2026 15:57:52 +0200 Subject: [PATCH] switch to the struct for positioning --- src/main.c | 118 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 66 insertions(+), 52 deletions(-) diff --git a/src/main.c b/src/main.c index 6589168..389f403 100644 --- a/src/main.c +++ b/src/main.c @@ -26,7 +26,12 @@ typedef struct{ int hdata; int digits; bool high; + int height; + int width; + int starty; + int startx; WINDOW *lwin; + char title[30]; } StInt; typedef struct{ float data; @@ -34,10 +39,20 @@ typedef struct{ float hdata; int digits; bool high; + int height; + int width; + int starty; + int startx; WINDOW *lwin; + char title[30]; } StFlt; typedef struct{ + int height; + int width; + int starty; + int startx; WINDOW *lwin; + char title[30]; } StStr; typedef struct { @@ -53,6 +68,25 @@ typedef struct { StStr message; } Tel; +void win_init_int(StInt *st) { + st->lwin = newwin(st->height, st->width, st->starty, st->startx); + box(st->lwin, 0, 0); + mvwprintw(st->lwin, 0, 2, "%s", st->title); + wrefresh(st->lwin); +}; +void win_init_flt(StFlt *st) { + st->lwin = newwin(st->height, st->width, st->starty, st->startx); + box(st->lwin, 0, 0); + mvwprintw(st->lwin, 0, 2, "%s", st->title); + wrefresh(st->lwin); +}; +void win_init_str(StStr *st) { + st->lwin = newwin(st->height, st->width, st->starty, st->startx); + box(st->lwin, 0, 0); + mvwprintw(st->lwin, 0, 2, "%s", st->title); + wrefresh(st->lwin); +}; + void get_fake_data(Tel *t) { t->speed.data = t->speed.ldata + rand() % (t->speed.hdata - t->speed.ldata + 1); t->power.data = t->power.ldata + rand() % (t->power.hdata - t->power.ldata + 1); @@ -347,20 +381,6 @@ int main(int argc, char **argv) { init_pair(3, COLOR_GREEN, -1); } - WINDOW *win[10]; - - Tel tel; - tel.speed = (StInt){0, 0, 200, 3, 1, NULL}; - tel.rpm = (StInt){0, 0, 6000, 4, 1, NULL}; - tel.tq = (StFlt){0.0f, 1.8f, 3.5f, 3, 1, NULL}; - tel.power = (StInt){0, 0, 1300, 4, 1, NULL}; - tel.eff = (StFlt){0.0f, 0.0f, 300.0f, 5, 1, NULL}; - tel.bat = (StInt){0, 0, 100, 3, 0, NULL}; - tel.bat_temp = (StFlt){0.0f, 0.0f, 150.0f, 5, 1, NULL}; - tel.var_temp = (StFlt){0.0f, 0.0f, 150.0f, 5, 1, NULL}; - tel.mot_temp = (StFlt){0.0f, 0.0f, 150.0f, 5, 1, NULL}; - tel.message = (StStr){NULL}; - int x3 = x / 3; int x3r = x - 2 * x3; @@ -371,41 +391,28 @@ int main(int argc, char **argv) { int y6 = y2r / 3; int y6r = y2r - 2 * y6; - typedef struct { - int height, width, starty, startx; - char *title; - } WinInfo; - - WinInfo win_infos[10] = { - {y2, x3, 0, 0, "speed (km/h)"}, // 0 - {y2, x3, 0, x3, "rpm (tr/min)"}, // 1 - {y4, x3r, 0, x - x3r, "batteries (%)"}, // 2 - {y4r, x3r, y4, x - x3r, "torque (N/m)"}, // 3 - {y6, 2 * x3, y2, 0, "power (W)"}, // 4 - {y6, x3r, y2, 2 * x3, "efficiency (Wh/Km)"}, // 5 - {y6, x3, y2 + y6, 0, "batteries temperature (deg C)"}, // 6 - {y6, x3, y2 + y6, x3, "variator temperature (deg C)"}, // 7 - {y6, x3r, y2 + y6, x - x3r, "motor temperature (deg C)"}, // 8 - {y6r, x, y - y6r, 0, "warnings"} // 9 - }; - - for (int i = 0; i < 10; i++) { - win[i] = newwin(win_infos[i].height, win_infos[i].width, win_infos[i].starty, win_infos[i].startx); - box(win[i], 0, 0); - mvwprintw(win[i], 0, 2, "%s", win_infos[i].title); - wrefresh(win[i]); - } - tel.speed.lwin = win[0]; - tel.rpm.lwin = win[1]; - tel.tq.lwin = win[3]; - tel.power.lwin = win[4]; - tel.eff.lwin = win[5]; - tel.bat.lwin = win[2]; - tel.bat_temp.lwin = win[6]; - tel.var_temp.lwin = win[7]; - tel.mot_temp.lwin = win[8]; - tel.message.lwin = win[9]; + Tel tel; + tel.speed = (StInt){0 , 0 , 200 , 3, 1, y2 , x3 , 0 , 0 , NULL, "speed (km/h)" }; + tel.rpm = (StInt){0 , 0 , 6000 , 4, 1, y2 , x3 , 0 , x3 , NULL, "rpm (tr/min)" }; + tel.tq = (StFlt){0.0f, 1.8f, 3.5f , 3, 1, y4r, x3r , y4 , x-x3r , NULL, "torque (N/m)" }; + tel.power = (StInt){0 , 0 , 1300 , 4, 1, y6 , 2*x3, y2 , 0 , NULL, "power (W)" }; + tel.eff = (StFlt){0.0f, 0.0f, 300.0f, 5, 1, y6 , x3r , y2 , 2*x3 , NULL, "efficiency (Wh/Km)" }; + tel.bat = (StInt){0 , 0 , 100 , 3, 0, y4 , x3r , 0 , x-x3r , NULL, "batteries (%)" }; + tel.bat_temp = (StFlt){0.0f, 0.0f, 150.0f, 5, 1, y6 , x3 , y2+y6, 0 , NULL, "batteries temperature (deg C)" }; + tel.var_temp = (StFlt){0.0f, 0.0f, 150.0f, 5, 1, y6 , x3 , y2+y6, x3 , NULL, "variator temperature (deg C)" }; + tel.mot_temp = (StFlt){0.0f, 0.0f, 150.0f, 5, 1, y6 , x3r , y2+y6, x-x3r , NULL, "motor temperature (deg C)" }; + tel.message = (StStr){ y6r, x , y-y6r, 0 , NULL, "warnings" }; + win_init_int(&tel.speed); + win_init_int(&tel.rpm); + win_init_flt(&tel.tq); + win_init_int(&tel.power); + win_init_flt(&tel.eff); + win_init_int(&tel.bat); + win_init_flt(&tel.bat_temp); + win_init_flt(&tel.var_temp); + win_init_flt(&tel.mot_temp); + win_init_str(&tel.message); bar_mark(tel.power.lwin); @@ -442,13 +449,20 @@ int main(int argc, char **argv) { win_float(tel.mot_temp, use_color); t1000 = now; } - //win[9]; + //message; napms(10); }; end: - for (int i = 0; i < 10; i++) { - delwin(win[i]); - } + delwin(tel.speed.lwin); + delwin(tel.rpm.lwin); + delwin(tel.tq.lwin); + delwin(tel.power.lwin); + delwin(tel.eff.lwin); + delwin(tel.bat.lwin); + delwin(tel.bat_temp.lwin); + delwin(tel.var_temp.lwin); + delwin(tel.mot_temp.lwin); + delwin(tel.message.lwin); endwin(); return 0; }