-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-api-doc.c
More file actions
60 lines (55 loc) · 1.69 KB
/
Copy pathpython-api-doc.c
File metadata and controls
60 lines (55 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// This file is here only for including Python API language in the generated docs.
/** @defgroup python Python API
*
* The Python API reference documentation for libpisoundmicro. It closely resembles the
* \ref cpp, refer to its documentation for detailed information on the available APIs.
* The Python wrapper is automatically generated from the C/C++ API using SWIG. The generated
* code includesautodoc comments, so the same reference documentation is available straight in
* your favorite IDE.
*
* The only major difference from C and C++ APIs is that the libpisoundmicro is implicitly
* initialized when importing the `pypisoundmicro` library in Python, and deinitialized upon
* exit.
*
*
* # Quick Start
*
* First, install the Python library package:
*
* ```bash
* sudo apt install pypisoundmicro
* ```
*
* Then, let's create a simple program to read the GPIO value of pin B03:
*
* ```py3
#!/usr/bin/env python3
# Import the pisoundmicro module, make all of it available in global namespace.
from pypisoundmicro import *
# Set up the Gpio Input Element using pin B03 with pull-up enabled.
gpio = Gpio.setupInput(ElementName.randomized(), UPISND_PIN_B03, UPISND_PIN_PULL_UP)
# Check if the setup was successful.
if not gpio.isValid():
print("GPIO setup failed")
exit(1)
# Read the GPIO value.
if gpio.get():
print("B03 is high.")
else:
print("B03 is low.")
```
* Save the code as `example.py`, make it executable:
* ```bash
* chmod +x example.py
* ```
*
* Then run it:
*
* ```bash
* ./example.py
* ```
*
* You should see it output either \"\a B03 \a is \a high.\" or \"\a B03 \a is \a low.\", depending on the B03 pin state.
*
* See the \ref cpp for more documentation.
*/