mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 02:09:30 +02:00
Allow shunt to be selected in the UI
This commit is contained in:
parent
4e31ce596a
commit
d34d9b2838
5 changed files with 91 additions and 12 deletions
|
@ -6,6 +6,8 @@
|
|||
#include "src/communication/can/comm_can.h"
|
||||
#include "src/devboard/utils/types.h"
|
||||
|
||||
enum class ShuntType { None = 0, BmwSbox = 1, Highest };
|
||||
|
||||
class CanShunt : public Transmitter, CanReceiver {
|
||||
public:
|
||||
virtual void setup() = 0;
|
||||
|
@ -35,4 +37,8 @@ class CanShunt : public Transmitter, CanReceiver {
|
|||
|
||||
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
|
||||
|
|
|
@ -2,7 +2,35 @@
|
|||
#include "Shunt.h"
|
||||
|
||||
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() {
|
||||
if (shunt) {
|
||||
return;
|
||||
|
@ -15,3 +43,25 @@ void setup_can_shunt() {
|
|||
}
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ void init_stored_settings() {
|
|||
(battery_chemistry_enum)settings.getUInt("BATTCHEM", (int)battery_chemistry_enum::NCA);
|
||||
user_selected_inverter_protocol = (InverterProtocolType)settings.getUInt("INVTYPE", (int)InverterProtocolType::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 batt1If = (comm_interface)settings.getUInt(settingName, (int)comm_interface::CanNative);
|
||||
|
|
|
@ -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),
|
||||
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") {
|
||||
return options_for_enum_with_none(
|
||||
(STOP_BUTTON_BEHAVIOR)settings.getUInt("EQSTOP", (int)STOP_BUTTON_BEHAVIOR::NOT_CONNECTED),
|
||||
|
@ -650,6 +661,14 @@ const char* getCANInterfaceName(CAN_Interface interface) {
|
|||
%CHGCOMM%
|
||||
</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'>
|
||||
%EQSTOP%
|
||||
</select>
|
||||
|
|
|
@ -432,30 +432,33 @@ void init_webserver() {
|
|||
if (p->name() == "inverter") {
|
||||
auto type = static_cast<InverterProtocolType>(atoi(p->value().c_str()));
|
||||
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") {
|
||||
auto type = static_cast<BatteryType>(atoi(p->value().c_str()));
|
||||
settings.saveUInt("BATTTYPE", (int)type);
|
||||
} else if (p->name() == "BATTCHEM") {
|
||||
auto type = static_cast<battery_chemistry_enum>(atoi(p->value().c_str()));
|
||||
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") {
|
||||
auto type = static_cast<comm_interface>(atoi(p->value().c_str()));
|
||||
settings.saveUInt("BATTCOMM", (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() == "INVCOMM") {
|
||||
auto type = static_cast<comm_interface>(atoi(p->value().c_str()));
|
||||
settings.saveUInt("INVCOMM", (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() == "CHGCOMM") {
|
||||
auto type = static_cast<comm_interface>(atoi(p->value().c_str()));
|
||||
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") {
|
||||
auto type = static_cast<comm_interface>(atoi(p->value().c_str()));
|
||||
settings.saveUInt("SHUNTCOMM", (int)type);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue