add telemetry to a struct

This commit is contained in:
smayzy 2026-04-06 12:38:15 +02:00
parent 9b6c7f7540
commit 403b3f6082

View File

@ -19,16 +19,47 @@ const int digit_bitmaps[10][5][3] = {
{{1,1,1},{1,0,1},{1,1,1},{0,0,1},{1,1,1}} // 9 {{1,1,1},{1,0,1},{1,1,1},{0,0,1},{1,1,1}} // 9
}; };
void get_fake_data(int *speed, int lspeed, int hspeed, int *power, int lpower, int hpower, int *bat, int lbat, int hbat, float *tq, float ltq, float htq, int *rpm, int lrpm, int hrpm, float *eff, float leff, float heff, float *bat_temp, float lbat_temp, float hbat_temp, float *var_temp, float lvar_temp, float hvar_temp, float *mot_temp, float lmot_temp, float hmot_temp) { typedef struct{
*speed = lspeed + rand() % (hspeed - lspeed + 1); int data;
*power = lpower + rand() % (hpower - lpower + 1); int ldata;
*bat = lbat + rand() % (hbat - lbat + 1); int hdata;
*tq = ltq + ((float)rand() / (float)RAND_MAX) * (htq - ltq); int digits;
*rpm = lrpm + rand() % (hrpm - lrpm + 1); WINDOW *lwin;
*eff = leff + (float)rand() / (float)RAND_MAX * (heff - leff); } StrInt;
*bat_temp = lbat_temp + (float)rand() / (float)RAND_MAX * (hbat_temp - lbat_temp); typedef struct{
*var_temp = lvar_temp + (float)rand() / (float)RAND_MAX * (hvar_temp - lvar_temp); float data;
*mot_temp = lmot_temp + (float)rand() / (float)RAND_MAX * (hmot_temp - lmot_temp); float ldata;
float hdata;
int digits;
WINDOW *lwin;
} StrFlt;
typedef struct{
WINDOW *lwin;
} StrStr;
typedef struct {
StrInt speed;
StrInt rpm;
StrFlt tq;
StrInt power;
StrFlt eff;
StrInt bat;
StrFlt bat_temp;
StrFlt var_temp;
StrFlt mot_temp;
StrStr message;
} Tel;
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);
t->bat.data = t->bat.ldata + rand() % (t->bat.hdata - t->bat.ldata + 1);
t->tq.data = t->tq.ldata + ((float)rand() / (float)RAND_MAX) * (float)(t->tq.hdata - t->tq.ldata);
t->rpm.data = t->rpm.ldata + rand() % (t->rpm.hdata - t->rpm.ldata + 1);
t->eff.data = t->eff.ldata + ((float)rand() / (float)RAND_MAX) * (float)(t->eff.hdata - t->eff.ldata);
t->bat_temp.data = t->bat_temp.ldata + ((float)rand() / (float)RAND_MAX) * (float)(t->bat_temp.hdata - t->bat_temp.ldata);
t->var_temp.data = t->var_temp.ldata + ((float)rand() / (float)RAND_MAX) * (float)(t->var_temp.hdata - t->var_temp.ldata);
t->mot_temp.data = t->mot_temp.ldata + ((float)rand() / (float)RAND_MAX) * (float)(t->mot_temp.hdata - t->mot_temp.ldata);
} }
long now_ms(void) { long now_ms(void) {
@ -303,6 +334,18 @@ int main(int argc, char **argv) {
WINDOW *win[10]; WINDOW *win[10];
Tel tel;
tel.speed = (StrInt){0, 0, 200, 3, NULL};
tel.rpm = (StrInt){0, 0, 6000, 4, NULL};
tel.tq = (StrFlt){0.0f, 1.8f, 3.5f, 3, NULL};
tel.power = (StrInt){0, 0, 1300, 4, NULL};
tel.eff = (StrFlt){0.0f, 0.0f, 300.0f, 5, NULL};
tel.bat = (StrInt){0, 0, 100, 3, NULL};
tel.bat_temp = (StrFlt){0.0f, 0.0f, 150.0f, 5, NULL};
tel.var_temp = (StrFlt){0.0f, 0.0f, 150.0f, 5, NULL};
tel.mot_temp = (StrFlt){0.0f, 0.0f, 150.0f, 5, NULL};
tel.message = (StrStr){NULL};
int x3 = x / 3; int x3 = x / 3;
int x3r = x - 2 * x3; int x3r = x - 2 * x3;
@ -339,10 +382,6 @@ int main(int argc, char **argv) {
} }
bar_mark(win[4]); bar_mark(win[4]);
int speed = 0, power = 0, bat = 0, rpm = 0;
float tq = 0.0f, eff = 0.0f, bat_temp = 0.0f, var_temp = 0.0f, mot_temp = 0.0f;
int lspeed = 0, hspeed = 200, lpower = 0, hpower = 1250, lbat = 0, hbat = 100, lrpm = 0, hrpm = 6000;
float ltq = 1.8f, htq = 3.5f, leff = 0.0f, heff = 300.0f, lbat_temp = 0.0f, hbat_temp = 150.0f, lvar_temp = 0.0f, hvar_temp = 150.0f, lmot_temp = 0.0f, hmot_temp = 150.0f;
long t100 = 0, t1000 = 0; long t100 = 0, t1000 = 0;
int ch = ERR; int ch = ERR;
@ -355,7 +394,7 @@ int main(int argc, char **argv) {
case ERR : case ERR :
default : default :
if (fake_data) { if (fake_data) {
get_fake_data(&speed, lspeed, hspeed, &power, lpower, hpower, &bat, lbat, hbat, &tq, ltq, htq, &rpm, lrpm, hrpm, &eff, leff, heff, &bat_temp, lbat_temp, hbat_temp, &var_temp, lvar_temp, hvar_temp, &mot_temp, lmot_temp, hmot_temp); get_fake_data(&tel);
} else { } else {
//real_data() //real_data()
} }
@ -366,18 +405,18 @@ int main(int argc, char **argv) {
long now = now_ms(); long now = now_ms();
if (now - t100 >= 100 * delay) { if (now - t100 >= 100 * delay) {
win_int(win[0], speed, 3, use_color, color_high(speed, lspeed, hspeed)); win_int(win[0], tel.speed.data, 3, use_color, color_high(tel.speed.data, tel.speed.ldata, tel.speed.hdata));
win_int(win[1], rpm, 4, use_color, color_high(rpm, lrpm, hrpm)); win_int(win[1], tel.rpm.data, 4, use_color, color_high(tel.rpm.data, tel.rpm.ldata, tel.rpm.hdata));
win_float(win[3], tq, 3, use_color, color_high(tq, ltq, htq)); win_float(win[3], tel.tq.data, 3, use_color, color_high(tel.tq.data, tel.tq.ldata, tel.tq.hdata));
win_bar(win[4], power, hpower, use_color, 4); win_bar(win[4], tel.power.data, tel.power.hdata, use_color, tel.power.digits);
win_float(win[5], eff, 5, use_color, color_high(eff, leff, heff)); win_float(win[5], tel.eff.data, 5, use_color, color_high(tel.eff.data, tel.eff.ldata, tel.eff.hdata));
t100 = now; t100 = now;
} }
if (now - t1000 >= 1000 * delay) { if (now - t1000 >= 1000 * delay) {
win_int(win[2], bat, 3, use_color, color_low(bat, lbat, hbat)); win_int(win[2], tel.bat.data, 3, use_color, color_low(tel.bat.data, tel.bat.ldata, tel.bat.hdata));
win_float(win[6], bat_temp, 5, use_color, color_high(bat_temp, lbat_temp, hbat_temp)); win_float(win[6], tel.bat_temp.data, 5, use_color, color_high(tel.bat_temp.data, tel.bat_temp.ldata, tel.bat_temp.hdata));
win_float(win[7], var_temp, 5, use_color, color_high(var_temp, lvar_temp, hvar_temp)); win_float(win[7], tel.var_temp.data, 5, use_color, color_high(tel.var_temp.data, tel.var_temp.ldata, tel.var_temp.hdata));
win_float(win[8], mot_temp, 5, use_color, color_high(mot_temp, lmot_temp, hmot_temp)); win_float(win[8], tel.mot_temp.data, 5, use_color, color_high(tel.mot_temp.data, tel.mot_temp.ldata, tel.mot_temp.hdata));
t1000 = now; t1000 = now;
} }
//win[9]; //win[9];