Пример #1
0
    def __init__(self,
                 channel,
                 offset=-19,
                 lock=True,
                 bus_number=None,
                 address=0x40):
        ''' Init a servo on specific channel, this offset '''
        if channel < 0 or channel > 16:
            raise ValueError(
                "Servo channel \"{0}\" is not in (0, 15).".format(channel))
        if self._DEBUG:
            print(self._DEBUG_INFO, "Debug on")
        self.channel = channel
        self.offset = offset
        self.lock = lock

        self.pwm = PWM(bus_number=bus_number, address=address)
        self.frequency = self._FREQUENCY
        self.write(90)
Пример #2
0
    def __init__(self, debug=False, bus_number=1, db="config"):
        ''' Init the direction channel and pwm channel '''
        self.forward_A = True
        self.forward_B = True

        self.db = fileDB(db=db)

        self.forward_A = int(self.db.get('forward_A', default_value=1))
        self.forward_B = int(self.db.get('forward_B', default_value=1))

        self.left_wheel = Motor(self.Motor_A, offset=self.forward_A)
        self.right_wheel = Motor(self.Motor_B, offset=self.forward_B)

        self.pwm = PWM(bus_number=bus_number)

        def _set_a_pwm(value):
            pulse_wide = self.pwm.map(value, 0, 100, 0, 4095)
            self.pwm.write(self.PWM_A, 0, pulse_wide)

        def _set_b_pwm(value):
            pulse_wide = self.pwm.map(value, 0, 100, 0, 4095)
            self.pwm.write(self.PWM_B, 0, pulse_wide)

        self.left_wheel.pwm = _set_a_pwm
        self.right_wheel.pwm = _set_b_pwm

        self._speed = 0

        self.debug = debug
        if self._DEBUG:
            print(
                self._DEBUG_INFO, 'Set left wheel to #%d, PWM channel to %d' %
                (self.Motor_A, self.PWM_A))
            print(
                self._DEBUG_INFO, 'Set right wheel to #%d, PWM channel to %d' %
                (self.Motor_B, self.PWM_B))
Пример #3
0
 def __init__(self, fwd, bwd, pwm):
     self.fwd_pin = fwd
     self.bwd_pin = bwd
     self.pwm_pin = PWM(pwm, blocking=False)
     GPIO.setup(self.fwd_pin, GPIO.OUT)
     GPIO.setup(self.bwd_pin, GPIO.OUT)
Пример #4
0
    def initialiseLists(self):
        db = sqlite3.connect("./test2.sql")
        gpio = db.execute(""" SELECT * FROM Gpio """)

        for row in gpio:
            gpioType = row[2]
            pinNumber = row[0]
            gpioNumber = row[1]
            label = row[3]

            if gpioType == 'out':
                # create a switch
                switch = Switch(pinNumber, gpioNumber, label, self)
                #self.gpioList.append(switch)
                self.gpioLabelMapping[label] = gpioNumber

                self.gpioMap[gpioNumber] = switch

            elif gpioType == 'in':
                # create a contact
                contact = Contact(pinNumber, gpioNumber, label, self)
                #self.gpioList.append(contact)
                self.gpioLabelMapping[label] = gpioNumber

                self.gpioMap[gpioNumber] = contact
            elif gpioType == 'PWM':
                # create a pwm
                pwm = PWM(pinNumber, gpioNumber, label, self)
                #self.gpioList.append(pwm)
                self.gpioLabelMapping[label] = gpioNumber

                self.gpioMap[gpioNumber] = pwm
            # else:
            #     print("Skipped pin for now")

        for gpio in self.gpioMap.values():
            if gpio.threadBehavior != None:
                gpio.threadBehavior.start()

        table = db.execute(""" SELECT * FROM Alias""")
        self.gpioAliasMapping = {}
        for row in table:
            alias = row[1]
            gpio = row[2]
            self.gpioAliasMapping[alias] = gpio

        self.gpioAliasMapping = {
            **self.gpioLabelMapping,
            **self.gpioAliasMapping
        }
        print("---------------")
        print("GPIO Map:")
        print("---------------")
        print(self.gpioMap)
        print("---------------")
        print("Alias Map:")
        print("---------------")
        print(self.gpioAliasMapping)

        db = sqlite3.connect("./test2.sql")

        rules = db.execute(""" SELECT * FROM Rules """)

        for row in rules:
            ruleGpioTrigger = row[1]
            ruleGpioNewValue = row[2]
            ruleTriggeredScript = row[3]

            if ruleGpioTrigger not in self.ruleTableSwitchType:
                self.ruleTableSwitchType[ruleGpioTrigger] = []
            self.ruleTableSwitchType[ruleGpioTrigger].append(
                [ruleGpioNewValue, ruleTriggeredScript])

        cronJobs = db.execute(""" SELECT * FROM CronJobs """)

        for row in cronJobs:
            ruleCronStatement = row[1]
            ruleTriggeredScript = row[2]

            if ruleCronStatement not in self.ruleTableCronType:
                self.ruleTableCronType[ruleCronStatement] = []
            self.ruleTableCronType[ruleCronStatement].append(
                ruleTriggeredScript)
Пример #5
0
UPPER_SHELL_RED = 8
UPPER_SHELL_GREEN = 9
UPPER_SHELL_BLUE = 10

############################################################
# i2c
############################################################

# prox detection address
GP2Y0E02B = 0x40

proxSensor1 = Adafruit_I2C(GP2Y0E02B)
#proxSensor2 = Adafruit_I2C(VCNL4010_I2CADDR_DEFAULT)

#PWM driver connected on i2c
ledDriver = PWM(0x42)

########################################################################
# websocket
########################################################################

amcServerIP = '192.168.42.1'


def on_show_video_1(message):
    if (message['id'] == ID):
        global player
        if (player):
            player.quit()
        player = OMXPlayer("path/to/file.mp4",
                           args=['--no-osd', '--no-keys', '-b'])
Пример #6
0
from PWM import PWM
import time

CUPHOLDER_PWM = 12
CUPHOLDER_2_PWM = 13

UNDER_SEAT_PWM = 0
UPPER_SHELL_RED = 8
UPPER_SHELL_GREEN = 9
UPPER_SHELL_BLUE = 10

# Initialise the PWM device using the default address
pwm = PWM(0x42)
# Note if you'd like more debug output you can instead run:
#pwm = PWM(0x42)

freq = 0
pwm.setPWMFreq(500)  # Set frequency to 60 Hz
while (True):
    if freq > 4095:
        freq = 0
    else:
        freq = freq + 10

    pwm.setPWM(UNDER_SEAT_PWM, 4095 - freq, freq)
    pwm.setPWM(CUPHOLDER_PWM, 4095 - freq, freq)
    pwm.setPWM(UPPER_SHELL_GREEN, 4095 - freq, freq)
    pwm.setPWM(UPPER_SHELL_BLUE, 4095 - freq, freq)
    pwm.setPWM(UPPER_SHELL_RED, 2048, 2048)
    pwm.setPWM(CUPHOLDER_2_PWM, 4095 - freq, freq)