steering-wheel/Core/Src/params.c

107 lines
1.8 KiB
C

#include "params.h"
#include "can-halal.h"
#include "vehicle.h"
Params params = {0};
void params_init() {
params.bbal = 50;
params.plim = 20;
}
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_ASRI:
params.asri++;
break;
case PF_ASRON:
params.asron = 1;
break;
case PF_PLIM:
params.plim = (params.plim < 80) ? params.plim + 1 : 80;
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_ASRI:
if (params.asri > 0) {
params.asri--;
}
break;
case PF_ASRON:
params.asron = 0;
break;
case PF_PLIM:
params.plim = (params.plim > 2) ? params.plim - 1 : 2;
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_ASRI:
value = params.asri;
break;
case PF_ASRON:
value = params.asron;
break;
case PF_PLIM:
value = params.plim;
break;
default:
return;
}
vehicle_broadcast_param(param, value);
}