Fix Master ID Selector and force refreshing module data grid
This commit is contained in:
parent
ac36ef74a8
commit
915ca498fb
3 changed files with 29 additions and 8 deletions
25
BmsApp.py
25
BmsApp.py
|
|
@ -96,6 +96,10 @@ class Controller:
|
|||
pub.subscribe(self.model.start_can, "view.start")
|
||||
pub.subscribe(self.model.stop_can, "view.stop")
|
||||
|
||||
pub.subscribe (self.view.update_battery_module_grid, "bms.module.update")
|
||||
|
||||
pub.subscribe (self.model.setter, "view.id_selector")
|
||||
|
||||
|
||||
class PmgrowBms:
|
||||
def __init__(self, add_printer=True):
|
||||
|
|
@ -104,6 +108,11 @@ class PmgrowBms:
|
|||
self.notifier = None
|
||||
self.listeners = [can.Printer()] if add_printer else []
|
||||
self.listeners.append(BmsListener(self))
|
||||
self.master_id = 0x02
|
||||
|
||||
def setter (self, id):
|
||||
print ("updating master id")
|
||||
self.master_id = id
|
||||
|
||||
@property
|
||||
def bms_id (self):
|
||||
|
|
@ -129,9 +138,8 @@ class PmgrowBms:
|
|||
full_id = (msg_prefix, master_id, msg_type)
|
||||
db_msg = db.get_message_by_frame_id(msg.arbitration_id)
|
||||
|
||||
id_chosen = int(self.choice_1.GetStringSelection(), 16)
|
||||
|
||||
if master_id == id_chosen:
|
||||
print(master_id, self.master_id)
|
||||
if master_id == self.master_id:
|
||||
if find_category(full_id, 0) == BMS_MSG_CAT.MODULE_DATA:
|
||||
try:
|
||||
decoded = db.decode_message(msg.arbitration_id, msg.data)
|
||||
|
|
@ -206,8 +214,6 @@ class BmsMonitorView(BmsMonitorFrame):
|
|||
if cat in pgrid_category:
|
||||
self.property_grid_page_info.AppendIn(cat.name, prop)
|
||||
|
||||
pub.subscribe (self.update_battery_module_grid, "bms.module.update")
|
||||
|
||||
def GetModuleVoltage(self, module_dict):
|
||||
keyString = 'BatS_Cell{}_V'
|
||||
return [module_dict.get(keyString.format(x), -1) for x in range(nCell)]
|
||||
|
|
@ -218,12 +224,19 @@ class BmsMonitorView(BmsMonitorFrame):
|
|||
|
||||
def update_battery_module_grid(self, state):
|
||||
i_module = self.spin_ctrl_1.GetValue()
|
||||
module_dict = self.state[i_module]
|
||||
module_dict = state[i_module]
|
||||
voltages = self.GetModuleVoltage(module_dict)
|
||||
bal_states = self.GetModuleBalState(module_dict)
|
||||
for i in range(nCell):
|
||||
self.grid_1.SetCellValue(i, 0, str(voltages[i]))
|
||||
self.grid_1.SetCellValue(i, 2, str(bal_states[i]))
|
||||
self.grid_1.ForceRefresh()
|
||||
|
||||
def OnIdChoice(self, event):
|
||||
print ("sending update request")
|
||||
pub.sendMessage("view.id_selector", id=int(self.choice_1.GetStringSelection(), 16))
|
||||
|
||||
event.Skip()
|
||||
|
||||
def OnToggle(self, event):
|
||||
if self.button_1.Value:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: UTF-8 -*-
|
||||
#
|
||||
# generated by wxGlade 0.9.6 on Thu Aug 6 14:36:04 2020
|
||||
# generated by wxGlade 0.9.6 on Tue Aug 11 19:12:46 2020
|
||||
#
|
||||
|
||||
import wx
|
||||
|
|
@ -35,6 +35,7 @@ class BmsMonitorFrame(wx.Frame):
|
|||
self.__do_layout()
|
||||
|
||||
self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle, self.button_1)
|
||||
self.Bind(wx.EVT_CHOICE, self.OnIdChoice, self.choice_1)
|
||||
# end wxGlade
|
||||
|
||||
def __set_properties(self):
|
||||
|
|
@ -106,6 +107,10 @@ class BmsMonitorFrame(wx.Frame):
|
|||
print("Event handler 'OnToggle' not implemented!")
|
||||
event.Skip()
|
||||
|
||||
def OnIdChoice(self, event): # wxGlade: BmsMonitorFrame.<event_handler>
|
||||
print("Event handler 'OnIdChoice' not implemented!")
|
||||
event.Skip()
|
||||
|
||||
# end of class BmsMonitorFrame
|
||||
|
||||
class BmsApp(wx.App):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- generated by wxGlade 0.9.6 on Thu Aug 6 14:36:03 2020 -->
|
||||
<!-- generated by wxGlade 0.9.6 on Tue Aug 11 19:12:43 2020 -->
|
||||
|
||||
<application class="BmsApp" encoding="UTF-8" for_version="3.0" header_extension=".h" indent_amount="4" indent_symbol="space" is_template="0" language="python" mark_blocks="1" name="app" option="0" overwrite="1" path="./BmsView.py" source_extension=".cpp" top_window="frame" use_gettext="1" use_new_namespace="1">
|
||||
<object class="BmsMonitorFrame" name="frame" base="EditFrame">
|
||||
|
|
@ -91,6 +91,9 @@
|
|||
<option>0</option>
|
||||
<border>0</border>
|
||||
<object class="wxChoice" name="choice_1" base="EditChoice">
|
||||
<events>
|
||||
<handler event="EVT_CHOICE">OnIdChoice</handler>
|
||||
</events>
|
||||
<selection>0</selection>
|
||||
<choices>
|
||||
<choice>0x02</choice>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue