예제 #1
0
    def run_inner(self):
        """Perform one on/off/blink pulse."""
        try:
            item = self.blink_command_queue.get(block=True, timeout=self.blink_duration)
            self.blinking = item[0]
            if self.blinking:
                # Always begin opposite of current state for immediate visual feedback
                GPIO.output(self.output_pin, not GPIO.input(self.output_pin))
                # Calculate number of remaining on/off blink toggles after this one
                # A zero count means to keep blinking indefinitely
                self.blink_count = item[1] * 2 - 1 if item[1] else 0
            else:
                # Remember last non-blinking state of the light which will be restored
                # after finite blink count has completed.
                self.steady_state = item[1]
                GPIO.output(self.output_pin, item[1])
        except queue.Empty:
            if self.blinking:
                # If blinking a finite number of times, count each on/off transition
                if self.blink_count > 0:
                    self.blink_count -= 1
                    if self.blink_count == 0:
                        # Ensure at the end of finite blink count we always return to
                        # the last on/off steady state, even if a new blink was started
                        # before a previous blink has finished.
                        GPIO.output(self.output_pin, self.steady_state)
                        self.blinking = False

                # Toggle output if blinking indefinitely or finite count not exhausted
                if self.blinking:
                    # When blinking, invert every timeout expiration (we might have woken
                    # up for some other reason, but this appears to work in practice).
                    GPIO.output(self.output_pin, not GPIO.input(self.output_pin))
    def __init__(
        self,
        event_queue,
        config_name,
        d0_pin,
        d1_pin,
        on_scan=None,
        queue_size=DEFAULT_QUEUE_SIZE,
        timeout_in_ms=DEFAULT_TIMEOUT_IN_MS,
    ):
        super(WiegandGPIOReader, self).__init__(event_queue, config_name,
                                                int(d0_pin), int(d1_pin))
        self._on_scan = on_scan
        # The limited-size queue protects from a slow leak in case of deadlock, so
        # we can detect and output something (just a print for now)
        self.bitqueue = queue.Queue(int(queue_size))
        self.timeout_in_seconds = float(timeout_in_ms) / 1000

        if self._on_scan:
            GPIO.add_event_detect(self.d0_pin,
                                  GPIO.FALLING,
                                  callback=self.decode)
            GPIO.add_event_detect(self.d1_pin,
                                  GPIO.FALLING,
                                  callback=self.decode)
예제 #3
0
  def __init__(self, event_queue, config_name, input_pin, output_pin, on_down=None):
    super(Button, self).__init__(event_queue, config_name, int(input_pin), int(output_pin))

    self._on_down = on_down
    self.blink_command_queue = Queue.Queue()
    self.blink_duration = 0.5  # seconds
    self.blinking = False
    if self._on_down:
      GPIO.add_event_detect(self.input_pin, GPIO.FALLING, callback=self._callback, bouncetime=150)
예제 #4
0
 def __init__(self, event_queue, config_name, d0_pin, d1_pin, on_scan=None):
   # presently, i've dropped bit_len as a parameter.  likely i'm going to
   # swap this around to make it so that you can pass a decoding format to
   # make it easier to work with different encoding schemes.
   super(WiegandGPIOReader, self).__init__(event_queue, config_name,
           int(d0_pin), int(d1_pin))
   self._on_scan = on_scan
   if self._on_scan:
       GPIO.add_event_detect(self.d0_pin, GPIO.FALLING, callback=self.decode)
       GPIO.add_event_detect(self.d1_pin, GPIO.FALLING, callback=self.decode)
예제 #5
0
  def run_inner(self):
    next_mode = self.set_queue.get(block=True)
    if next_mode == OFF:
      GPIO.output(self.output_pin, False)
    elif next_mode == ON:
      GPIO.output(self.output_pin, True)
    elif next_mode in (BEEP, BEEPING):
      # TODO Support both types of piezo buzzer/transducer.
      # As-is, this provides a logic HIGH to make a 4KHz sound on PK-12N40PQ;
      # newer prototypes include one that requires the Pi to make a 4KHz
      # square wave, which should use pigpio instead of RPi.GPIO.
      print "Beeping"
      while True:
        if not self.set_queue.empty():
          print "Done beeping"
          break
        GPIO.output(self.output_pin, True)
        time.sleep(0.3)
        GPIO.output(self.output_pin, False)
        time.sleep(0.3)
        if next_mode == BEEP:
	  break
        print "...more beep"
    elif next_mode == HAPPY:
      print "Happy"
      # TODO use pigpio
      p = GPIO.PWM(self.output_pin, 440)
      if p is None:
        # FakeRPi.GPIO does this
        return
      p.start(50)
      time.sleep(0.5)
      p.ChangeFrequency(440 * 1.25)
      time.sleep(0.5)
      p.ChangeFrequency(440 * 1.5)
      time.sleep(0.5)
      p.stop()  # TODO make sure it ends up off
    elif next_mode == SAD:
      print "Sad"
      # TODO use pigpio
      p = GPIO.PWM(self.output_pin, 440 * 1.2)
      if p is None:
        # FakeRPi.GPIO does this
        return
      p.start(50)
      time.sleep(0.5)
      p.ChangeFrequency(440 * 0.75)
      time.sleep(0.5)
      p.stop()  # TODO make sure it ends up off
    else:
      print "Error", next_mode
예제 #6
0
  def __init__(self, event_queue, config_name, d0_pin, d1_pin, initial_output=GPIO.LOW):
    super(BaseGPIOPinThread, self).__init__(event_queue, config_name)

    self.d0_pin = d0_pin
    self.d1_pin = d1_pin

    GPIO.setmode(GPIO.BOARD)
    GPIO.setwarnings(False)  # for reusing pins
    if self.d0_pin:
      GPIO.setup(self.d0_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    if self.d1_pin:
      GPIO.setup(self.d1_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
예제 #7
0
 def run_inner(self):
   """Perform one on/off/blink pulse."""
   try:
     item = self.blink_command_queue.get(block=True, timeout=self.blink_duration)
     self.blinking = item[0]
     if self.blinking:
       # Always begin on; always turn off when disabling
       GPIO.output(self.output_pin, True)
     else:
       GPIO.output(self.output_pin, item[1])
   except Queue.Empty:
     if self.blinking:
       # When blinking, invert every timeout expiration (we might have woken
       # up for some other reason, but this appears to work in practice).
       GPIO.output(self.output_pin, not GPIO.input(self.output_pin))
예제 #8
0
 def run_inner(self, block=True):
   item = self.set_queue.get(block=block)
   next_mode = item[0]
   if next_mode == OFF:
     GPIO.output(self.output_pin, False)
   elif next_mode == ON:
     GPIO.output(self.output_pin, True)
   elif next_mode in (BEEP, BEEPING):
     # As-is, this provides a logic HIGH to make a 4KHz sound on PK-12N40PQ;
     print("Beeping")
     while True:
       if not self.set_queue.empty():
         print("Done beeping")
         break
       GPIO.output(self.output_pin, True)
       time.sleep(item[1])
       GPIO.output(self.output_pin, False)
       time.sleep(item[2])
       if next_mode == BEEP:
         break
       print("...more beep")
   else:
     print("Error", next_mode)
  def run_inner(self, block=True):
    item = self.set_queue.get(block=block)
    next_mode = item[0]
    if next_mode == OFF:
      GPIO.output(self.output_pin, False)
    elif next_mode == ON:
      GPIO.output(self.output_pin, True)
    elif next_mode in (BEEP, BEEPING):
      # As-is, this provides a logic HIGH to make a 4KHz sound on PK-12N40PQ;
      print "Beeping"
      while True:
        if not self.set_queue.empty():
          print "Done beeping"
          break
        GPIO.output(self.output_pin, True)
        time.sleep(item[1])
        GPIO.output(self.output_pin, False)
        time.sleep(item[2])
        if next_mode == BEEP:
	  break
        print "...more beep"
    else:
      print "Error", next_mode
예제 #10
0
  def __init__(self, event_queue, config_name, output_pin):
    super(Buzzer, self).__init__(event_queue, config_name, None, int(output_pin))
    self.set_queue = queue.Queue()

    GPIO.output(self.output_pin, False)
예제 #11
0
 def off(self):
   GPIO.output(self.output_pin, not self.output_on_val)
예제 #12
0
 def on(self):
   GPIO.output(self.output_pin, self.output_on_val)
  def __init__(self, event_queue, config_name, output_pin):
    super(Buzzer, self).__init__(event_queue, config_name, None, int(output_pin))
    self.set_queue = Queue.Queue(None)

    GPIO.output(self.output_pin, False)