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