def test_start_pwm(self):
        PWM.start("P9_14", 0)

        files = os.listdir('/sys/devices')
        ocp = '/sys/devices/'+[s for s in files if s.startswith('ocp')][0]
        files = os.listdir(ocp)
        pwm_test = ocp+'/'+[s for s in files if s.startswith('pwm_test_P9_14')][0]

        assert os.path.exists(pwm_test)
        duty = open(pwm_test + '/duty').read()
        period = open(pwm_test + '/period').read()
        assert int(duty) == 0
        assert int(period) == 500000
        PWM.cleanup()
 def test_pwm_duty_cycle_invalid_value_negative(self):
     PWM.start("P9_14", 0)
     with pytest.raises(ValueError):
         PWM.set_duty_cycle("P9_14", -1)
         PWM.cleanup()            
 def test_pwm_start_invalid_frequency_negative(self):
     with pytest.raises(ValueError):
         PWM.start("P9_14", 0, -1)
 def test_pwm_start_invalid_frequency_string(self):
     with pytest.raises(TypeError):   
         PWM.start("P9_14", 0, "1")              
 def test_pwm_start_invalid_duty_cycle_high(self):
     with pytest.raises(ValueError):   
         PWM.start("P9_14", 101)  
 def test_pwm_start_invalid_duty_cycle_string(self):
     with pytest.raises(TypeError):   
         PWM.start("P9_14", "1")              
 def test_pwm_start_invalid_duty_cycle_negative(self):
     with pytest.raises(ValueError):   
         PWM.start("P9_14", -1)     
 def test_pwm_start_valid_duty_cycle_max(self):
     #testing an exception isn't thrown
     PWM.start("P9_14", 100)  
     PWM.cleanup()            
 def test_pwm_start_invalid_pwm_key(self):
     with pytest.raises(ValueError):   
         PWM.start("P8_25", -1)             
 def test_pwm_frequency_invalid_value_string(self):
     PWM.start("P9_14", 0)
     with pytest.raises(TypeError):
         PWM.set_frequency("P9_14", "11")
         PWM.cleanup()
 def test_pwm_frequency_invalid_value_negative(self):
     PWM.start("P9_14", 0)
     with pytest.raises(ValueError):
         PWM.set_frequency("P9_14", -1)
         PWM.cleanup()            
 def test_pwm_duty_cycle_invalid_value_string(self):
     PWM.start("P9_14", 0)
     with pytest.raises(TypeError):
         PWM.set_duty_cycle("P9_14", "a")
         PWM.cleanup()               
Esempio n. 13
0
def init_pwm():
    # due to a small issue with the library,
    # the first pin initialized is not usable
    # until it is stopped and started again
    # after this, all pins work normally
    PWM.start(pins[1], 7.5)
    time.sleep(0.5)
    PWM.stop(pins[1])
    time.sleep(0.5)
    # start PWM output at 50Hz, all middle except throttle
    # 1.5/20 = .075 = 7.5%
    PWM.start(pins[1], 7.5, 50)
    PWM.start(pins[2], 7.5, 50)
    PWM.start(pins[3], 7.5, 50)
    PWM.start(pins[4], 10, 50)
    PWM.start(pins[5], 7.64, 50)
    PWM.on(pins[1])
    PWM.on(pins[2])
    PWM.on(pins[3])
    PWM.on(pins[4])
    PWM.on(pins[5])