steering-wheel/Core/Src/params.c

128 lines
2.2 KiB
C
Raw Normal View History

#include "params.h"
2023-04-04 22:05:50 +02:00
#include "can-halal.h"
#include "vehicle.h"
Params params = {0};
2023-04-04 22:05:50 +02:00
void params_init() { params.bbal = 50; }
void params_inc(ParamType param) {
switch (param) {
case PF_BBAL:
params.bbal += 0.5f;
if (params.bbal > 100.0f) {
params.bbal = 100.0f;
}
break;
2023-04-11 21:10:20 +02:00
case PF_SLIPREF:
params.slipref += 0.01f;
2023-04-04 22:05:50 +02:00
break;
2023-04-12 13:48:02 +02:00
case PF_MUMAX:
params.mumax += 0.1f;
break;
2023-04-11 21:10:20 +02:00
case PF_ASRP:
params.asrp++;
2023-04-04 22:05:50 +02:00
break;
2023-04-11 21:10:20 +02:00
case PF_ASRON:
params.asron = 1;
2023-04-04 22:05:50 +02:00
break;
case PF_TEST1:
params.test[0]++;
break;
case PF_TEST2:
params.test[1]++;
break;
case PF_TEST3:
params.test[2]++;
break;
case PF_TEST4:
params.test[3]++;
break;
}
}
void params_dec(ParamType param) {
switch (param) {
case PF_BBAL:
params.bbal -= 0.5f;
if (params.bbal < 0.0f) {
params.bbal = 0.0f;
}
break;
2023-04-11 21:10:20 +02:00
case PF_SLIPREF:
if (params.slipref > 0) {
params.slipref -= 0.01f;
2023-04-04 22:05:50 +02:00
}
break;
2023-04-12 13:48:02 +02:00
case PF_MUMAX:
if (params.mumax > 0) {
params.mumax -= 0.1f;
}
break;
2023-04-11 21:10:20 +02:00
case PF_ASRP:
if (params.asrp > 0) {
params.asrp--;
2023-04-04 22:05:50 +02:00
}
break;
2023-04-11 21:10:20 +02:00
case PF_ASRON:
params.asron = 0;
2023-04-04 22:05:50 +02:00
break;
case PF_TEST1:
if (params.test[0] > 0) {
params.test[0]--;
}
break;
case PF_TEST2:
if (params.test[1] > 0) {
params.test[1]--;
}
break;
case PF_TEST3:
if (params.test[2] > 0) {
params.test[2]--;
}
break;
case PF_TEST4:
if (params.test[3] > 0) {
params.test[3]--;
}
break;
}
}
void params_broadcast(ParamType param) {
int32_t value;
switch (param) {
case PF_BBAL:
value = params.bbal * 10;
break;
2023-04-11 21:10:20 +02:00
case PF_SLIPREF:
value = params.slipref * 100;
2023-04-04 22:05:50 +02:00
break;
2023-04-12 13:48:02 +02:00
case PF_MUMAX:
value = params.mumax * 10;
break;
2023-04-11 21:10:20 +02:00
case PF_ASRP:
value = params.asrp;
2023-04-04 22:05:50 +02:00
break;
2023-04-11 21:10:20 +02:00
case PF_ASRON:
value = params.asron;
2023-04-04 22:05:50 +02:00
break;
case PF_TEST1:
value = params.test[0];
break;
case PF_TEST2:
value = params.test[1];
break;
case PF_TEST3:
value = params.test[2];
break;
case PF_TEST4:
value = params.test[3];
break;
default:
return;
}
vehicle_broadcast_param(param, value);
}