Exemple #1
0
    def test_start_pwm(self):
        PWM.start("PWM0", 0)

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

        assert os.path.exists(pwm_test) == True
        duty = open(pwm_test + 'duty_cycle').readline().strip()
        period = open(pwm_test + 'period').readline().strip()
        assert int(duty) == 0
        assert int(period) == 500000
    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()
Exemple #3
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"
    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()
    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()
    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()
Exemple #7
0
import CHIP_IO.OverlayManager as OM
import CHIP_IO.PWM as PWM
import time

# Initialize hardware pwm thorugh the OM
OM.enable_debug()
OM.load("PWM0")

# Test it loaded properly
if (OM.get_pwm_loaded()):
    print("PWM OM Successfully loaded...")

# Setup the pins
GPIO.setup("XIO-P0", GPIO.OUT)
GPIO.setup("XIO-P1", GPIO.OUT)
PWM.start("PWM0", 100, 100, 0)

# Run the test
try:
    GPIO.output("XIO-P0", GPIO.HIGH)
    GPIO.output("XIO-P1", GPIO.LOW)

    print("Testing duty cycle...")

    # Test duty cycle
    #    for x in range(0,100):
    #        SPWM.set_duty_cycle("PWM0", x)
    #        print(x)
    #        time.sleep(.1)

    # Test frequency
 def test_pwm_start_invalid_frequency_string(self):
     with pytest.raises(TypeError):
         PWM.start("PWM0", 0, "1")
Exemple #9
0
 def test_pwm_freq_non_setup_key(self):
     with pytest.raises(RuntimeError):
         PWM.set_frequency("PWM0", 100)
         PWM.cleanup()
 def test_pwm_start_invalid_duty_cycle_negative(self):
     with pytest.raises(ValueError):
         PWM.start("PWM0", -1)
def teardown_module(module):
    PWM.cleanup()
Exemple #12
0
def teardown_module(module):
    PWM.cleanup()
Exemple #13
0
 def test_pwm_duty_cycle_non_setup_key(self):
     with pytest.raises(ValueError):
         PWM.cleanup()
         PWM.set_duty_cycle("PWM0", 100)
Exemple #14
0
 def test_pwm_start_invalid_duty_cycle_high(self):
     with pytest.raises(ValueError):
         PWM.start("PWM0", 101)
Exemple #15
0
 def test_pwm_start_invalid_duty_cycle_string(self):
     with pytest.raises(TypeError):
         PWM.start("PWM0", "1")
Exemple #16
0
 def test_pwm_start_valid_duty_cycle_max(self):
     #testing an exception isn't thrown
     PWM.start("PWM0", 100)
     PWM.cleanup()
Exemple #17
0
 def test_pwm_start_invalid_duty_cycle_negative(self):
     with pytest.raises(ValueError):
         PWM.start("PWM0", -1)
Exemple #18
0
 def test_pwm_start_invalid_pwm_key(self):
     with pytest.raises(ValueError):
         PWM.start("P8_25", -1)
Exemple #19
0
 def test_pwm_start_invalid_frequency_string(self):
     with pytest.raises(TypeError):
         PWM.start("PWM0", 0, "1")
Exemple #20
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()
Exemple #21
0
 def test_pwm_start_invalid_positive_polarity(self):
     with pytest.raises(ValueError):
         PWM.start("PWM0", 0, 100, 2)
 def test_pwm_freq_non_setup_key(self):
     with pytest.raises(ValueError):
         PWM.set_frequency("P9_15", 100)
         PWM.cleanup()
Exemple #23
0
 def test_pwm_duty_cycle_invalid_key(self):
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("P9_15", 100)
Exemple #24
0
 def test_pwm_freq_non_setup_key(self):
     with pytest.raises(ValueError):
         PWM.set_frequency("P9_15", 100)
         PWM.cleanup()
 def test_pwm_freq_non_setup_key(self):
     with pytest.raises(RuntimeError):
         PWM.set_frequency("PWM0", 100)
         PWM.cleanup()
Exemple #26
0
def teardown_module(module):
    PWM.cleanup()
    if not UT.is_chip_pro():
        OM.unload("PWM0")
Exemple #27
0
 def test_pwm_frequency_invalid_value_negative(self):
     PWM.start("PWM0", 0)
     with pytest.raises(ValueError):
         PWM.set_frequency("PWM0", -1)
         PWM.cleanup()
 def test_pwm_start_invalid_duty_cycle_high(self):
     with pytest.raises(ValueError):
         PWM.start("PWM0", 101)
 def test_pwm_start_invalid_pwm_key(self):
     with pytest.raises(ValueError):
         PWM.start("P8_25", -1)
 def test_pwm_start_invalid_frequency_negative(self):
     with pytest.raises(ValueError):
         PWM.start("PWM0", 0, -1)
 def test_pwm_start_valid_duty_cycle_max(self):
     #testing an exception isn't thrown
     PWM.start("PWM0", 100)
     PWM.cleanup()
Exemple #32
0
 def test_pwm_frequency_invalid_value_string(self):
     PWM.start("PWM0", 0)
     with pytest.raises(TypeError):
         PWM.set_frequency("PWM0", "11")
         PWM.cleanup()
 def test_pwm_start_invalid_duty_cycle_string(self):
     with pytest.raises(TypeError):
         PWM.start("PWM0", "1")
 def test_pwm_start_invalid_positive_polarity(self):
     with pytest.raises(ValueError):
         PWM.start("PWM0", 0, 100, 2)
 def test_pwm_start_invalid_polarity_type(self):
     with pytest.raises(TypeError):
         PWM.start("PWM0", 0, 100, "1")
 def test_pwm_duty_cycle_non_setup_key(self):
     with pytest.raises(RuntimeError):
         PWM.set_duty_cycle("PWM0", 100)
         PWM.cleanup()
 def test_pwm_start_negative_polarity(self):
     with pytest.raises(ValueError):
         PWM.start("PWM0", 0, 100, -1)
 def test_pwm_duty_cycle_invalid_key(self):
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("P9_15", 100)
         PWM.cleanup()
Exemple #39
0
 def test_pwm_start_invalid_frequency_negative(self):
     with pytest.raises(ValueError):
         PWM.start("PWM0", 0, -1)
 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()
Exemple #41
0
 def test_pwm_start_negative_polarity(self):
     with pytest.raises(ValueError):
         PWM.start("PWM0", 0, 100, -1)
 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()
Exemple #43
0
 def test_pwm_start_invalid_polarity_type(self):
     with pytest.raises(TypeError):
         PWM.start("PWM0", 0, 100, "1")
 def test_pwm_frequency_invalid_value_negative(self):
     PWM.start("PWM0", 0)
     with pytest.raises(ValueError):
         PWM.set_frequency("PWM0", -1)
         PWM.cleanup()
Exemple #45
0
def teardown_module(module):
    PWM.cleanup()
    if not UT.is_chip_pro():
        OM.unload("PWM0")
 def test_pwm_frequency_invalid_value_string(self):
     PWM.start("PWM0", 0)
     with pytest.raises(TypeError):
         PWM.set_frequency("PWM0", "11")
         PWM.cleanup()
Exemple #47
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()
Exemple #48
0
    SLEEPTIME = 0.01

    # LOAD THE PWM OVERLAY
    print("LOADING PWM OVERLAY")
    OM.load("PWM0")

    time.sleep(1)

    # CLEANUP THE GPIO
    #GPIO.cleanup()
    #PWM.cleanup()

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

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

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

        # SETUP PWM RECEIVER
        #rcvr = PWMReceiver(GPIO, RECEIVERGPIO, COUNT, SLEEPTIME)