Example #1
0
def sig_handler(signal, frame):
    OM.unload("PWM0")
    GPIO.cleanup()
    PWM.cleanup()
    SPWM.cleanup()
    UT.disable_1v8_pin()
    sys.exit(0)
Example #2
0
    def api_pwm(self, chan, command, option, req_method, req_args):
        resp = copy.deepcopy(self.CHIP_INFO)
        resp["connected"] = True

        # Default the channel to PWM0
        # CHIP Pro will support PWM1
        cname = "PWM0"

        chan = int(chan)
        if chan not in [0]:  #,1]:
            resp["message"] = "Invalid PWM Channel Specified"
            return jsonify(resp)
        else:
            if chan == 0:
                cname = "PWM0"
            elif chan == 1:
                cname = "PWM1"

        # Figure out our command
        if command == "start" and req_method == 'GET':
            # Load the overlay
            OM.load(cname)
            # Get the arguments
            duty_cycle = req_args.get('duty_cycle', 25.0)
            frequency = req_args.get('frequency', 200.0)
            polarity = req_args.get('polarity', 0)
            # Start the PWM
            PWM.start(cname, duty_cycle, frequency, polarity)
            resp[
                "message"] = "Setting {0} to duty cycle: {1}, frequency: {2}, and polarity {3}".format(
                    cname, duty_cycle, frequency, polarity)
        elif command == "stop" and req_method == 'GET':
            PWM.stop(chame)
            resp["message"] = "Stopping {0}".format(cname)
        elif command == "cleanup" and req_method == 'GET':
            # TODO: Handle per channel cleanup
            PWM.cleanup()
            OM.unload(cname)
            resp["message"] = "Cleaning up and unloading {0}".format(cname)
        elif command == "duty_cycle" and req_method in ['GET', 'PUT', 'POST']:
            PWM.set_duty_cycle(cname, float(option))
            resp["message"] = "Changing duty cycle on {0} to {1}".format(
                cname, option)
        elif command == "frequency" and req_method in ['GET', 'PUT', 'POST']:
            PWM.set_frequency(cname, float(option))
            resp["message"] = "Changing duty cycle on {0} to {1}".format(
                cname, option)
        return jsonify(resp)
Example #3
0
def teardown_module(module):
    PWM.cleanup()
    if not UT.is_chip_pro():
        OM.unload("PWM0")
Example #4
0
# ENABLE DEBUG
print("ENABLING OVERLAY MANAGER DEBUG")
OM.enable_debug()

# **************** PWM *******************
print("\nIS PWM ENABLED: {0}".format(OM.get_pwm_loaded()))
OM.load("PWM0")
print("IS PWM ENABLED: {0}".format(OM.get_pwm_loaded()))
# VERIFY PWM0 EXISTS
if os.path.exists('/sys/class/pwm/pwmchip0'):
    print("PWM DEVICE EXISTS")
else:
    print("PWM DEVICE DID NOT LOAD PROPERLY")
print("UNLOADING PWM0")
OM.unload("PWM0")
print("IS PWM ENABLED: {0}".format(OM.get_pwm_loaded()))

# **************** I2C-1 *******************
print("\nIS I2C ENABLED: {0}".format(OM.get_i2c_loaded()))
OM.load("I2C1")
print("IS I2C ENABLED: {0}".format(OM.get_i2c_loaded()))
# VERIFY I2C-1 EXISTS
if os.path.exists('/sys/class/i2c-dev/i2c-1'):
    print("I2C1 DEVICE EXISTS")
else:
    print("I2C1 DEVICE DID NOT LOAD PROPERLY")
print("UNLOADING I2C1")
OM.unload("I2C1")
print("IS I2C ENABLED: {0}".format(OM.get_i2c_loaded()))
Example #5
0
    # Test duty cycle
    #    for x in range(0,100):
    #        SPWM.set_duty_cycle("PWM0", x)
    #        print(x)
    #        time.sleep(.1)

    # Test frequency
    PWM.set_duty_cycle("PWM0", 100)
    print("Testing frequency at 100% duty")
    for f in range(100, 5000, 100):
        PWM.set_frequency("PWM0", f)
        print(f)
        time.sleep(.1)

    # Hold at high
    print("Holding high")
    PWM.set_duty_cycle("PWM0", 100)
    PWM.set_frequency("PWM0", 5000)

    time.sleep(3)

except:
    print("An error hath occurred.")

# Cleanup afterwards
PWM.stop("PWM0")
PWM.cleanup()
OM.unload("PWM0")
GPIO.cleanup()
Example #6
0
# ENABLE DEBUG
print("ENABLING OVERLAY MANAGER DEBUG")
OM.toggle_debug()

# **************** PWM *******************
print("\nIS PWM ENABLED: {0}".format(OM.get_pwm_loaded()))
OM.load("PWM0")
print("IS PWM ENABLED: {0}".format(OM.get_pwm_loaded()))
# VERIFY PWM0 EXISTS
if os.path.exists('/sys/class/pwm/pwmchip0'):
    print("PWM DEVICE EXISTS")
else:
    print("PWM DEVICE DID NOT LOAD PROPERLY")
print("UNLOADING PWM0")
OM.unload("PWM0")
print("IS PWM ENABLED: {0}".format(OM.get_pwm_loaded()))

# **************** SPI2 *******************
print("\nIS SPI ENABLED: {0}".format(OM.get_spi_loaded()))
OM.load("SPI2")
print("IS SPI ENABLED: {0}".format(OM.get_spi_loaded()))
# VERIFY SPI2 EXISTS
if os.listdir('/sys/class/spi_master') != "":
    print("SPI DEVICE EXISTS")
else:
    print("SPI DEVICE DID NOT LOAD PROPERLY")
print("UNLOADING SPI")
OM.unload("SPI2")
print("IS SPI ENABLED: {0}".format(OM.get_spi_loaded()))
Example #7
0
def teardown_module(module):
    PWM.cleanup()
    if not UT.is_chip_pro():
        OM.unload("PWM0")