Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions vehicle/OVMS.V3/components/vehicle_smarteq/src/eq_can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,16 @@ void OvmsVehicleSmartEQ::IncomingFrameCan1(CAN_frame_t* p_frame) {
vehicle_smart_car_on((CAN_BYTE(0) & 0x40) > 0); // Drive Ready
break;
case 0x673:
// TPMS values only used, when CAN write is disabled, otherwise utilize PollReply_TPMS_InputCapt
if ( !m_enable_write )
// TPMS pressure values only used, when CAN write is disabled, otherwise utilize PollReply_TPMS_InputCapt
if (!m_enable_write)
{
REQ_DLC(7);
// Read TPMS pressure values:
for (int i = 0; i < 4; i++)
{
if (CAN_BYTE(2 + i) != 0xff)
{
m_tpms_pressure[i] = (float) CAN_BYTE(2 + i) * 3.1; // kPa
m_tpms_pressure[3-i] = (float) CAN_BYTE(2 + i) * 3.1; // kPa, counter m_tpms_pressure indexing FL=3, FR=2, RL=1, RR=0
}
}
}
Expand Down
18 changes: 17 additions & 1 deletion vehicle/OVMS.V3/components/vehicle_smarteq/src/eq_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,16 +803,32 @@ void OvmsVehicleSmartEQ::xsq_tpms_set(int verbosity, OvmsWriter* writer, OvmsCom

smarteq->CommandTPMSset(verbosity, writer);
}

OvmsVehicle::vehicle_command_t OvmsVehicleSmartEQ::CommandTPMSset(int verbosity, OvmsWriter* writer) {
float dummy_pressure = mt_dummy_pressure->AsFloat();
writer->printf("Setting dummy TPMS values (base pressure: %.1f kPa)\n", dummy_pressure);

for (int i = 0; i < 4; i++) {
m_tpms_pressure[i] = dummy_pressure + (i * 10); // kPa
m_tpms_temperature[i] = 21 + i; // Celsius
m_tpms_lowbatt[i] = false;
m_tpms_missing_tx[i] = false;
writer->printf(" Sensor %d: pressure=%.1f kPa, temp=%.1f°C\n",
i, m_tpms_pressure[i], m_tpms_temperature[i]);
}
writer->printf("set TPMS dummy pressure: %.2f temp: %.2f\n", dummy_pressure, m_tpms_temperature[0]);

setTPMSValue(); // update TPMS metrics

// Show what was actually set in metrics
writer->puts("\nAfter setTPMSValue():");
auto pressure = StdMetrics.ms_v_tpms_pressure->AsVector();
auto temp = StdMetrics.ms_v_tpms_temp->AsVector();
for (size_t i = 0; i < pressure.size(); i++) {
writer->printf(" Wheel %d: pressure=%.1f kPa, temp=%.1f°C\n",
(int)i, pressure[i], temp[i]);
}

writer->puts("TPMS dummy values set");
return Success;
}

Expand Down
27 changes: 4 additions & 23 deletions vehicle/OVMS.V3/components/vehicle_smarteq/src/eq_features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ void OvmsVehicleSmartEQ::setTPMSValue() {

std::vector<string> tpms_layout = OvmsVehicle::GetTpmsLayout();
int count = (int)tpms_layout.size();
std::vector<float> tpms_pressure(count);
std::vector<float> tpms_temp(count);
std::vector<short> tpms_alert(count);
std::vector<float> tpms_pressure(count, 0.0f);
std::vector<float> tpms_temp(count, 0.0f);
std::vector<short> tpms_alert(count, 0);

float _threshold_front = m_front_pressure;
float _threshold_rear = m_rear_pressure;
Expand All @@ -54,22 +54,11 @@ void OvmsVehicleSmartEQ::setTPMSValue() {
static const float PRESSURE_MIN = 10.0f; // Below this = sensor not working
static const float PRESSURE_MAX = 500.0f; // Above this = invalid reading
static const float TEMP_MIN = -40.0f;
static const float TEMP_MAX = 150.0f;
static const float TEMP_MAX = 90.0f;

for (int i=0; i < count; i++)
{
int indexcar = m_tpms_index[i];

// Bounds check for indexcar
if (indexcar < 0 || indexcar >= count)
{
ESP_LOGW(TAG, "Invalid TPMS index mapping: %d -> %d (max: %d)", i, indexcar, count-1);
tpms_pressure[i] = 0.0f;
tpms_temp[i] = 0.0f;
tpms_alert[i] = 0;
continue;
}

float _pressure = m_tpms_pressure[indexcar];
float _temp = m_tpms_temperature[indexcar];
bool _lowbatt = m_tpms_lowbatt[indexcar];
Expand All @@ -87,20 +76,12 @@ void OvmsVehicleSmartEQ::setTPMSValue() {
tpms_pressure[i] = _pressure;
_flag = true;
}
else
{
tpms_pressure[i] = 0.0f;
}

// Validate and set temperature
if (m_tpms_temp_enable && _temp >= TEMP_MIN && _temp < TEMP_MAX)
{
tpms_temp[i] = _temp;
}
else
{
tpms_temp[i] = 0.0f;
}

// Handle alert conditions only if sensor is working and alerts are enabled
if (!pressure_valid || !alerts_enabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ OvmsVehicleSmartEQ::OvmsVehicleSmartEQ() {
mt_tpms_alert = MyMetrics.InitVector<short> ("xsq.tpms.alert", SM_STALE_MID, nullptr, Other);
mt_tpms_low_batt = MyMetrics.InitVector<short> ("xsq.tpms.lowbatt", SM_STALE_MID, nullptr, Other);
mt_tpms_missing_tx = MyMetrics.InitVector<short> ("xsq.tpms.missing", SM_STALE_MID, nullptr, Other);
mt_dummy_pressure = MyMetrics.InitFloat("xsq.tpms.dummy", SM_STALE_NONE, 230, kPa); // Dummy pressure for TPMS alert testing
mt_dummy_pressure = MyMetrics.InitFloat("xsq.tpms.dummy", SM_STALE_NONE, 210, kPa); // Dummy pressure for TPMS alert testing
// 0x765 BCM metrics
mt_bcm_vehicle_state = MyMetrics.InitString("xsq.bcm.state", SM_STALE_MIN, "UNKNOWN", Other);
mt_bcm_gen_mode = MyMetrics.InitString("xsq.bcm.gen.mode", SM_STALE_MID, "UNKNOWN", Other);
Expand Down