예제 #1
0
def sig_handler(signal, frame):
    OM.unload("PWM0")
    GPIO.cleanup()
    PWM.cleanup()
    SPWM.cleanup()
    UT.disable_1v8_pin()
    sys.exit(0)
예제 #2
0
def RestApp(host="0.0.0.0", port=1883, debug=False):
    try:
        app.run(host=host, port=port, debug=debug)
    except KeyboardInterrupt:
        GPIO.cleanup()
        PWM.cleanup()
        SPWM.cleanup()
        UT.disable_1v8_pin()
        sys.exit(0)
예제 #3
0
    def test_start_pwm(self):
        PWM.start("PWM0", 0)

        pwm_test = '/sys/class/pwm/pwmchip0/pwm0'

        assert os.path.exists(pwm_test)
        duty = open(pwm_test + '/duty_cycle').read()
        period = open(pwm_test + '/period').read()
        assert int(duty) == 0
        assert int(period) == 500000
        PWM.cleanup()
예제 #4
0
    def test_start_pwm(self):
        PWM.start("PWM0", 0)

        pwm_test = '/sys/class/pwm/pwmchip0/pwm0'

        assert os.path.exists(pwm_test)
        duty = open(pwm_test + '/duty_cycle').readline().strip()
        period = open(pwm_test + '/period').readline().strip()
        assert int(duty) == 0
        assert int(period) == 500000
        PWM.cleanup()
예제 #5
0
    def test_start_pwm_with_polarity_zero(self):
        PWM.cleanup()
        PWM.start("PWM0", 0, 2000, 0)

        pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'

        duty = open(pwm_test + 'duty_cycle').readline().strip()
        period = open(pwm_test + 'period').readline().strip()
        polarity = open(pwm_test + 'polarity').readline().strip()
        assert int(duty) == 0
        assert int(period) == 500000
        assert str(polarity) == "normal"
예제 #6
0
    def test_start_pwm_with_polarity_zero(self):
        PWM.cleanup()
        PWM.start("PWM0", 0, 2000, 0)

        pwm_test = '/sys/class/pwm/pwmchip0/pwm0/'

        duty = open(pwm_test + 'duty_cycle').readline().strip()
        period = open(pwm_test + 'period').readline().strip()
        polarity = open(pwm_test + 'polarity').readline().strip()
        assert int(duty) == 0
        assert int(period) == 500000
        assert str(polarity) == "normal"
예제 #7
0
    def test_start_pwm_with_polarity_default(self):
        PWM.start("PWM0", 0, 2000, 0)

        pwm_test = '/sys/class/pwm/pwmchip0/pwm0'

        assert os.path.exists(pwm_test)
        duty = open(pwm_test + '/duty_cycle').readline().strip()
        period = open(pwm_test + '/period').readline().strip()
        polarity = open(pwm_test + '/polarity').readline().strip()
        assert int(duty) == 0
        assert int(period) == 500000
        assert str(polarity) == "normal"
        PWM.cleanup()
예제 #8
0
    def test_start_pwm_with_polarity_one(self):
        PWM.start("PWM0", 0, 2000, 1)

        pwm_test = '/sys/class/pwm/pwmchip0/pwm0'

        assert os.path.exists(pwm_test)
        duty = open(pwm_test + '/duty_cycle').readline().strip()
        period = open(pwm_test + '/period').readline().strip()
        polarity = open(pwm_test + '/polarity').readline().strip()
        assert int(duty) == 0
        assert int(period) == 500000
        assert str(polarity) == "inverted"
        PWM.cleanup()
예제 #9
0
    def test_start_pwm_with_polarity_zero(self):
        PWM.start("PWM0", 0, 2000, 0)

        pwm_test = '/sys/class/pwm/pwmchip0/pwm0'

        assert os.path.exists(pwm_test)
        duty = open(pwm_test + '/duty_cycle').read()
        period = open(pwm_test + '/period').read()
        polarity = open(pwm_test + '/polarity').read()
        assert int(duty) == 0
        assert int(period) == 500000
        assert string(polarity) == "normal"
        PWM.cleanup()
예제 #10
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)
예제 #11
0
    def test_pwm_duty_modified(self):
        PWM.start("PWM0", 0)

        pwm_test = '/sys/class/pwm/pwmchip0/pwm0'

        assert os.path.exists(pwm_test)
        duty = open(pwm_test + '/duty_cycle').readline().strip()
        period = open(pwm_test + '/period').readline().strip()
        assert int(duty) == 0
        assert int(period) == 500000

        PWM.set_duty_cycle("PWM0", 100)
        duty = open(pwm_test + '/duty_cycle').readline().strip()
        period = open(pwm_test + '/period').readline().strip()
        assert int(duty) == 500000
        assert int(period) == 500000
        PWM.cleanup()
예제 #12
0
 def test_pwm_freq_non_setup_key(self):
     with pytest.raises(RuntimeError):
         PWM.set_frequency("PWM0", 100)
         PWM.cleanup()
예제 #13
0
 def test_pwm_frequency_invalid_value_string(self):
     PWM.start("PWM0", 0)
     with pytest.raises(TypeError):
         PWM.set_frequency("PWM0", "11")
         PWM.cleanup()
예제 #14
0
 def test_pwm_duty_cycle_invalid_key(self):
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("P9_15", 100)
         PWM.cleanup()
예제 #15
0
 def test_pwm_frequency_invalid_value_negative(self):
     PWM.start("PWM0", 0)
     with pytest.raises(ValueError):
         PWM.set_frequency("PWM0", -1)
     PWM.cleanup()
예제 #16
0
def teardown_module(module):
    PWM.cleanup()
예제 #17
0
 def test_pwm_freq_non_setup_key(self):
     with pytest.raises(RuntimeError):
         PWM.set_frequency("PWM0", 100)
         PWM.cleanup()
예제 #18
0
def teardown_module(module):
    PWM.cleanup()
    if not UT.is_chip_pro():
        OM.unload("PWM0")
예제 #19
0
 def test_pwm_freq_non_setup_key(self):
     with pytest.raises(ValueError):
         PWM.set_frequency("P9_15", 100)
         PWM.cleanup()
예제 #20
0
 def test_pwm_freq_non_setup_key(self):
     with pytest.raises(ValueError):
         PWM.set_frequency("P9_15", 100)
         PWM.cleanup()
예제 #21
0
 def test_pwm_duty_cycle_non_setup_key(self):
     with pytest.raises(ValueError):
         PWM.cleanup()
         PWM.set_duty_cycle("PWM0", 100)
예제 #22
0
 def test_pwm_duty_cycle_invalid_value_negative(self):
     PWM.start("PWM0", 0)
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("PWM0", -1)
     PWM.cleanup()
예제 #23
0
 def test_pwm_start_valid_duty_cycle_max(self):
     #testing an exception isn't thrown
     PWM.start("PWM0", 100)
     PWM.cleanup()
예제 #24
0
def teardown_module(module):
    PWM.cleanup()
예제 #25
0
파일: hpwm_test.py 프로젝트: m-long/chip
    # 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()
예제 #26
0
 def test_pwm_duty_cycle_non_setup_key(self):
     with pytest.raises(RuntimeError):
         PWM.set_duty_cycle("PWM0", 100)
         PWM.cleanup()
예제 #27
0
def teardown_module(module):
    PWM.cleanup()
    if not UT.is_chip_pro():
        OM.unload("PWM0")
예제 #28
0
 def test_pwm_duty_cycle_invalid_key(self):
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("P9_15", 100)
         PWM.cleanup()
예제 #29
0
 def test_pwm_duty_cycle_invalid_value_string(self):
     PWM.start("PWM0", 0)
     with pytest.raises(TypeError):
         PWM.set_duty_cycle("PWM0", "a")
     PWM.cleanup()
예제 #30
0
 def test_pwm_duty_cycle_invalid_value_negative(self):
     PWM.start("PWM0", 0)
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("PWM0", -1)
         PWM.cleanup()
예제 #31
0
 def test_pwm_frequency_invalid_value_string(self):
     PWM.start("PWM0", 0)
     with pytest.raises(TypeError):
         PWM.set_frequency("PWM0", "11")
     PWM.cleanup()
예제 #32
0
 def test_pwm_duty_cycle_invalid_value_string(self):
     PWM.start("PWM0", 0)
     with pytest.raises(TypeError):
         PWM.set_duty_cycle("PWM0", "a")
         PWM.cleanup()
예제 #33
0
 def test_pwm_start_valid_duty_cycle_max(self):
     #testing an exception isn't thrown
     PWM.start("PWM0", 100)
     PWM.cleanup()
예제 #34
0
 def test_pwm_frequency_invalid_value_negative(self):
     PWM.start("PWM0", 0)
     with pytest.raises(ValueError):
         PWM.set_frequency("PWM0", -1)
         PWM.cleanup()