コード例 #1
0
 def __init__(self, beetle):
     self.beetle = beetle
     self.front_heat = gpiozero.OutputDevice(22, active_high=False)
     self.back_heat = gpiozero.OutputDevice(23, active_high=False)
     self.init_time = time.time()
     self.last_poll = 0.0
     self.beetle.logger.info('Battery heater poller initialized')
コード例 #2
0
ファイル: controls.py プロジェクト: sysfian/sysfian-kotacon
	def __init__(this, status_q, masterPin, r1Pin, r2Pin, r3Pin, r4Pin):
		this.status_q = status_q
		this.masterRelay = gpiozero.OutputDevice(masterPin, active_high=False, initial_value=False)
		this.resistorRelays = [
			gpiozero.OutputDevice(r1Pin, active_high=False, initial_value=False),
			gpiozero.OutputDevice(r2Pin, active_high=False, initial_value=False),
			gpiozero.OutputDevice(r3Pin, active_high=False, initial_value=False),
			gpiozero.OutputDevice(r4Pin, active_high=False, initial_value=False)]

		this.speedSettings = {
			 1 : [0,0,0,0],
			 2 : [1,0,0,0],
			 3 : [0,1,0,0],
			 4 : [1,1,0,0],
			 5 : [1,0,1,0],
			 6 : [0,1,1,0],
			 7 : [1,1,1,0],
			 8 : [0,0,0,1],
			 9 : [1,0,0,1],
			10 : [0,1,0,1],
			11 : [1,1,0,1],
			12 : [0,0,1,1],
			13 : [1,0,1,1],
			14 : [0,1,1,1],
			15 : [1,1,1,1]
		}
		this.curSpeed = 1
コード例 #3
0
    def __init__(self,
                 clk_pin: int,
                 din_pin: int,
                 sleep: Callable = lambda: None,
                 pin_factory=None):
        '''
        Parameters:
        clk_pin: The RPi GPIO pin number for SCLK
        din_pin: The RPi GPIO pin number for DIN
        sleep: A function to sleep between each pin output value change
        pin_factory: Parameter passed to gpiozero constructors
        
        Regarding `sleep` parameter: Technically, the code has to wait a few microseconds between each pin state change. The datasheet says the TM1640 chip has an oscillation frequency of 450MHz, and a maximum clock frequency of 1MHz. However, given this is interpreted Python code running on Raspberry Pi, the amount of time between one state change statement and the next one is already long enough, so we don't need to wait, in practice.
        '''
        self.clk_pin = clk_pin
        self.din_pin = din_pin
        self.clk = gpiozero.OutputDevice(self.clk_pin,
                                         initial_value=True,
                                         pin_factory=pin_factory)
        self.din = gpiozero.OutputDevice(self.din_pin,
                                         initial_value=True,
                                         pin_factory=pin_factory)
        self.sleep = sleep

        self._brightness = None  # It's unknown at this time.
        self._command1_data()
コード例 #4
0
    def __init__ (self, state_file = None ):
        if state_file is None:
            state_file = STATE_FILE
        self.statefile = state_file
        self.reverse_of = { 'CLOSING': self.open, 'CLOSED': self.open, 
            'OPENING':self.close, 'OPEN': self.close }
        
        self.button = gpiozero.Button(BUTTON)
        self.pressure_sensor = gpiozero.Button(PRESSURE)
        self.open_led = gpiozero.LED(LED_O)
        self.close_led = gpiozero.LED(LED_C)
        self.open_relay = gpiozero.OutputDevice(RELAY_O)
        self.close_relay = gpiozero.OutputDevice(RELAY_C)

        self.led_of = {'OPENING': self.open_led, 'OPEN': self.open_led,
                'CLOSING': self.close_led, 'CLOSED': self.close_led }

        self.button.when_pressed = self.press_button
        self.pressure_sensor.when_pressed = self.sense_pressure
        
        try:
            handle = open(self.statefile)
            self.set_state(handle.read().rstrip())
            print(f"*** State File Says {self.state} ***")
            handle.close()
        except IOError:
            print(f"Failed to open state file {self.statefile}")
コード例 #5
0
    def __init__(
        self,
        control_panel_service,
        led_indexes,
        electromagnet_pin,
        jack_pin,
        manual_mode_jack_port_pin,
        marmitron_mode_jack_port_pin,
        table_button_pin,
        table_up_pin,
        table_down_pin,
        table_up_down_pins_active_high,
        table_max_amplitude_duration,
        table_up_down_minimum_delay,
        colors,
    ):
        self.service = control_panel_service

        self._status = None

        self.led_strip = neopixel.NeoPixel(board.D18, 9)
        self.led_tasks = {}
        self.scene_led_indexes = led_indexes["scene"]
        self.manual_mode_led_index = led_indexes["manual_mode"]
        self.marmitron_mode_led_index = led_indexes["marmitron_mode"]
        self.lights_status_led_index = led_indexes["lights_status"]
        self.menu_status_led_index = led_indexes["menu_status"]
        self.table_led_index = led_indexes["table"]
        self.electromagnet_led_index = led_indexes["electromagnet"]

        self.electromagnet = gpiozero.OutputDevice(electromagnet_pin)

        self.table_button = gpiozero.Button(table_button_pin)
        # Never have the table_up_pin and table_down_pin active at the same time or electronics might crash
        self.table_motor_up = gpiozero.OutputDevice(
            table_up_pin, active_high=table_up_down_pins_active_high)
        self.table_motor_up.off()
        self.table_motor_down = gpiozero.OutputDevice(
            table_down_pin, active_high=table_up_down_pins_active_high)
        self.table_motor_down.off()
        self.table_max_amplitude_duration = table_max_amplitude_duration
        self.table_up_down_minimum_delay = table_up_down_minimum_delay
        self.table_stop_motor_task = None
        self.table_led_task = None
        self.table_watch_button_task = LoopingCall(self.check_table_button)

        self.has_manual_mode_been_set_once = False
        self.jack = gpiozero.OutputDevice(jack_pin)
        self.jack.on()
        self.manual_mode_jack_port = gpiozero.InputDevice(
            manual_mode_jack_port_pin)
        self.marmitron_mode_jack_port = gpiozero.InputDevice(
            marmitron_mode_jack_port_pin)

        self.colors = colors

        self.check_jack_ports()
コード例 #6
0
ファイル: service.py プロジェクト: nosseb/justrelax
 def __init__(self, name, air_duct_controller, fan_pin, jack_pin,
              led_index):
     self.name = name
     self.ad_controller = air_duct_controller
     self.fan = gpiozero.OutputDevice(fan_pin)
     self.jack = gpiozero.OutputDevice(jack_pin)
     self.led_index = led_index
     self.connected_source = None
     self.last_connected_sources = []
コード例 #7
0
    def __init__(self, data, clk, fsync):
        self.dataPin  = gpiozero.OutputDevice(pin = data)
        self.clkPin   = gpiozero.OutputDevice(pin = clk)
        self.fsyncPin = gpiozero.OutputDevice(pin = fsync)

        self.fsyncPin.on()
        self.clkPin.on()
        self.dataPin.off()

        self.clk_freq = 25.0e6
コード例 #8
0
 def __init__(self, forward=None, backward=None, enable=None, pin_factory=None):
     if not all(p is not None for p in [forward, backward, enable]):
         raise gz.GPIOPinMissing(
             'forward and backward pins must be provided.'
             )
     super(PWM_Motor, self).__init__(
             forward_device=gz.OutputDevice(forward, pin_factory=pin_factory),
             backward_device=gz.OutputDevice(backward, pin_factory=pin_factory),
             enable_device=gz.PWMOutputDevice(enable, pin_factory=pin_factory),
             _order=('forward_device', 'backward_device', 'enable_device'),
             pin_factory=pin_factory
             )
コード例 #9
0
ファイル: pwdgen.py プロジェクト: dslusser/pwdgen
    def __init__(self, cfg, lcds, wordlist, rng):

        self.__button = gpiozero.Button(
            cfg['button_pin'],
            pull_up=True,
            ##                                        bounce_time=0.001,
            hold_time=3)
        self.__press_time = None

        self.__button.when_held = self.__on_hold
        self.__button.when_pressed = self.__on_press
        self.__button.when_released = self.__on_release

        self.__cfg = cfg
        self.__lcds = lcds
        self.__wordlist = wordlist
        self.__rng = rng
        self.__groundpin = self.__cfg['button_ground']
        if self.__groundpin != -1:
            # this is to allow the use of an arbitrary gpio as
            # ground for the button
            self.__ground = gpiozero.OutputDevice(self.__groundpin,
                                                  initial_value=False)
        else:
            self.__ground = None
コード例 #10
0
 def __init__(self):
     # Define like output the pin
     logger.info("Create Modem")
     self.pwr = gpiozero.OutputDevice(PWR_PIN,
                                      active_high=True,
                                      initial_value=True)
     return
コード例 #11
0
 def __init__(self, beetle):
     self.beetle = beetle
     self.pin = gpiozero.OutputDevice(13, active_high=False)
     self.beetle.state.set('dcdc', 'disabled')
     self.last_poll = 0.0
     self.next_poll = 5
     self.beetle.logger.info('DCDC poller initialized')
コード例 #12
0
 def __init__(self, beetle):
     self.beetle = beetle
     self.pin = gpiozero.OutputDevice(19, active_high=False)
     self.beetle.state.set('controller_fan', 'disabled')
     self.last_poll = 0.0
     self.next_poll = 10
     self.beetle.logger.info('Controller fan poller initialized')
コード例 #13
0
 def __init__(self, name, area, pin):
     self.name = name
     self.area = area
     self.runtimes = list()
     self.line = gpiozero.OutputDevice(pin)  #gpio pin number
     self.open = False
     self.override = False
コード例 #14
0
 def __init__(self, pins=None, values=None):
     self.logger = logging.getLogger('select')
     self.bits = []
     self.map = values
     self.invmap = {v:k for k,v in self.map.items()}
     for p in pins:
         self.bits.append(gpiozero.OutputDevice(p))
コード例 #15
0
    def getDistance():
        try:
            PIN_TRIGGER = generalSettings.distanceSensorPin_TRIGGER
            PIN_ECHO = generalSettings.distanceSensorPin_ECHO

            sensorOutput = gpiozero.OutputDevice(PIN_TRIGGER,
                                                 active_high=True,
                                                 initial_value=False)
            sensorInput = gpiozero.InputDevice(PIN_ECHO)

            sensorOutput.on()

            time.sleep(0.00001)

            sensorOutput.off()

            global pulse_start_time
            global pulse_end_time
            while not sensorInput.is_active:
                pulse_start_time = time.time()
            while sensorInput.is_active:
                pulse_end_time = time.time()
            pulse_duration = pulse_end_time - pulse_start_time
            distance = round(pulse_duration * 17150, 2)
            return distance
        finally:
            pass
コード例 #16
0
    def __init__(self, *args, **kwargs):
        super(OutputDevice, self).__init__(*args, **kwargs)

        pin = self.config["pin"]
        self.device = gpiozero.OutputDevice(pin)

        self._reset()
コード例 #17
0
ファイル: 4chAD9833.py プロジェクト: itplants/4chAD9833
    def __init__(self, data, clk, fsync):
        # Setup some defaults
        self.DacDisabled = False
        self.IntClkDisabled = False
        self.outputEnabled = False
        self.waveForm = SQUARE_WAVE
        self.waveForm0 = self.waveForm1 = self.waveForm 
        self.frequency0 = frequency1 = 40000	# 40 KHz sine wave to start
        self.phase0 = phase1 = 0.0	# 0 phase
        self.activeFreq = REG0
        self.activePhase = REG0
        self.freqReg = REG0
        self.phaseVal=REG0
        self.phaseReg=REG0
        self.waveFormReg = REG0

        self.dataPin  = dataPin
        self.clkPin   = clkPin
        self.fsyncPin = gpiozero.OutputDevice(pin = fsync)

        self.fsyncPin.on()
        self.clkPin.on()
        self.dataPin.off()

        # FPIO CLOCK Frwq = 25.0e6
        self.clk_freq = 25.0e6
コード例 #18
0
ファイル: Valve.py プロジェクト: haolee21/Exoskeleton
 def __init__(self, name, index, valveRecQue, valveRecLock):
     self.name = name
     self.pin = gp.OutputDevice(index)
     self.valveRecQue = valveRecQue
     self.valveRecLock = valveRecLock
     self.onStr = ',' + name + ',1'
     self.offStr = ',' + name + ',0'
コード例 #19
0
def init(relay_pin):
    # initialize the relay object
    print("Initializing relay object")
    global relay
    relay = gpiozero.OutputDevice(relay_pin,
                                  active_high=True,
                                  initial_value=False)
コード例 #20
0
ファイル: node.py プロジェクト: just-escape/justrelax
    def __init__(self, *args, **kwargs):
        super(VentsLocker, self).__init__(*args, **kwargs)

        power_pin = self.config["power_pin"]
        limit_switch_pin = self.config["limit_switch_pin"]
        self.unlock_frequency = self.config["unlock_frequency"]
        self.unlock_falling_edge_delay = self.config[
            "unlock_falling_edge_delay"]
        self.device = gpiozero.OutputDevice(power_pin)
        self.limit_switch_power = gpiozero.OutputDevice(
            self.config["limit_switch_power_pin"])
        self.limit_switch_power.on()
        self.limit_switch = gpiozero.InputDevice(limit_switch_pin)

        self.locked = self.config["locked_by_default"]

        self.check_lock_mistake()
コード例 #21
0
    def init_relays(self):
        self.relays = {}
        power_port = self.config['power']['port']
        print('Initilize power rele, port %d' % power_port)
        power_relay = gpiozero.OutputDevice(
            power_port, active_high=False, initial_value=False)
        self.relays[power_port] = power_relay

        ports_initialized = []
        for zone in self.config['zones']:
            port = zone['port']
            if port not in ports_initialized:
                ports_initialized.append(port)
                print('Initialize zone %s, port %d' % (zone['name'], port))
                zone_relay = gpiozero.OutputDevice(
                    port, active_high=False, initial_value=False)
                self.relays[port] = zone_relay
コード例 #22
0
 def __init__(self, pwmPin, forwardPin, backwardPin, encoderPin=None):
     '''
     `forwardPin`: the motor rotate forward when this pin is on\n
     `backwardPin`: the motor rotate backward when this pin is on\n
     `encoderPin`: pin of motor's encoder phase A, default to None
     '''
     self.pwmPin = gpiozero.OutputDevice(pwmPin)
     self.pwmPin.on()
     self.motor = gpiozero.Motor(forwardPin, backwardPin)
     if encoderPin is not None:
         self.encoderPin = gpiozero.InputDevice(encoderPin)
コード例 #23
0
ファイル: node.py プロジェクト: just-escape/justrelax
    def __init__(self, *args, **kwargs):
        super(Cylinders, self).__init__(*args, **kwargs)

        self.success = False
        self.difficulty = 'normal'
        self.delay = self.config['delay']

        self.index_mapping = self.config['index_mapping']

        self.slots = {}
        for key, slot in self.config['slots'].items():
            red_led = gpiozero.OutputDevice(slot['red_pin'])
            green_led = gpiozero.OutputDevice(slot['green_pin'])
            self.slots[key] = {
                'current_tag': None,
                'expected_tag': slot['expected_tag'],
                'red_led': red_led,
                'green_led': green_led,
                'delayed_task': None,
            }
コード例 #24
0
def main():
    relay_pin_list = [24, 23, 25, 17, 27, 22, 8, 7]
    relay_list = []

    for relay_pin in relay_pin_list:
        relay_list.append(
            gpiozero.OutputDevice(relay_pin,
                                  active_high=False,
                                  initial_value=False))

    all_off(relay_list)
コード例 #25
0
ファイル: PWMGen.py プロジェクト: haolee21/Exoskeleton
    def __init__(self, name, index, pwmRecQue):
        self.name = name
        self.pwmRecQue = pwmRecQue

        self.pwmVal = gp.OutputDevice(index)
        self.switch = mp.Event()
        self.dutyQue = mp.Queue(1)
        self.dutyLock = th.Lock()
        with self.dutyLock:
            self.dutyQue.put(0)
        self.setDuty(0)
コード例 #26
0
    def __init__(self, RELAY: str, _ip_address: str = IP):
        """
        :param _ip_address: TCP/IP address of source meter
        """
        self.pin = {'1': 14, '2': 15, '3': 18, '4': 23, '5': 24, '6': 25}

        self.ON = True
        self.OFF = False
        self.relay = gpiozero.OutputDevice(self.pin[RELAY],
                                           active_high=False,
                                           initial_value=False)
        pass
コード例 #27
0
    def __init__(self, config):
        """ Trigger door-strike actions by relays

        """

        self._config = config

        for door in self._config:
            relay = gpiozero.OutputDevice(self._config[door]["bcd_pin_number"],
                                          active_high=False,
                                          initial_value=False)
            self._config[door].update({"relay": relay})
コード例 #28
0
ファイル: flipdot.py プロジェクト: koolatron/annax_flipdot
    def __init__(self,
                 row_pins=DEFAULT_ROW_PINS,
                 col_pins=DEFAULT_COL_PINS,
                 strobe_pin=DEFAULT_STROBE_PIN,
                 data_pin=DEFAULT_DATA_PIN,
                 reset_pin=DEFAULT_RESET_PIN,
                 oe_pin=DEFAULT_OE_PIN,
                 rows=ROWS,
                 cols=COLS):
        self.strobe_pin = gpiozero.OutputDevice(strobe_pin, active_high=False)
        self.data_pin = gpiozero.OutputDevice(data_pin)
        self._reset_pin = gpiozero.OutputDevice(reset_pin)
        self._oe_pin = gpiozero.OutputDevice(oe_pin)

        self.row_pins = []
        self.col_pins = []

        self.rows = rows
        self.cols = cols

        for pin in row_pins:
            self.row_pins.append(gpiozero.OutputDevice(pin))

        for pin in col_pins:
            self.col_pins.append(gpiozero.OutputDevice(pin))

        self.all_pins = self.row_pins + self.col_pins + \
            [self.strobe_pin] + [self.data_pin]
        self.panel_state = [[0] * self.rows for i in range(self.cols)]

        for pin in self.all_pins:
            pin.off()

        self._reset_pin.on()
        self._oe_pin.on()
コード例 #29
0
ファイル: websocketserver.py プロジェクト: lifcey/lifceypi
def InitialazeRelays():
    i = 0

    rs = RepoSettings()
    relays = rs.get_relays()
    for RelayPin in relays:
        relay = gpiozero.OutputDevice(int(RelayPin[1]),
                                      active_high=False,
                                      initial_value=False)
        lstRelays.append(relay)
        # lstRelays[i].on()
        # time.sleep(0.2)
        i += 1
コード例 #30
0
    def __init__(self):
        self.door_open_button = Button(DOOR_OPEN_PIN)
        self.door_closed_button = Button(DOOR_CLOSED_PIN)
        self.relay = gpiozero.OutputDevice(RELAY_PIN,
                                           active_high=False,
                                           initial_value=False)
        self.wall_switch = Button(WALL_SWITCH_PIN)
        self.thread = threading.Thread(target=self.wall_input).start()
        self.lock = threading.Lock()
        self.ldr = LightSensor(LIGHTSENSOR_PIN)

        print('Controller class intialized:' +
              time.strftime('%I:%M:%S %p %A, %B %d'))
        print('1light detected:' + str(self.ldr.light_detected))