示例#1
0
    def api_softpwm(self, pin, command, option, req_method, req_args):
        resp = copy.deepcopy(self.CHIP_INFO)
        resp["connected"] = True

        # Figure out our command
        if command == "start" and req_method == 'GET':
            # Get the arguments
            duty_cycle = req_args.get('duty_cycle', 25.0)
            frequency = req_args.get('frequency', 35.0)
            polarity = req_args.get('polarity', 0)
            # Start the SoftPWM
            SPWM.start(pin, duty_cycle, frequency, polarity)
            resp[
                "message"] = "Setting {0} to duty cycle: {1}, frequency: {2}, and polarity {3}".format(
                    pin, duty_cycle, frequency, polarity)
        elif command == "stop" and req_method == 'GET':
            SPWM.stop(pin)
            resp["message"] = "Stopping {0}".format(pin)
        elif command == "cleanup" and req_method == 'GET':
            SPWM.cleanup(pin)
            resp["message"] = "Cleaning up {0}".format(pin)
        elif command == "duty_cycle" and req_method in ['GET', 'PUT', 'POST']:
            SPWM.set_duty_cycle(pin, float(option))
            resp["message"] = "Changing duty cycle on {0} to {1}".format(
                pin, option)
        elif command == "frequency" and req_method in ['GET', 'PUT', 'POST']:
            SPWM.set_frequency(pin, float(option))
            resp["message"] = "Changing duty cycle on {0} to {1}".format(
                pin, option)
        return jsonify(resp)
示例#2
0
def sig_handler(signal, frame):
    OM.unload("PWM0")
    GPIO.cleanup()
    PWM.cleanup()
    SPWM.cleanup()
    UT.disable_1v8_pin()
    sys.exit(0)
 def test_start_pwm(self):
     PWM.start("XIO-P7", 50, 10)
     base = GPIO.get_gpio_base() + 7
     gfile = '/sys/class/gpio/gpio%d' % base
     assert os.path.exists(gfile)
     direction = open(gfile + '/direction').read()
     assert(direction == 'out\n')
     PWM.cleanup()
示例#4
0
 def test_start_pwm(self):
     PWM.start("XIO-P7", 50, 10)
     base = GPIO.get_gpio_base() + 7
     gfile = '/sys/class/gpio/gpio%d' % base
     assert os.path.exists(gfile)
     direction = open(gfile + '/direction').read()
     assert(direction == 'out\n')
     PWM.cleanup()
示例#5
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)
示例#6
0
def pwm():

    rospy.init_node('pwm')
    rospy.Subscriber('speeds', Speeds, callback)

    while not rospy.is_shutdown():
        rospy.spin()

    SPWM.cleanup()
    UT.unexport_all()
示例#7
0
 def test_pwm_duty_cycle_invalid_key(self):
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("P9_15", 100)
         PWM.cleanup()
 def test_pwm_duty_cycle_invalid_value_string(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(TypeError):
         PWM.set_duty_cycle("XIO-P7", "a")
         PWM.cleanup()
 def test_pwm_duty_cycle_invalid_key(self):
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("P9_15", 100)
         PWM.cleanup()
示例#10
0
 def test_pwm_duty_cycle_non_setup_key(self):
     with pytest.raises(RuntimeError):
         PWM.set_duty_cycle("XIO-P7", 100)
         PWM.cleanup()
示例#11
0
 def test_pwm_frequency_invalid_value_negative(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(ValueError):
         PWM.set_frequency("XIO-P7", -1)
         PWM.cleanup()
示例#12
0
文件: pwm_test.py 项目: m-long/chip
        print(f)
        time.sleep(.1)

    # Hold at high 50%
    print("Holding high at 50% duty")
    SPWM.set_duty_cycle("XIO-P7", 50)
    SPWM.set_frequency("XIO-P7", 5000)

    time.sleep(3)

    # Hold at high 100%
    print("Holding high at 100% duty")
    SPWM.set_duty_cycle("XIO-P7", 100)
    SPWM.set_frequency("XIO-P7", 5000)

    time.sleep(3)

    # Try higher frequency
    print("Holding high at 10000Hz")
    SPWM.set_frequency("XIO-P7", 10000)

    time.sleep(3)

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

# Cleanup afterwards
SPWM.stop("XIO-P7")
SPWM.cleanup()
GPIO.cleanup()
示例#13
0
def stop():
    SPWM.cleanup()
    toggle = False
 def test_start_pwm(self):
     PWM.start("XIO-P7", 50, 10)
     assert os.path.exists('/sys/class/gpio/gpio415')
     direction = open('/sys/class/gpio/gpio415/direction').read()
     assert direction == 'out\n'
     PWM.cleanup()
示例#15
0
    time.sleep(1)

    # SETUP PWM
    try:
        print("PWM START")
        #PWM.toggle_debug()
        PWM.start(PWMGPIO, 50, 45, 1)

        # UNCOMMENT FOR CRASH
        print("PWM SET FREQUENCY")
        PWM.set_frequency(PWMGPIO, 10)

        # UNCOMMENT FOR CRASH
        print("PWM SET DUTY CYCLE")
        PWM.set_duty_cycle(PWMGPIO, 25)

        #time.sleep(COUNT*SLEEPTIME + 1)
        raw_input("PRESS ENTER WHEN DONE")

    except:
        raise
    finally:
        # CLEANUP
        print("CLEANUP")
        PWM.stop(PWMGPIO)
        PWM.cleanup()
        #OM.unload("PWM0")
        #GPIO.cleanup()


示例#16
0
 def test_pwm_duty_cycle_invalid_value_negative(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("XIO-P7", -1)
         PWM.cleanup()
示例#17
0
 def test_pwm_duty_cycle_invalid_value_string(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(TypeError):
         PWM.set_duty_cycle("XIO-P7", "a")
         PWM.cleanup()
示例#18
0
 def test_pwm_frequency_invalid_value_string(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(TypeError):
         PWM.set_frequency("XIO-P7", "11")
         PWM.cleanup()
示例#19
0
 def test_pwm_frequency_invalid_value_string(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(TypeError):
         PWM.set_frequency("XIO-P7", "11")
         PWM.cleanup()
示例#20
0
 def setup_method(self, test_method):
     PWM.cleanup()
示例#21
0
 def test_pwm_start_valid_duty_cycle_max(self):
     # testing an exception isn't thrown
     PWM.start("XIO-P7", 100)
     PWM.cleanup()
示例#22
0
 def test_pwm_start_valid_duty_cycle_max(self):
     # testing an exception isn't thrown
     PWM.start("XIO-P7", 100)
     PWM.cleanup()
示例#23
0
def teardown_module(module):
    PWM.cleanup()
示例#24
0
def teardown_module(module):
    PWM.cleanup()
示例#25
0
 def test_pwm_duty_cycle_invalid_value_negative(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("XIO-P7", -1)
         PWM.cleanup()
示例#26
0
 def test_pwm_duty_cycle_non_setup_key(self):
     with pytest.raises(RuntimeError):
         PWM.set_duty_cycle("XIO-P7", 100)
         PWM.cleanup()
示例#27
0
 def test_pwm_frequency_invalid_value_negative(self):
     PWM.start("XIO-P7", 0)
     with pytest.raises(ValueError):
         PWM.set_frequency("XIO-P7", -1)
         PWM.cleanup()
示例#28
0
def cleanup():
	motorStop()
	PWM.stop(pin_pwm)
	GPIO.cleanup(pin_forward)
	GPIO.cleanup(pin_back)
	PWM.cleanup()