1
0
mirror of https://github.com/xtacocorex/CHIP_IO synced 2025-07-20 04:43:21 +00:00

finalizing servo, softpwm, and pwm api docs, cleanup of code comments for #73

This commit is contained in:
Robert Wolterman
2017-08-07 22:02:16 -05:00
parent e038fc9c89
commit 1e3935c8ea
5 changed files with 268 additions and 6 deletions

View File

@ -5,6 +5,10 @@ Import the PWM module as follows
import CHIP_IO.PWM as PWM import CHIP_IO.PWM as PWM
``` ```
For the CHIP, this requires the PWM0 DTBO loaded via the OverlayManager or other means.
For the CHIP, PWM1 is unavaiable
For the CHIP Pro, PWM0 and PWM1 are setup in the base DTB by default
### toggle_debug() ### toggle_debug()
Enable/Disable the Debug Enable/Disable the Debug
@ -18,6 +22,151 @@ Enable/Disable the Debug
PWM.toggle_debug() PWM.toggle_debug()
``` ```
### is_chip_pro()
Function to report to the calling script if the SBC is a CHIP or a CHIP Pro
* Parameters
None
* Returns
int - 1 for CHIP Pro, 0 for CHIP
* Examples
```python
is_chip_pro = PWM.is_chip_pro()
```
### start(channel, duty_cycle=0.0, frequency=2000.0, polarity=0)
Start the Software PWM
* Parameters
channel - pin for software PWM is configured
duty_cycle - initial duty cycle of the PWM (optional)
frequency - frequency of the PWM (optional)
polarity - signal polarity of the PWM (optional)
* Returns
None
* Examples
```python
PWM.start("PWM0")
PWM.start("PWM0", 37.0)
PWM.start("PWM0", 10.0, 500.0)
PWM.start("PWM0", 50.0, 1000.0, 1)
```
### stop(channel)
Stop the PWM
* Parameters
channel - pin PWM is configured
* Returns
None
* Examples
```python
PWM.stop("PWM0")
```
### set_duty_cycle(channel, duty_cycle)
Set the duty cycle of the PWM
* Parameters
channel - pin PWM is configured
duty_cycle - duty cycle of the PWM (0.0 to 100.0)
* Returns
None
* Examples
```python
PWM.set_duty_cycle("PWM0", 25.0)
```
### set_pulse_width_ns(channel, pulse_width_ns)
Set the width of the PWM pulse in nano seconds
* Parameters
channel - pin PWM is configured
pulse_width_ns - pulse width of the PWM in nanoseconds
* Returns
None
* Examples
```python
PWM.set_pulse_width_ns("PWM0", 2500.0)
```
### set_frequency(channel, frequency)
Set the frequency of the PWM in Hertz
* Parameters
channel - pin software PWM is configured
frequency - frequency of the PWM
* Returns
None
* Examples
```python
PWM.set_frequency("PWM0", 450.0)
```
### set_period_ns(channel, pulse_width_ns)
Set the period of the PWM pulse in nano seconds
* Parameters
channel - pin PWM is configured
period_ns - period of the PWM in nanoseconds
* Returns
None
* Examples
```python
PWM.set_period_ns("PWM0", 130.0)
```
### cleanup(channel)
Cleanup PWM. If not channel input, all PWM will be cleaned up
* Parameters
channel - pin PWM is configured (optional)
* Returns
None
* Examples
```python
PWM.cleanup()
PWM.cleanup("PWM0")
```
[home](./index.md) [home](./index.md)

View File

@ -32,7 +32,7 @@ Function to report to the calling script if the SBC is a CHIP or a CHIP Pro
* Examples * Examples
```python ```python
is_chip_pro = UT.is_chip_pro() is_chip_pro = SERVO.is_chip_pro()
``` ```
### start(channel, angle=0.0, range=180.0) ### start(channel, angle=0.0, range=180.0)

View File

@ -18,4 +18,115 @@ Enable/Disable the Debug
SPWM.toggle_debug() SPWM.toggle_debug()
``` ```
### is_chip_pro()
Function to report to the calling script if the SBC is a CHIP or a CHIP Pro
* Parameters
None
* Returns
int - 1 for CHIP Pro, 0 for CHIP
* Examples
```python
is_chip_pro = SPWM.is_chip_pro()
```
### start(channel, duty_cycle=0.0, frequency=2000.0, polarity=0)
Start the Software PWM
* Parameters
channel - pin for software PWM is configured
duty_cycle - initial duty cycle of the PWM (optional)
frequency - frequency of the PWM (optional)
polarity - signal polarity of the PWM (optional)
* Returns
None
* Examples
```python
SPWM.start("CSID0")
SPWM.start("CSID0", 37.0)
SPWM.start("CSID0", 10.0, 500.0)
SPWM.start("CSID0", 50.0, 1000.0, 1)
```
### stop(channel)
Stop the Software PWM
* Parameters
channel - pin software PWM is configured
* Returns
None
* Examples
```python
SPWM.stop("CSID0")
```
### set_duty_cycle(channel, duty_cycle)
Set the duty cycle of the Software PWM
* Parameters
channel - pin software PWM is configured
duty_cycle - duty cycle of the PWM (0.0 to 100.0)
* Returns
None
* Examples
```python
SPWM.set_duty_cycle("CSID0", 25.0)
```
### set_frequency(channel, frequency)
Set the frequency of the Software PWM in Hertz
* Parameters
channel - pin PWM is configured
frequency - frequency of the PWM
* Returns
None
* Examples
```python
SPWM.set_frequency("CSID0", 450.0)
```
### cleanup(channel)
Cleanup Software PWM. If not channel input, all Software PWM will be cleaned up
* Parameters
channel - pin Software PWM is configured (optional)
* Returns
None
* Examples
```python
SPWM.cleanup()
SPWM.cleanup("CSID0")
```
[home](./index.md) [home](./index.md)

View File

@ -50,6 +50,8 @@ static PyObject *py_toggle_debug(PyObject *self, PyObject *args)
// python function cleanup() // python function cleanup()
static PyObject *py_cleanup(PyObject *self, PyObject *args) static PyObject *py_cleanup(PyObject *self, PyObject *args)
{ {
// TODO: PER PIN CLEANUP LIKE EVERYTHING ELSE
// unexport the Servo // unexport the Servo
servo_cleanup(); servo_cleanup();
@ -68,7 +70,7 @@ static int init_module(void)
return 0; return 0;
} }
// python function value = is_chip_pro // python function value = is_chip_pro()
static PyObject *py_is_chip_pro(PyObject *self, PyObject *args) static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
{ {
PyObject *py_value; PyObject *py_value;
@ -185,7 +187,7 @@ static PyObject *py_stop_channel(PyObject *self, PyObject *args, PyObject *kwarg
Py_RETURN_NONE; Py_RETURN_NONE;
} }
// python method SERVO.set_range(channel, duty_cycle) // python method SERVO.set_range(channel, range)
static PyObject *py_set_range(PyObject *self, PyObject *args, PyObject *kwargs) static PyObject *py_set_range(PyObject *self, PyObject *args, PyObject *kwargs)
{ {
int gpio; int gpio;
@ -241,7 +243,7 @@ static PyObject *py_set_range(PyObject *self, PyObject *args, PyObject *kwargs)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
// python method SERVO.set_angle(channel, duty_cycle) // python method SERVO.set_angle(channel, angle)
static PyObject *py_set_angle(PyObject *self, PyObject *args, PyObject *kwargs) static PyObject *py_set_angle(PyObject *self, PyObject *args, PyObject *kwargs)
{ {
int gpio; int gpio;

View File

@ -82,7 +82,7 @@ static int init_module(void)
return 0; return 0;
} }
// python function value = is_chip_pro // python function value = is_chip_pro()
static PyObject *py_is_chip_pro(PyObject *self, PyObject *args) static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
{ {
PyObject *py_value; PyObject *py_value;
@ -92,7 +92,7 @@ static PyObject *py_is_chip_pro(PyObject *self, PyObject *args)
return py_value; return py_value;
} }
// python function start(channel, duty_cycle, freq) // python function start(channel, duty_cycle, freq, polarity)
static PyObject *py_start_channel(PyObject *self, PyObject *args, PyObject *kwargs) static PyObject *py_start_channel(PyObject *self, PyObject *args, PyObject *kwargs)
{ {
char key[8]; char key[8];