示例#1
0
    def __init__(self):
        global mraa
        try:
            import mraa as mraa
        except ImportError:
            raise ImportError('pingo.galileo.Galileo2 requires mraa installed')

        super(Galileo2, self).__init__()

        self.PIN_MODES = {
            pingo.IN: mraa.DIR_IN,
            pingo.OUT: mraa.DIR_OUT,
        }

        self.PIN_STATES = {
            pingo.HIGH: 1,
            pingo.LOW: 0,
        }

        pwm_pin_numbers = [3, 5, 6, 9, 10, 11, 13]
        digital_pin_numbers = [1, 2, 4, 7, 8, 12]

        self._add_pins(
            [pingo.PwmPin(self, location) for location in pwm_pin_numbers] + [
                pingo.DigitalPin(self, location)
                for location in digital_pin_numbers
            ] + [
                pingo.AnalogPin(self, 'A' + location, 12)
                for location in '012345'
            ])

        self.mraa_pins, self.mraa_analogs, self.mraa_pwms = {}, {}, {}
示例#2
0
    def __init__(self, host, verbose=False):

        super(ArduinoYun, self).__init__()

        self.yun = YunBridge(host, verbose)

        self.PIN_MODES = {
            pingo.IN: 'input',
            pingo.OUT: 'output',
        }

        self.PIN_STATES = {
            pingo.HIGH: 1,
            pingo.LOW: 0,
        }

        pwm_pin_numbers = [3, 5, 6, 9, 10, 11, 13]
        digital_pin_numbers = [0, 1, 2, 4, 7, 8, 12]

        self._add_pins(
            [pingo.PwmPin(self, location) for location in pwm_pin_numbers] + [
                pingo.DigitalPin(self, location)
                for location in digital_pin_numbers
            ] + [
                pingo.AnalogPin(self, 'A' + location, 10)
                for location in '012345'
            ])
示例#3
0
 def __init__(self, server):
     self.server = server
     response = urlopen(server)
     if response.code != 200:
         raise Exception(u'HTTPBoard not found on server {}'.format(server))
     response = json.load(response)
     pins = json.loads(response['pins'])
     gpio_pins = []
     ground_pins = []
     vcc_pins = []
     pwm_pins = []
     for pin, value in pins.items():
         # TODO: serialize the pin (and/or the board) to do this in a better way
         if 'GroundPin' in value:
             ground_pins.append(pingo.GroundPin(self, pin))
         elif 'VccPin' in value:
             voltage = float(value[:-2].split(' ')[1])
             vcc_pins.append(pingo.VccPin(self, pin, voltage))
         elif 'PwmPin' in value:
             gpio_id = value.split(' ')[1].split('@')[0]
             pwm_pins.append(pingo.PwmPin(self, pin, gpio_id))
         elif 'DigitalPin' in value:
             gpio_id = value.split(' ')[1].split('@')[0]
             gpio_pins.append(pingo.DigitalPin(self, pin, gpio_id))
     self._add_pins(ground_pins + vcc_pins + gpio_pins + pwm_pins)
示例#4
0
    def __init__(self):
        global grovepi
        try:
            import grovepi as grovepi  # noqa
        except ImportError:
            raise ImportError('pingo.rpi.GrovePi requires grovepi installed')

        super(GrovePi, self).__init__()

        # location: gpio_id
        self.ANALOG_PINS = {'A0': 14, 'A1': 15, 'A2': 16, 'A3': 17}

        self.PIN_MODES = {pingo.IN: 'INPUT', pingo.OUT: 'OUTPUT'}

        self.PIN_STATES = {pingo.HIGH: 1, pingo.LOW: 0}

        pwm_pins = [3, 5, 6]
        digital_pins = [0, 1, 2, 4, 7, 8, 9]

        self._add_pins(
            [pingo.PwmPin(self, location) for location in pwm_pins] +
            [pingo.DigitalPin(self, location) for location in digital_pins] + [
                pingo.AnalogPin(self, location, 10, gpio_id)
                for location, gpio_id in self.ANALOG_PINS.items()
            ])
示例#5
0
    def __init__(self):
        global GPIO
        try:
            import RPi.GPIO as GPIO
        except ImportError:
            raise ImportError(
                'pingo.rpi.RaspberryPi requires RPi.GPIO installed')

        super(RaspberryPi, self).__init__()
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(True)

        pins = [
            pingo.VccPin(self, 1, 3.3),
            pingo.VccPin(self, 2, 5.0),
            pingo.VccPin(self, 4, 5.0),
            pingo.VccPin(self, 17, 3.3)
        ]

        pins += [pingo.GroundPin(self, n) for n in self.GROUNDS_LIST]

        pins += [
            pingo.PwmPin(self, location, gpio_id)
            for location, gpio_id in self.PWM_PIN_MAP.items()
        ]

        self._add_pins(pins)
        self._rpi_pwm = {}
示例#6
0
    def __init__(self):
        global mraa
        try:
            import mraa as mraa
        except ImportError:
            raise ImportError('pingo.galileo.Galileo2 requires mraa installed')

        super(Galileo2, self).__init__()

        self.PIN_MODES = {
            pingo.IN: mraa.DIR_IN,
            pingo.OUT: mraa.DIR_OUT,
        }

        self.PIN_STATES = {
            pingo.HIGH: 1,
            pingo.LOW: 0,
        }

        self._add_pins([
            pingo.PwmPin(self, location)
            for location in [3, 5, 6, 9, 10, 11, 13]
        ] + [
            pingo.DigitalPin(self, location)
            for location in [1, 2, 4, 7, 8, 12]
        ] + [
            pingo.AnalogPin(self, 'A' + location, 12) for location in '012345'
        ])

        self.mraa_pins = {
            location: mraa.Gpio(location)
            for location in range(1, 14)
        }

        self.mraa_analogs = {
            'A' + location: mraa.Aio(int(location))
            for location in '012345'
        }

        self.mraa_pwms = {
            location: mraa.Pwm(location)
            for location in [3, 5, 6, 9, 10, 11, 13]
        }
示例#7
0
文件: ghost.py 项目: juniortada/pingo
    def __init__(self, filepath=None):
        super(GhostBoard, self).__init__()

        # Arduino ATmega168/328 pin mapping
        pins = set([
            pingo.DigitalPin(self, 0),
            pingo.DigitalPin(self, 1),
            pingo.DigitalPin(self, 2),
            pingo.PwmPin(self, 3),
            pingo.DigitalPin(self, 4),
            pingo.VccPin(self, 'VCC', 5.0),
            pingo.GroundPin(self, 'GND'),
            pingo.PwmPin(self, 5),
            pingo.PwmPin(self, 6),
            pingo.DigitalPin(self, 7),
            pingo.DigitalPin(self, 8),
            pingo.AnalogPin(self, 'A5', 10),
            pingo.AnalogPin(self, 'A4', 10),
            pingo.AnalogPin(self, 'A3', 10),
            pingo.AnalogPin(self, 'A2', 10),
            pingo.AnalogPin(self, 'A1', 10),
            pingo.AnalogPin(self, 'A0', 10),
            pingo.GroundPin(self, 'GND'),
            pingo.VccPin(self, 'AREF', 5.0),
            pingo.VccPin(self, 'AVCC', 5.0),
            pingo.DigitalPin(self, 12),
            pingo.DigitalPin(self, 13),
            pingo.PwmPin(self, 11),
            pingo.PwmPin(self, 10),
            pingo.PwmPin(self, 9),
        ])

        self._add_pins(pins)

        self._pin_states = pingo.util.StrKeyDict()
        # All pins start on LOW
        # FIXME: use "LOW" instead of 0
        for location, pin in self.pins.iteritems():
            self._pin_states[location] = 0 if hasattr(pin, 'state') else None

        # Pin 8 starts on HIGH
        self._pin_states[8] = 1