Ejemplo n.º 1
0
  def initGpio(self, gpio, a, b, c, d, e, f):
    if gpio == None:
      self.gpio = wiringpi2.GPIO(wiringpi2.GPIO.WPI_MODE_PINS)
    else:
      self.gpio = gpio

    # Setup ShiftReg
    self.pin_s_clock = 1
    self.pin_s_data = 6
    self.pin_s_latch = 5
    self.sRegBase = 100
    self.sRegPins = 6
    self.sReg = wiringpi2.sr595Setup(self.sRegBase, self.sRegPins, self.pin_s_data, self.pin_s_clock, self.pin_s_latch)

    # ShiftReg 3 wire
    self.gpio.pinMode(self.pin_s_clock, self.gpio.OUTPUT)
    self.gpio.pinMode(self.pin_s_data,  self.gpio.OUTPUT)
    self.gpio.pinMode(self.pin_s_latch, self.gpio.OUTPUT) 

    # LCD Pins (on the 595 end)
    self.pin_rs = self.sRegBase + 0 # rs
    self.pin_e =  self.sRegBase + 5 # e
    self.pin_d4 = self.sRegBase + 1 # d4
    self.pin_d5 = self.sRegBase + 2 # d5
    self.pin_d6 = self.sRegBase + 3 # d6
    self.pin_d7 = self.sRegBase + 4 # d7
Ejemplo n.º 2
0
    def initGpio(self, gpio, a, b, c, d, e, f):
        if gpio == None:
            self.gpio = wiringpi2.GPIO(wiringpi2.GPIO.WPI_MODE_PINS)
        else:
            self.gpio = gpio

        # Setup ShiftReg
        self.pin_s_clock = 1
        self.pin_s_data = 6
        self.pin_s_latch = 5
        self.sRegBase = 100
        self.sRegPins = 6
        self.sReg = wiringpi2.sr595Setup(self.sRegBase, self.sRegPins,
                                         self.pin_s_data, self.pin_s_clock,
                                         self.pin_s_latch)

        # ShiftReg 3 wire
        self.gpio.pinMode(self.pin_s_clock, self.gpio.OUTPUT)
        self.gpio.pinMode(self.pin_s_data, self.gpio.OUTPUT)
        self.gpio.pinMode(self.pin_s_latch, self.gpio.OUTPUT)

        # LCD Pins (on the 595 end)
        self.pin_rs = self.sRegBase + 0  # rs
        self.pin_e = self.sRegBase + 5  # e
        self.pin_d4 = self.sRegBase + 1  # d4
        self.pin_d5 = self.sRegBase + 2  # d5
        self.pin_d6 = self.sRegBase + 3  # d6
        self.pin_d7 = self.sRegBase + 4  # d7
Ejemplo n.º 3
0
          '(pulsanti e interruttori sono in numero diverso)')
    sys.exit(0)

'''parametri preimpostati all'avvio, da non modificare'''
start = [datetime(year=2000,month=01,day=01) for i in range(numerozone)]
end   = [datetime(year=2000,month=01,day=02) for i in range(numerozone)]
days  = ['lunedi','martedi','mercoledi',
         'giovedi','venerdi','sabato','domenica']
'''assegnazione numeri ai pin dello shift register (dal 100 in su)'''
pinBase = 100
RS  = pinBase + 0
E   = RS  + 1
DB4 = E + 1
DB5 = DB4 + 1
DB6 = DB5 + 1
DB7 = DB6 + 1
'''setup iniziale wiringpi'''
wpi.wiringPiSetup()
wpi.pinMode(dataPin, 1)
wpi.pinMode(clockPin, 1)
wpi.pinMode(latchPin, 1)
'''inizializzazione shift register e lcd -- da testare'''
wpi.sr595Setup(pinBase, 6, dataPin, clockPin, latchPin)
lcd = wpi.lcdInit(
    4, 16, 4,
    RS, E, DB4, DB5, DB6, DB7,
    0,0,0,0
    )
logtime = Queue.Queue()
lcdput = Queue.Queue()
def enable_device():
    """enable the specified device """
    try:
        devices = cm.hardware.devices

        for key in devices.keys():
            device = key
            device_slaves = devices[key]

            # mcp23017
            if device.lower() == "mcp23017":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23017Setup(int(params['pinBase']),
                                           int(params['i2cAddress'],
                                               16))

            # mcp23s17
            elif device.lower() == "mcp23s17":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23s17Setup(int(params['pinBase']),
                                           int(params['spiPort'],
                                               16),
                                           int(params['devId']))

            # TODO: Devices below need testing, these should work but
            # could not verify due to lack of hardware

            # mcp23016
            elif device.lower() == "mcp23016":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23016Setup(int(params['pinBase']),
                                           int(params['i2cAddress'],
                                               16))

            # mcp23s08 - Needs Testing
            elif device.lower() == "mcp23008":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23008Setup(int(params['pinBase']),
                                           int(params['i2cAddress'],
                                               16))

            # mcp23s08 - Needs Testing
            elif device.lower() == "mcp23s08":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23s08Setup(int(params['pinBase']),
                                           int(params['spiPort'],
                                               16),
                                           int(params['devId']))

            # sr595 - Needs Testing
            elif device.lower() == "sr595":
                for slave in device_slaves:
                    params = slave
                    wiringpi.sr595Setup(int(params['pinBase']),
                                        int(params['numPins']),
                                        int(params['dataPin']),
                                        int(params['clockPin']),
                                        int(params['latchPin']))

            # pcf8574
            elif device.lower() == "pcf8574":
                for slave in device_slaves:
                    params = slave
                    wiringpi.pcf8574Setup(int(params['pinBase']),
                                          int(params['i2cAddress'],
                                              16))

            else:
                logging.error("Device defined is not supported, please check "
                              "your devices settings: " + str(device))
    except Exception as error:
        logging.debug("Error setting up devices, please check your devices "
                      "settings.")
        logging.debug(error)
def enable_device():
    """enable the specified device """
    try:
        devices = cm.hardware.devices

        for key in devices.keys():
            device = key
            device_slaves = devices[key]

            # mcp23017
            if device.lower() == "mcp23017":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23017Setup(int(params['pinBase']),
                                           int(params['i2cAddress'], 16))

            # mcp23s17
            elif device.lower() == "mcp23s17":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23s17Setup(int(params['pinBase']),
                                           int(params['spiPort'], 16),
                                           int(params['devId']))

            # TODO: Devices below need testing, these should work but
            # could not verify due to lack of hardware

            # mcp23016
            elif device.lower() == "mcp23016":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23016Setup(int(params['pinBase']),
                                           int(params['i2cAddress'], 16))

            # mcp23s08 - Needs Testing
            elif device.lower() == "mcp23008":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23008Setup(int(params['pinBase']),
                                           int(params['i2cAddress'], 16))

            # mcp23s08 - Needs Testing
            elif device.lower() == "mcp23s08":
                for slave in device_slaves:
                    params = slave
                    wiringpi.mcp23s08Setup(int(params['pinBase']),
                                           int(params['spiPort'], 16),
                                           int(params['devId']))

            # sr595 - Needs Testing
            elif device.lower() == "sr595":
                for slave in device_slaves:
                    params = slave
                    wiringpi.sr595Setup(int(params['pinBase']),
                                        int(params['numPins']),
                                        int(params['dataPin']),
                                        int(params['clockPin']),
                                        int(params['latchPin']))

            # pcf8574
            elif device.lower() == "pcf8574":
                for slave in device_slaves:
                    params = slave
                    wiringpi.pcf8574Setup(int(params['pinBase']),
                                          int(params['i2cAddress'], 16))

            else:
                logging.error("Device defined is not supported, please check "
                              "your devices settings: " + str(device))
    except Exception as error:
        logging.debug("Error setting up devices, please check your devices "
                      "settings.")
        logging.debug(error)