示例#1
0
    def set_servo(self, gpio, pulse_width_us):
        """
        Sets a pulse-width on a gpio to repeat every subcycle
        (by default every 20ms).
        """
        # Make sure we can set the exact pulse_width_us
        _pulse_incr_us = _PWM.get_pulse_incr_us()
        if pulse_width_us % _pulse_incr_us:
            # No clean division possible
            raise AttributeError(("Pulse width increment granularity %sus "
                                  "cannot divide a pulse-time of %sus") %
                                 (_pulse_incr_us, pulse_width_us))

        # Initialize channel if not already done, else check subcycle time
        if _PWM.is_channel_initialized(self._dma_channel):
            _subcycle_us = _PWM.get_channel_subcycle_time_us(self._dma_channel)
            if _subcycle_us != self._subcycle_time_us:
                raise AttributeError(("Error: DMA channel %s is setup with a "
                        "subcycle_time of %sus (instead of %sus)") % \
                        (self._dma_channel, _subcycle_us,
                            self._subcycle_time_us))
        else:
            init_channel(self._dma_channel, self._subcycle_time_us)

        # Add pulse for this GPIO
        add_channel_pulse(self._dma_channel, gpio, 0, \
                int(pulse_width_us / _pulse_incr_us))
示例#2
0
    def set_servo(self, gpio, pulse_width_us):
        """
        Sets a pulse-width on a gpio to repeat every subcycle
        (by default every 20ms).
        """
        # Make sure we can set the exact pulse_width_us
        _pulse_incr_us = _PWM.get_pulse_incr_us()
        if pulse_width_us % _pulse_incr_us:
            # No clean division possible
            raise AttributeError(("Pulse width increment granularity %sus "
                    "cannot divide a pulse-time of %sus") % (_pulse_incr_us,
                    pulse_width_us))

        # Initialize channel if not already done, else check subcycle time
        if _PWM.is_channel_initialized(self._dma_channel):
            _subcycle_us = _PWM.get_channel_subcycle_time_us(self._dma_channel)
            if _subcycle_us != self._subcycle_time_us:
                raise AttributeError(("Error: DMA channel %s is setup with a "
                        "subcycle_time of %sus (instead of %sus)") % \
                        (self._dma_channel, _subcycle_us, 
                            self._subcycle_time_us))
        else:
            init_channel(self._dma_channel, self._subcycle_time_us)

        # If this GPIO is already used, clear it first
        if self._gpios_used & 1 << gpio:
            clear_channel_gpio(self._dma_channel, gpio)
        self._gpios_used |= 1 << gpio

        # Add pulse for this GPIO
        add_channel_pulse(self._dma_channel, gpio, 0, \
                int(pulse_width_us / _pulse_incr_us))
示例#3
0
def is_channel_initialized(channel):
    """ Returns 1 if this channel has been initialized, else 0 """
    return _PWM.is_channel_initialized(channel)
示例#4
0
def is_channel_initialized(channel):
    """ Returns 1 if this channel has been initialized, else 0 """
    return _PWM.is_channel_initialized(channel)