Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show MOSFET temperature from JKBMS #440

Merged
merged 4 commits into from
Apr 26, 2023
Merged
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
9 changes: 9 additions & 0 deletions etc/dbus-serialbattery/battery.py
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ def __init__(self, port, baud, address):
self.temp_sensors = None
self.temp1 = None
self.temp2 = None
self.temp_mos = None
self.cells: List[Cell] = []
self.control_charging = None
self.control_voltage = None
@@ -140,6 +141,8 @@ def to_temp(self, sensor: int, value: float) -> None:
self.temp1 = min(max(value, -20), 100)
if sensor == 2:
self.temp2 = min(max(value, -20), 100)
if sensor == 'mos':
self.temp_mos = min(max(value, -20), 100

def manage_charge_voltage(self) -> None:
"""
@@ -571,6 +574,12 @@ def get_max_temp(self) -> Union[float, None]:
return self.extract_from_temp_values(
extractor=lambda temp1, temp2: max(temp1, temp2)
)

def get_mos_temp(self) -> Union[float, None]:
if self.temp_mos is not None:
return self.temp_mos
else:
return None

def log_cell_data(self) -> bool:
if logger.getEffectiveLevel() > logging.INFO and len(self.cells) == 0:
2 changes: 2 additions & 0 deletions etc/dbus-serialbattery/dbushelper.py
Original file line number Diff line number Diff line change
@@ -224,6 +224,7 @@ def setup_vedbus(self):
# Create battery extras
self._dbusservice.add_path("/System/MinCellTemperature", None, writeable=True)
self._dbusservice.add_path("/System/MaxCellTemperature", None, writeable=True)
self._dbusservice.add_path("/System/MOSTemperature", None, writeable=True)
self._dbusservice.add_path(
"/System/MaxCellVoltage",
None,
@@ -386,6 +387,7 @@ def publish_dbus(self):
)
self._dbusservice["/System/MinCellTemperature"] = self.battery.get_min_temp()
self._dbusservice["/System/MaxCellTemperature"] = self.battery.get_max_temp()
self._dbusservice["/System/MOSTemperature"] = self.battery.get_mos_temp()

# Charge control
self._dbusservice[
5 changes: 5 additions & 0 deletions etc/dbus-serialbattery/jkbms.py
Original file line number Diff line number Diff line change
@@ -87,6 +87,11 @@ def read_status_data(self):
temp2 = unpack_from(">H", self.get_data(status_data, b"\x82", offset, 2))[0]
self.to_temp(1, temp1 if temp1 < 99 else (100 - temp1))
self.to_temp(2, temp2 if temp2 < 99 else (100 - temp2))

# MOSFET temperature
offset = cellbyte_count + 3
temp_mos = unpack_from(">H", self.get_data(status_data, b"\x80", offset, 2))[0]
self.to_temp('mos', temp_mos if temp_mos < 99 else (100 - temp_mos))

offset = cellbyte_count + 12
voltage = unpack_from(">H", self.get_data(status_data, b"\x83", offset, 2))[0]
9 changes: 9 additions & 0 deletions etc/dbus-serialbattery/qml/PageBattery.qml
Original file line number Diff line number Diff line change
@@ -118,6 +118,15 @@ MbPage {
displayUnit: user.temperatureUnit
}
}

MbItemValue {
description: qsTr("MOSFET temperature")
show: item.valid
item {
bind: service.path("/System/MOSTemperature")
displayUnit: user.temperatureUnit
}
}

MbItemValue {
description: qsTr("Air temperature")