steering-wheel/Core/Src/params.c

128 lines
2.2 KiB
C

#include "params.h"
#include "can-halal.h"
#include "vehicle.h"
Params params = {0};
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;
case PF_SLIPREF:
params.slipref += 0.01f;
break;
case PF_MUMAX:
params.mumax += 0.1f;
break;
case PF_ASRP:
params.asrp++;
break;
case PF_ASRON:
params.asron = 1;
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;
case PF_SLIPREF:
if (params.slipref > 0) {
params.slipref -= 0.01f;
}
break;
case PF_MUMAX:
if (params.mumax > 0) {
params.mumax -= 0.1f;
}
break;
case PF_ASRP:
if (params.asrp > 0) {
params.asrp--;
}
break;
case PF_ASRON:
params.asron = 0;
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;
case PF_SLIPREF:
value = params.slipref * 100;
break;
case PF_MUMAX:
value = params.mumax * 10;
break;
case PF_ASRP:
value = params.asrp;
break;
case PF_ASRON:
value = params.asron;
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);
}