def close(self, event): log.debug("Closing LTCBackend") try: self.ignite(False) except PhidgetException: log.info("Unable to turn off ignite on quit") self.relay.close() self.core.close()
def __init__(self, set_status): log.info("Starting Backend") self.relay = IgnitionRelay() self.relay.add_callback(self.attach, "attach") self.core = CorePhidget() self.core.add_callback(self.attach, "attach") self.relay.shorepower.add_callback(self.output, 'value') self.set_status = set_status
def on_value(self, event): try: val = event.value except AttributeError: val = event.state if val is 0: # The sensors seem to return 0 when absent. self.status_ind.set_state('Unknown', 'Not Found') return newval = self.conversion(val) log.info("{}: {}{}".format(self.name, newval, self.unit)) if isinstance(newval, str): self.status_ind.text = '{} {}'.format(newval, self.unit) else: self.status_ind.text = '{:.1f} {}'.format(newval, self.unit) self.status_ind.background_color = self.nominal_value(newval)
def setShorepowerState(self, state): log.info("Setting shorepower state to {}".format(state)) self.ik.setOutputState(self.shorepower.index, state)
def setIgnitionRelayState(self, state): log.info("Setting ignition relay state to {}".format(state)) self.ik.setOutputState(self.relay.index, state)
def set_state(self, state): log.info("State changed:{}".format(state)) self.state_info.text = state self.state_info.color = self.states[state][1] self.state_message.text = self.states[state][0]
relay_panel.add_widget(sens4) relay_panel.add_widget(relay2) relay_panel.add_widget(sens6) relay_panel.add_widget(relay1) relay_panel.add_widget(sens9) backend.core.add_callback(status.on_attach, 'attach') backend.core.add_callback(status.on_detach, 'detach') backend.core.add_callback(status.on_error, 'error') backend.relay.add_callback(status.on_attach, 'attach') backend.relay.add_callback(status.on_detach, 'detach') backend.relay.add_callback(status.on_error, 'error') backend.relay.relay.add_callback(status.on_ignite, 'value') ctrl = LTCctrl(backend.ignite, backend.shorepower, status.set_state) backend.relay.shorepower.add_callback(ctrl.on_shorepower, "value") backend.relay.relay.add_callback(ctrl.on_ignite, "value") ltc = LTC() ltc.toplayout.add_widget(ctrl) ltc.toplayout.add_widget(status) ltc.indicators.add_widget(relay_panel) ltc.indicators.add_widget(input_panel) return ltc if __name__ == '__main__': log.info("Starting LTCCOM") LTCApp().run()