# -*- coding: utf-8 -*- import RPi.GPIO as io import time def do_open_roof(pin_cmd_open_bcm=27, debug_level=0): """Ouvre le toit avec un moteur de toit Came. Exemple: import driver_came ; driver_came.do_open_roof(27,2) """ io.setwarnings(False) io.setmode(io.BCM) #set up GPIO using BCM numbering io.setup(pin_cmd_open_bcm,io.OUT) # make pin an output (=arduino 27 open) io.output(pin_cmd_open_bcm,1) time.sleep(3) io.output(pin_cmd_open_bcm,0) err=0 return err def do_stop_roof(pin_cmd_stop_bcm=4, debug_level=0): """Stope le toit avec un moteur de toit Came. Exemple: import driver_came ; driver_came.do_stop_roof(4,2) """ io.setwarnings(False) io.setmode(io.BCM) #set up GPIO using BCM numbering io.setup(pin_cmd_stop_bcm,io.OUT) # make pin an output (=arduino 25 stop) io.output(pin_cmd_stop_bcm,1) time.sleep(3) io.output(pin_cmd_stop_bcm,0) err=0 return err def do_close_roof(pin_cmd_close_bcm=23, debug_level=0): """Ferme le toit avec un moteur de toit Came. Exemple: import driver_came ; driver_came.do_close_roof(23,2) """ io.setwarnings(False) io.setmode(io.BCM) #set up GPIO using BCM numbering io.setup(pin_cmd_close_bcm,io.OUT) # make pin an output (=arduino 29 close) io.output(pin_cmd_close_bcm,1) time.sleep(3) io.output(pin_cmd_close_bcm,0) err=0 return err def get_data(pin_chk_power_bcm=26, pin_sw_manu_bcm=22, pin_sw_closed_bcm=5, pin_sw_opened_bcm=6, debug_level=0): """Lecture des etats des switchs du moteur de toit Came. Retourne un tuple, dans l'ordre: Un code de validité, Exemple: import driver_came ; driver_came.get_data(26,22,5,6,2) """ io.setwarnings(False) io.setmode(io.BCM) #set up GPIO using BCM numbering io.setup(pin_chk_power_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 48 24V) io.setup(pin_sw_manu_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 31 manu/auto) io.setup(pin_sw_closed_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 39 closed) io.setup(pin_sw_opened_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 41 opened) pin48 = io.input(pin_chk_power_bcm) pin31 = io.input(pin_sw_manu_bcm) pin39 = io.input(pin_sw_closed_bcm) pin41 = io.input(pin_sw_opened_bcm) if (debug_level==2): print("=== Bit states ===") disp ="pin48,gpio26,power24V ="+str(pin48)+"pin31,gpio22,auto/manu ="+str(pin31)+" pin39,gpio5,closed ="+str(pin39)+" pin41,gpio6,opened ="+str(pin41) print(disp) # === return err = 0 power_came = 0 if ( pin48==0 ): power_came_msg = "24Volts" power_came = 1 else: power_came_msg = "0Volt" err = err +1 if ( pin31==1 ): mode_came= 1 mode_came_msg = "Auto" else: mode_came = 0 mode_came_msg = "Manual" roof_state = -1 roof_state_msg = "Unknown" if ( (pin39==1) and (pin41==1) ): err = err + 2 roof_state_msg = "NoPower" elif ( (pin39==0) and (pin41==0) ): roof_state = 2 roof_state_msg = "Intermediate" elif ( (pin39==1) and (pin41==0) ): roof_state = 0 roof_state_msg = "Closed" elif ( (pin39==0) and (pin41==1) ): roof_state = 1 roof_state_msg = "Opened" if (debug_level>=1): print("=== Came states ===") print("power={} mode={} state={}".format(power_came_msg, mode_came_msg, roof_state_msg)); return err, power_came, mode_came, roof_state, power_came_msg, mode_came_msg, roof_state_msg, pin48, pin39, pin41,pin31