def init(): global Turnouts global cleesObjects global Buttons global Outputs with open('clees_objects.json') as f: cleesObjects = json.load(f) Turnouts = cleesObjects["turnouts"] Buttons = cleesObjects["buttons"] Outputs = cleesObjects["outputs"] for i in range(0, len(Turnouts)): # Add internal variables Turnouts[i]['action'] = '' Turnouts[i]['curwid'] = 0 Turnouts[i]['cmd_topic'] = clees_mqtt.gettopicstr( 'cmd', 't', Turnouts[i]['id']) # Set default positions if Turnouts[i]['homeposition'] == 'T': init_width = Turnouts[i]['pwmwidththrown'] else: init_width = Turnouts[i]['pwmwidthclosed'] clees_io.Set_pca9685(Turnouts[i]['devicenr'], Turnouts[i]['pwmnr'], init_width) Turnouts[i]['curwid'] = init_width time.sleep(cleesObjects['homepositiondelayonstart']) # Make our IO buffer upp to speed with real values and not defaults clees_io.call_80Hz() clees_io.call_80Hz() clees_io.call_80Hz() clees_io.call_80Hz() for i in range(0, len(Buttons)): # Add internal variables if Buttons[i]['inverted'] == 1: Buttons[i]['curstate'] = 0 else: Buttons[i]['curstate'] = 1 for i in range(0, len(Outputs)): # Add internal variables Outputs[i]['cmd_topic'] = clees_mqtt.gettopicstr( 'cmd', 'o', Outputs[i]['id']) Outputs[i]['curstate'] = 0 if Outputs[i]['inverted'] == 1: Outputs[i]['curstate'] = 1 if Outputs[i]['devicetype'] == 'pcf8574': clees_io.Set_pcf8574_bit(Outputs[i]['devicenr'], Outputs[i]['pinnr'], Outputs[i]['curstate']) if Outputs[i]['devicetype'] == 'pcf8574A': clees_io.Set_pcf8574A_bit(Outputs[i]['devicenr'], Outputs[i]['pinnr'], Outputs[i]['curstate']) # Now lets check if Turnouts have slave outputs, eg turnout polarization releays for i in range(0, len(Turnouts)): if Turnouts[i]['slaveoutputid'] != '': # This turnout have a slave output that also shall be set to reflect turnout homepos if Turnouts[i]['homeposition'] == 'T': set_outputobject(Turnouts[i]['slaveoutputid'], 'activated') else: set_outputobject(Turnouts[i]['slaveoutputid'], 'deactivated') return (0)
def send_output_deactivated(i): global Outputs topic = clees_mqtt.gettopicstr('rep', 'o', Outputs[i]['id']) clees_mqtt.publish(topic, 'deactivated') return (0)
def send_turnout_thrown(i): global Turnouts topic = clees_mqtt.gettopicstr('rep', 't', Turnouts[i]['id']) clees_mqtt.publish(topic, 'thrown') return (0)
def send_turnout_changing(i): global Turnouts topic = clees_mqtt.gettopicstr('rep', 't', Turnouts[i]['id']) clees_mqtt.publish(topic, 'changing') return (0)
def send_button_deactivated(i): global Buttons topic = clees_mqtt.gettopicstr('rep', 'b', Buttons[i]['id']) msg = 'deactivated' clees_mqtt.publish(topic, msg) return (0)