Skip to content

Commit bf190cc

Browse files
committed
Updated docs, improved examples
1 parent a1df065 commit bf190cc

File tree

12 files changed

+154
-182
lines changed

12 files changed

+154
-182
lines changed

README.rst

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,49 @@ Please ensure all dependencies are available on the CircuitPython filesystem.
3030
This is easily achieved by downloading
3131
`the Adafruit library and driver bundle <https://circuitpython.org/libraries>`_.
3232

33-
Installing from PyPI
34-
=====================
35-
.. note:: This library is not available on PyPI yet. Install documentation is included
36-
as a standard element. Stay tuned for PyPI availability!
37-
38-
.. todo:: Remove the above note if PyPI version is/will be available at time of release.
39-
If the library is not planned for PyPI, remove the entire 'Installing from PyPI' section.
40-
41-
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
42-
PyPI <https://pypi.org/project/adafruit-circuitpython-magtag/>`_. To install for current user:
43-
44-
.. code-block:: shell
45-
46-
pip3 install adafruit-circuitpython-magtag
47-
48-
To install system-wide (this may be required in some cases):
49-
50-
.. code-block:: shell
51-
52-
sudo pip3 install adafruit-circuitpython-magtag
53-
54-
To install in a virtual environment in your current project:
55-
56-
.. code-block:: shell
57-
58-
mkdir project-name && cd project-name
59-
python3 -m venv .env
60-
source .env/bin/activate
61-
pip3 install adafruit-circuitpython-magtag
6233

6334
Usage Example
6435
=============
6536

66-
.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
37+
.. code:: python
38+
39+
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
40+
#
41+
# SPDX-License-Identifier: Unlicense
42+
import time
43+
import terminalio
44+
from adafruit_magtag.magtag import MagTag
45+
46+
magtag = MagTag()
47+
48+
magtag.add_text(
49+
text_font=terminalio.FONT,
50+
text_position=(
51+
50,
52+
(magtag.graphics.display.height // 2) - 1,
53+
),
54+
text_scale=3,
55+
)
56+
57+
magtag.set_text("Hello World")
58+
59+
buttons = magtag.peripherals.buttons
60+
button_colors = ((255, 0, 0), (255, 150, 0), (0, 255, 255), (180, 0, 255))
61+
button_tones = (1047, 1318, 1568, 2093)
62+
timestamp = time.monotonic()
63+
64+
while True:
65+
for i, b in enumerate(buttons):
66+
if not b.value:
67+
print("Button %c pressed" % chr((ord("A") + i)))
68+
magtag.peripherals.neopixel_disable = False
69+
magtag.peripherals.neopixels.fill(button_colors[i])
70+
magtag.peripherals.play_tone(button_tones[i], 0.25)
71+
break
72+
else:
73+
magtag.peripherals.neopixel_disable = True
74+
time.sleep(0.01)
75+
6776
6877
Contributing
6978
============

adafruit_magtag/graphics.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Graphics:
4646
"""
4747

4848
# pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements
49-
def __init__(self, *, default_bg=None, auto_refresh=True, debug=False):
49+
def __init__(self, *, default_bg=0xFFFFFF, auto_refresh=True, debug=False):
5050

5151
self._debug = debug
5252
if not hasattr(board, "DISPLAY"):
@@ -139,7 +139,6 @@ def set_background(self, file_or_color, position=None):
139139
self._bg_group.append(self._bg_sprite)
140140
if self.auto_refresh:
141141
self.display.refresh()
142-
sleep(5)
143142
gc.collect()
144143

145144
def qrcode(

adafruit_magtag/magtag.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(
6565
headers=None,
6666
json_path=None,
6767
regexp_path=None,
68-
default_bg=None,
68+
default_bg=0xFFFFFF,
6969
status_neopixel=None,
7070
json_transform=None,
7171
debug=False,
@@ -74,6 +74,7 @@ def __init__(
7474
self._debug = debug
7575
self.graphics = Graphics(
7676
default_bg=default_bg,
77+
auto_refresh=False,
7778
debug=debug,
7879
)
7980
self.display = self.graphics.display

docs/api.rst

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11

2-
.. If you created a package, create one automodule per module in the package.
32

4-
.. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py)
5-
.. use this format as the module name: "adafruit_foo.foo"
3+
.. automodule:: adafruit_magtag.fakerequests
4+
:members:
5+
6+
.. automodule:: adafruit_magtag.graphics
7+
:members:
8+
9+
.. automodule:: adafruit_magtag.magtag
10+
:members:
11+
12+
.. automodule:: adafruit_magtag.network
13+
:members:
14+
15+
.. automodule:: adafruit_magtag.wifi_module
16+
:members:
617

7-
.. automodule:: adafruit_magtag
18+
.. automodule:: adafruit_magtag.peripherals
819
:members:

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Uncomment the below if you use native CircuitPython modules such as
2626
# digitalio, micropython and busio. List the modules you use. Without it, the
2727
# autodoc module docs will fail to generate with a warning.
28-
# autodoc_mock_imports = ["digitalio", "busio"]
28+
autodoc_mock_imports = ["supervisor", "rtc", "ssl", "wifi", "socketpool", "secrets"]
2929

3030

3131
intersphinx_mapping = {

docs/examples.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/magtag_simpletest.py
77
:caption: examples/magtag_simpletest.py
88
:linenos:
9+
10+
Other Demos
11+
------------
12+
13+
.. literalinclude:: ../examples/bitcoin_demo.py
14+
:caption: examples/bitcoin_demo.py
15+
:linenos:

docs/index.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26-
.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
27-
the toctree above for use later.
26+
* Adafruit MagTag <https://learn.adafruit.com/adafruit-magtag>
2827

2928
.. toctree::
3029
:caption: Related Products
3130

32-
.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
33-
the toctree above for use later.
31+
* Adafruit MagTag <https://www.adafruit.com/product/4800>
3432

3533
.. toctree::
3634
:caption: Other Links

examples/bitcoin_demo.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
import time
5+
import terminalio
6+
from adafruit_magtag.magtag import MagTag
7+
8+
# Set up where we'll be fetching data from
9+
DATA_SOURCE = "https://api.coindesk.com/v1/bpi/currentprice.json"
10+
DATA_LOCATION = ["bpi", "USD", "rate_float"]
11+
12+
def text_transform(val):
13+
return "Bitcoin: $%d" % val
14+
15+
magtag = MagTag(
16+
url=DATA_SOURCE, json_path=DATA_LOCATION,
17+
)
18+
19+
magtag.network.connect()
20+
21+
magtag.add_text(
22+
text_font=terminalio.FONT,
23+
text_position=(
24+
10,
25+
(magtag.graphics.display.height // 2) - 1,
26+
),
27+
text_scale=3,
28+
text_transform=text_transform,
29+
)
30+
31+
magtag.preload_font(b"$012345789") # preload numbers
32+
magtag.preload_font((0x00A3, 0x20AC)) # preload gbp/euro symbol
33+
34+
timestamp = time.monotonic()
35+
36+
while True:
37+
if (time.monotonic() - timestamp) > 5: # once a second...
38+
try:
39+
value = magtag.fetch()
40+
print("Response is", value)
41+
except (ValueError, RuntimeError) as e:
42+
print("Some error occured, retrying! -", e)
43+
timestamp = time.monotonic()
44+
45+
time.sleep(0.01)

examples/bitcoin_peripheral_demo.py

Lines changed: 0 additions & 77 deletions
This file was deleted.

examples/magtag_simpletest.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
11
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
22
#
33
# SPDX-License-Identifier: Unlicense
4+
import time
5+
import terminalio
6+
from adafruit_magtag.magtag import MagTag
7+
8+
magtag = MagTag()
9+
10+
magtag.add_text(
11+
text_font=terminalio.FONT,
12+
text_position=(
13+
50,
14+
(magtag.graphics.display.height // 2) - 1,
15+
),
16+
text_scale=3,
17+
)
18+
19+
magtag.set_text("Hello World")
20+
21+
buttons = magtag.peripherals.buttons
22+
button_colors = ((255, 0, 0), (255, 150, 0), (0, 255, 255), (180, 0, 255))
23+
button_tones = (1047, 1318, 1568, 2093)
24+
timestamp = time.monotonic()
25+
26+
while True:
27+
for i, b in enumerate(buttons):
28+
if not b.value:
29+
print("Button %c pressed" % chr((ord("A") + i)))
30+
magtag.peripherals.neopixel_disable = False
31+
magtag.peripherals.neopixels.fill(button_colors[i])
32+
magtag.peripherals.play_tone(button_tones[i], 0.25)
33+
break
34+
else:
35+
magtag.peripherals.neopixel_disable = True
36+
time.sleep(0.01)

setup.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)