module.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import json
  2. from heat import heat,wire_ntc,center_ntc
  3. from work_time import wt
  4. class Module():
  5. # 用于更新用户界面,被 class controller 调用
  6. # 基类,只能被上层继承和调用
  7. def __init__(self) -> None:
  8. self.heat = heat
  9. self.center_ntc = center_ntc
  10. self.wire_ntc = wire_ntc
  11. self.work_time = wt
  12. self.dat = {}
  13. def register(self, name, obj):
  14. self.obj.update({name: obj})
  15. def get_dat(self):
  16. self.dat.update({'heat': {"status": heat.status, 'pwr_percent': heat.duty}})
  17. self.dat.update({'ntc': {"wire_temp": self.wire_ntc.get_temperature(), 'center_temp':self.center_ntc.get_temperature()}})
  18. if not heat.status:
  19. self.work_time.init()
  20. self.dat.update({'time':{'start_time': self.work_time.start_time, 'run_time': self.work_time.get_run_time(), 'now_time': self.work_time.now_time}})
  21. return json.dumps(self.dat)
  22. def heat_on(self):
  23. self.heat.on()
  24. wt.init()
  25. # print('on')
  26. def heat_off(self):
  27. self.heat.off()
  28. # print('off')
  29. mod = Module()
  30. # print(mod.get_dat())