Allow shunt to be selected in the UI

This commit is contained in:
Jaakko Haakana 2025-07-11 22:43:38 +03:00
parent 4e31ce596a
commit d34d9b2838
5 changed files with 91 additions and 12 deletions

View file

@ -6,6 +6,8 @@
#include "src/communication/can/comm_can.h" #include "src/communication/can/comm_can.h"
#include "src/devboard/utils/types.h" #include "src/devboard/utils/types.h"
enum class ShuntType { None = 0, BmwSbox = 1, Highest };
class CanShunt : public Transmitter, CanReceiver { class CanShunt : public Transmitter, CanReceiver {
public: public:
virtual void setup() = 0; virtual void setup() = 0;
@ -35,4 +37,8 @@ class CanShunt : public Transmitter, CanReceiver {
extern CanShunt* shunt; extern CanShunt* shunt;
extern std::vector<ShuntType> supported_shunt_types();
extern const char* name_for_shunt_type(ShuntType type);
extern ShuntType user_selected_shunt_type;
#endif #endif

View file

@ -2,7 +2,35 @@
#include "Shunt.h" #include "Shunt.h"
CanShunt* shunt = nullptr; CanShunt* shunt = nullptr;
ShuntType user_selected_shunt_type = ShuntType::None;
#ifdef COMMON_IMAGE
#ifdef SELECTED_SHUNT_CLASS
#error "Compile time SELECTED_SHUNT_CLASS should not be defined with COMMON_IMAGE"
#endif
void setup_can_shunt() {
if (shunt) {
return;
}
switch (user_selected_shunt_type) {
case ShuntType::None:
shunt = nullptr;
return;
case ShuntType::BmwSbox:
shunt = new BmwSbox();
break;
default:
return;
}
if (shunt) {
shunt->setup();
}
}
#else
void setup_can_shunt() { void setup_can_shunt() {
if (shunt) { if (shunt) {
return; return;
@ -15,3 +43,25 @@ void setup_can_shunt() {
} }
#endif #endif
} }
#endif
extern std::vector<ShuntType> supported_shunt_types() {
std::vector<ShuntType> types;
for (int i = 0; i < (int)ShuntType::Highest; i++) {
types.push_back((ShuntType)i);
}
return types;
}
extern const char* name_for_shunt_type(ShuntType type) {
switch (type) {
case ShuntType::None:
return "None";
case ShuntType::BmwSbox:
return BmwSbox::Name;
default:
return nullptr;
}
}

View file

@ -79,6 +79,7 @@ void init_stored_settings() {
(battery_chemistry_enum)settings.getUInt("BATTCHEM", (int)battery_chemistry_enum::NCA); (battery_chemistry_enum)settings.getUInt("BATTCHEM", (int)battery_chemistry_enum::NCA);
user_selected_inverter_protocol = (InverterProtocolType)settings.getUInt("INVTYPE", (int)InverterProtocolType::None); user_selected_inverter_protocol = (InverterProtocolType)settings.getUInt("INVTYPE", (int)InverterProtocolType::None);
user_selected_charger_type = (ChargerType)settings.getUInt("CHGTYPE", (int)ChargerType::None); user_selected_charger_type = (ChargerType)settings.getUInt("CHGTYPE", (int)ChargerType::None);
user_selected_shunt_type = (ShuntType)settings.getUInt("SHUNTTYPE", (int)ShuntType::None);
auto readIf = [](const char* settingName) { auto readIf = [](const char* settingName) {
auto batt1If = (comm_interface)settings.getUInt(settingName, (int)comm_interface::CanNative); auto batt1If = (comm_interface)settings.getUInt(settingName, (int)comm_interface::CanNative);

View file

@ -187,6 +187,17 @@ String settings_processor(const String& var, BatteryEmulatorSettingsStore& setti
return options_for_enum((comm_interface)settings.getUInt("CHGCOMM", (int)comm_interface::CanNative), return options_for_enum((comm_interface)settings.getUInt("CHGCOMM", (int)comm_interface::CanNative),
name_for_comm_interface); name_for_comm_interface);
} }
if (var == "SHUNTTYPE") {
return options_for_enum_with_none((ShuntType)settings.getUInt("SHUNTTYPE", (int)ShuntType::None),
name_for_shunt_type, ShuntType::None);
}
if (var == "SHUNTCOMM") {
return options_for_enum((comm_interface)settings.getUInt("SHUNTCOMM", (int)comm_interface::CanNative),
name_for_comm_interface);
}
if (var == "EQSTOP") { if (var == "EQSTOP") {
return options_for_enum_with_none( return options_for_enum_with_none(
(STOP_BUTTON_BEHAVIOR)settings.getUInt("EQSTOP", (int)STOP_BUTTON_BEHAVIOR::NOT_CONNECTED), (STOP_BUTTON_BEHAVIOR)settings.getUInt("EQSTOP", (int)STOP_BUTTON_BEHAVIOR::NOT_CONNECTED),
@ -650,6 +661,14 @@ const char* getCANInterfaceName(CAN_Interface interface) {
%CHGCOMM% %CHGCOMM%
</select> </select>
<label>Shunt: </label><select name='SHUNT'>
%SHUNTTYPE%
</select>
<label>Shunt comm I/F: </label><select name='SHUNTCOMM'>
%SHUNTCOMM%
</select>
<label>Equipment stop button: </label><select name='EQSTOP'> <label>Equipment stop button: </label><select name='EQSTOP'>
%EQSTOP% %EQSTOP%
</select> </select>

View file

@ -432,30 +432,33 @@ void init_webserver() {
if (p->name() == "inverter") { if (p->name() == "inverter") {
auto type = static_cast<InverterProtocolType>(atoi(p->value().c_str())); auto type = static_cast<InverterProtocolType>(atoi(p->value().c_str()));
settings.saveUInt("INVTYPE", (int)type); settings.saveUInt("INVTYPE", (int)type);
} else if (p->name() == "INVCOMM") {
auto type = static_cast<comm_interface>(atoi(p->value().c_str()));
settings.saveUInt("INVCOMM", (int)type);
} else if (p->name() == "battery") { } else if (p->name() == "battery") {
auto type = static_cast<BatteryType>(atoi(p->value().c_str())); auto type = static_cast<BatteryType>(atoi(p->value().c_str()));
settings.saveUInt("BATTTYPE", (int)type); settings.saveUInt("BATTTYPE", (int)type);
} else if (p->name() == "BATTCHEM") { } else if (p->name() == "BATTCHEM") {
auto type = static_cast<battery_chemistry_enum>(atoi(p->value().c_str())); auto type = static_cast<battery_chemistry_enum>(atoi(p->value().c_str()));
settings.saveUInt("BATTCHEM", (int)type); settings.saveUInt("BATTCHEM", (int)type);
} else if (p->name() == "charger") {
auto type = static_cast<ChargerType>(atoi(p->value().c_str()));
settings.saveUInt("CHGTYPE", (int)type);
} else if (p->name() == "EQSTOP") {
auto type = static_cast<STOP_BUTTON_BEHAVIOR>(atoi(p->value().c_str()));
settings.saveUInt("EQSTOP", (int)type);
} else if (p->name() == "BATTCOMM") { } else if (p->name() == "BATTCOMM") {
auto type = static_cast<comm_interface>(atoi(p->value().c_str())); auto type = static_cast<comm_interface>(atoi(p->value().c_str()));
settings.saveUInt("BATTCOMM", (int)type); settings.saveUInt("BATTCOMM", (int)type);
} else if (p->name() == "BATT2COMM") { } else if (p->name() == "charger") {
auto type = static_cast<comm_interface>(atoi(p->value().c_str())); auto type = static_cast<ChargerType>(atoi(p->value().c_str()));
settings.saveUInt("BATT2COMM", (int)type); settings.saveUInt("CHGTYPE", (int)type);
} else if (p->name() == "INVCOMM") {
auto type = static_cast<comm_interface>(atoi(p->value().c_str()));
settings.saveUInt("INVCOMM", (int)type);
} else if (p->name() == "CHGCOMM") { } else if (p->name() == "CHGCOMM") {
auto type = static_cast<comm_interface>(atoi(p->value().c_str())); auto type = static_cast<comm_interface>(atoi(p->value().c_str()));
settings.saveUInt("CHGCOMM", (int)type); settings.saveUInt("CHGCOMM", (int)type);
} else if (p->name() == "EQSTOP") {
auto type = static_cast<STOP_BUTTON_BEHAVIOR>(atoi(p->value().c_str()));
settings.saveUInt("EQSTOP", (int)type);
} else if (p->name() == "BATT2COMM") {
auto type = static_cast<comm_interface>(atoi(p->value().c_str()));
settings.saveUInt("BATT2COMM", (int)type);
} else if (p->name() == "shunt") {
auto type = static_cast<ShuntType>(atoi(p->value().c_str()));
settings.saveUInt("SHUNTTYPE", (int)type);
} else if (p->name() == "SHUNTCOMM") { } else if (p->name() == "SHUNTCOMM") {
auto type = static_cast<comm_interface>(atoi(p->value().c_str())); auto type = static_cast<comm_interface>(atoi(p->value().c_str()));
settings.saveUInt("SHUNTCOMM", (int)type); settings.saveUInt("SHUNTCOMM", (int)type);