19
19
* Adafruit CircuitPython firmware for the supported boards:
20
20
https://github.com/adafruit/circuitpython/releases
21
21
"""
22
-
22
+ try :
23
+ import typing
24
+ except ImportError :
25
+ pass
26
+
23
27
import time
24
28
from pulseio import PulseIn
25
29
from micropython import const
@@ -43,7 +47,7 @@ class ScaleReading:
43
47
class DYMOScale :
44
48
"""Interface to a DYMO postal scale."""
45
49
46
- def __init__ (self , data_pin , units_pin , timeout = 1.0 ):
50
+ def __init__ (self , data_pin : pulseio . PulseIn , units_pin : digitalio . DigitalInOut , timeout : double = 1.0 ) -> None :
47
51
"""Sets up a DYMO postal scale.
48
52
:param ~pulseio.PulseIn data_pin: The data pin from the Dymo scale.
49
53
:param ~digitalio.DigitalInOut units_pin: The grams/oz button from the Dymo scale.
@@ -56,15 +60,15 @@ def __init__(self, data_pin, units_pin, timeout=1.0):
56
60
self .dymo = PulseIn (data_pin , maxlen = 96 , idle_state = True )
57
61
58
62
@property
59
- def weight (self ):
63
+ def weight (self ) -> ScaleReading :
60
64
"""Weight in grams"""
61
65
reading = self .get_scale_data ()
62
66
if reading .units == OUNCES :
63
67
reading .weight *= 28.35
64
68
reading .units = GRAMS
65
69
return reading
66
70
67
- def toggle_unit_button (self , switch_units = False ):
71
+ def toggle_unit_button (self , switch_units : bool = False ) -> None :
68
72
"""Toggles the unit button on the dymo.
69
73
:param bool switch_units: Simulates pressing the units button.
70
74
"""
@@ -78,7 +82,7 @@ def toggle_unit_button(self, switch_units=False):
78
82
time .sleep (2 )
79
83
toggle_times += 1
80
84
81
- def _read_pulse (self ):
85
+ def _read_pulse (self ) -> None :
82
86
"""Reads a pulse of SPI data on a pin that corresponds to DYMO scale
83
87
output protocol (12 bytes of data at about 14KHz).
84
88
"""
@@ -93,7 +97,7 @@ def _read_pulse(self):
93
97
)
94
98
self .dymo .pause ()
95
99
96
- def get_scale_data (self ):
100
+ def get_scale_data (self ) -> ScaleReading :
97
101
"""Reads a pulse of SPI data and analyzes the resulting data."""
98
102
self ._read_pulse ()
99
103
bits = [0 ] * 96 # there are 12 bytes = 96 bits of data
0 commit comments