예제 #1
0
    def switch_eventA(self, switch):
        # look r a low-to-high on channel A
        if GPIO.input(self.pinA):
            # check pin B to see which was we are turning
            if not GPIO.input(self.pinB):
                self.encoder0Pos = self.encoder0Pos + 1  #cw
                direction = "cw"
            else:
                self.encoder0Pos = self.encoder0Pos - 1  #ccw
                direction = "ccw"
        else:
            #   // must be a high-to-low edge on channel A
            if GPIO.input(self.pinB):
                self.encoder0Pos = self.encoder0Pos + 1  #cw
                direction = "cw"
            else:
                self.encoder0Pos = self.encoder0Pos - 1  #ccw
                direction = "ccw"
        print "A", self.encoder0Pos, direction

        if not self.busy:
            self.busy = True
            if self.encoder0Pos < -1:
                print "Trigger Counter Clockwise", self.clockwise

                if self.clockwise: self.clockwise()
                self.encoder0Pos = 0
            if self.encoder0Pos > 1:
                print "Trigger CLockwise", self.counterclockwise
                if self.counterclockwise: self.counterclockwise()
                self.encoder0Pos = 0
            self.busy = False
        else:
            print "- skiping roatry event"
예제 #2
0
 def waitForChange(self, pin):
     self.input(pin)
     startstate = GPIO.input(self.PINS[pin]['pin'])
     newstate = startstate
     print "Startt State = ", startstate
     while newstate == startstate:
         newstate = GPIO.input(self.PINS[pin]['pin'])
         print newstate
         time.sleep(.1)
예제 #3
0
    def input(self, pin):
        if not self.PINS.has_key(pin):
            sys.stderr.write("pin %s does not exist\n" % (pin))
        else:
            if not self.PINS[pin]['setup']:
                if not self.PINS[pin]['input']:
                    sys.stderr.write("pin %s set as an output pin\n" % (pin))
                else:
                    if self.PINS[pin]['pup']:
                        GPIO.setup(self.PINS[pin]['pin'],
                                   1,
                                   pull_up_down=GPIO.PUD_UP)
                    else:
                        GPIO.setup(self.PINS[pin]['pin'], 1)

            if os.path.exists("ipc/manual_%s" % (pin)):
                os.unlink("ipc/manual_%s" % (pin))
                print "file existed returning True", pin
                return True
            state = GPIO.input(self.PINS[pin]['pin'])
            #			print "RAW STATE",self.PINS[pin]['pin'],state
            if self.PINS[pin]['inverse']:
                if state == True:
                    return False
                else:
                    return True
            return state
예제 #4
0
    def input(self, pin):
        if not self.PINS.has_key(pin):
            sys.stderr.write("pin %s does not exist\n" % (pin))
        else:
            if not self.PINS[pin]['setup']:
                if not self.PINS[pin]['input']:
                    sys.stderr.write("pin %s set as an output pin\n" % (pin))
                else:
                    if self.PINS[pin]['pup']:
                        GPIO.setup(self.PINS[pin]['pin'],
                                   1,
                                   pull_up_down=GPIO.PUD_UP)
                    else:
                        GPIO.setup(self.PINS[pin]['pin'], 1)

            state = GPIO.input(self.PINS[pin]['pin'])
            if self.PINS[pin]['inverse']:
                if state == True:
                    return False
                else:
                    return True


#			self._log("gpio.input %s %s" %(pin,state),importance=1)
            return state
예제 #5
0
 def switch_eventB(self, switch):
     # look r a low-to-high on channel A
     if GPIO.input(self.pinB):
         # check pin B to see which was we are turning
         if GPIO.input(self.pinA):
             self.encoder0Pos = self.encoder0Pos + 1  #cw
             direction = "cw"
         else:
             self.encoder0Pos = self.encoder0Pos - 1  #ccw
             direction = "ccw"
     else:
         #   // must be a high-to-l2ow edge on channel A
         if not GPIO.input(self.pinA):
             self.encoder0Pos = self.encoder0Pos + 1  #cw
             direction = "cw"
         else:
             self.encoder0Pos = self.encoder0Pos - 1  #ccw
             direction = "ccw"
     print "B", self.encoder0Pos, direction
예제 #6
0
    def switch_event(self, switch):
        if GPIO.input(self.pinA):
            self.rotary_a = 1
        else:
            self.rotary_a = 0

        if GPIO.input(self.pinB):
            self.rotary_b = 1
        else:
            self.rotary_b = 0

        self.rotary_c = self.rotary_a ^ self.rotary_b
        new_state = self.rotary_a * 4 + self.rotary_b * 2 + self.rotary_c * 1
        delta = (new_state - self.last_state) % 4
        self.last_state = new_state
        event = 0

        if delta == 1:
            if self.direction == self.CLOCKWISE:
                print "Clockwise"
                event = self.direction
            else:
                self.right = self.right + 1
                self.left = 0
                self.direction = self.CLOCKWISE
        elif delta == 3:
            if self.direction == self.ANTICLOCKWISE:
                print "Anticlockwise"
                event = self.direction
            else:
                self.left = self.left + 1
                self.right = 0
                self.direction = self.ANTICLOCKWISE

        if delta > 0:
            if not self.callback:
                print "callback", self.direction, self.left, self.right
                if self.left > 0:
                    print "LEFT"
                    self.left = 0
                if self.right > 0:
                    print "RIGHT"
                    self.right = 0
예제 #7
0
 def input(pin):
     GPIO.setup(pin, GPIO.IN)
     return GPIO.input(pin)