Пример #1
0
def pwmEnable(pwm_pin):
  """ Ensures PWM module for the given pin is enabled and its ocp helper
      is loaded. """
  global PWM_PINS_ENABLED
  if PWM_PINS_ENABLED.get(pwm_pin): return
  pin_config = PWM_PINS[pwm_pin]
  assert (pin_config), "*Invalid PWM pin: '%s'" % pwm_pin

  for overlay in pin_config[2]:
    cape_manager.load(overlay, auto_unload=False)
    delay(250) # Give it some time to take effect
  cape_manager.load(pin_config[0], auto_unload=False)
  delay(250)

  helper_path = pin_config[1]
  # Make sure output is disabled, so it won't start outputing a 
  # signal until analogWrite() is called: 
  if (sysfs.kernelFileIO('%s/%s' % (helper_path, PWM_RUN)) == '1\n'):
    sysfs.kernelFileIO('%s/%s' % (helper_path, PWM_RUN), '0')

  # Duty cyle must be set to 0 before changing frequency:
  sysfs.kernelFileIO('%s/%s' % (helper_path, PWM_DUTY), '0')
  # Is this still true??

  sysfs.kernelFileIO('%s/%s' % (helper_path, PWM_PERIOD), 
                      str(PWM_DEFAULT_PERIOD))
  addToCleanup(lambda : pwmDisable(pwm_pin))
  PWM_PINS_ENABLED[pwm_pin] = True
Пример #2
0
def pwmEnable(pwm_pin):
  """ Ensures PWM module for the given pin is enabled and its ocp helper
      is loaded. """
  global PWM_PINS_ENABLED
  if PWM_PINS_ENABLED.get(pwm_pin): return
  pin_config = PWM_PINS[pwm_pin]
  assert (pin_config), "*Invalid PWM pin: '%s'" % pwm_pin

  for overlay in pin_config[2]:
    cape_manager.load(overlay, auto_unload=False)
    delay(250) # Give it some time to take effect
  cape_manager.load(pin_config[0], auto_unload=False)
  delay(250)

  helper_path = pin_config[1]
  # Make sure output is disabled, so it won't start outputing a 
  # signal until analogWrite() is called: 
  if (sysfs.kernelFileIO('%s/%s' % (helper_path, PWM_RUN)) == '1\n'):
    sysfs.kernelFileIO('%s/%s' % (helper_path, PWM_RUN), '0')

  # Duty cyle must be set to 0 before changing frequency:
  sysfs.kernelFileIO('%s/%s' % (helper_path, PWM_DUTY), '0')
  # Is this still true??

  sysfs.kernelFileIO('%s/%s' % (helper_path, PWM_PERIOD), 
                      str(PWM_DEFAULT_PERIOD))
  addToCleanup(lambda : pwmDisable(pwm_pin))
  PWM_PINS_ENABLED[pwm_pin] = True
Пример #3
0
    def __init__(self, eqep_num):
        '''
    RotaryEncoder(eqep_num)
    Creates an instance of the class RotaryEncoder. 
    eqep_num determines which eQEP pins are set up. 
    eqep_num can be: EQEP0, EQEP1, EQEP2 or EQEP2b based on which pins \
    the rotary encoder is connected to.
    '''
        assert 0 <= eqep_num <= 3, "eqep_num must be between 0 and 3"
        if eqep_num == 3:
            overlay = "PyBBIO-eqep2b"
            eqep_num = 2
        else:
            overlay = 'PyBBIO-eqep%i' % eqep_num

        pwmss_overlay = "PyBBIO-epwmss%i" % eqep_num
        cape_manager.load(pwmss_overlay, auto_unload=False)
        delay(10)
        cape_manager.load(overlay, auto_unload=False)
        delay(250)  # Give driver time to load
        self.base_dir = self._eqep_dirs[eqep_num]
        self.enable()
        addToCleanup(self.disable)
Пример #4
0
  def __init__(self, eqep_num):
    '''
    RotaryEncoder(eqep_num)
    Creates an instance of the class RotaryEncoder. 
    eqep_num determines which eQEP pins are set up. 
    eqep_num can be: EQEP0, EQEP1, EQEP2 or EQEP2b based on which pins \
    the rotary encoder is connected to.
    '''
    assert 0 <= eqep_num <= 3 , "eqep_num must be between 0 and 3"
    if eqep_num == 3:
        overlay = "PyBBIO-eqep2b"
    	eqep_num = 2
    else:
    	overlay = 'PyBBIO-eqep%i' % eqep_num

    pwmss_overlay = "PyBBIO-epwmss%i" % eqep_num
    cape_manager.load(pwmss_overlay, auto_unload=False)
    delay(10)
    cape_manager.load(overlay, auto_unload=False)
    delay(250) # Give driver time to load 
    self.base_dir = self._eqep_dirs[eqep_num]
    self.enable()
    addToCleanup(self.disable)