2020 https://github.com/adafruit/circuitpython/releases
2121"""
2222
23+ try :
24+ import typing # pylint: disable=unused-import
25+ from digitalio import DigitalInOut
26+ import microcontroller
27+ except ImportError :
28+ pass
29+
2330import time
2431from pulseio import PulseIn
2532from micropython import const
@@ -43,7 +50,12 @@ class ScaleReading:
4350class DYMOScale :
4451 """Interface to a DYMO postal scale."""
4552
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 :
4759 """Sets up a DYMO postal scale.
4860 :param ~pulseio.PulseIn data_pin: The data pin from the Dymo scale.
4961 :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):
5668 self .dymo = PulseIn (data_pin , maxlen = 96 , idle_state = True )
5769
5870 @property
59- def weight (self ):
71+ def weight (self ) -> ScaleReading :
6072 """Weight in grams"""
6173 reading = self .get_scale_data ()
6274 if reading .units == OUNCES :
6375 reading .weight *= 28.35
6476 reading .units = GRAMS
6577 return reading
6678
67- def toggle_unit_button (self , switch_units = False ):
79+ def toggle_unit_button (self , switch_units : bool = False ) -> None :
6880 """Toggles the unit button on the dymo.
6981 :param bool switch_units: Simulates pressing the units button.
7082 """
@@ -78,7 +90,7 @@ def toggle_unit_button(self, switch_units=False):
7890 time .sleep (2 )
7991 toggle_times += 1
8092
81- def _read_pulse (self ):
93+ def _read_pulse (self ) -> None :
8294 """Reads a pulse of SPI data on a pin that corresponds to DYMO scale
8395 output protocol (12 bytes of data at about 14KHz).
8496 """
@@ -93,7 +105,7 @@ def _read_pulse(self):
93105 )
94106 self .dymo .pause ()
95107
96- def get_scale_data (self ):
108+ def get_scale_data (self ) -> ScaleReading :
97109 """Reads a pulse of SPI data and analyzes the resulting data."""
98110 self ._read_pulse ()
99111 bits = [0 ] * 96 # there are 12 bytes = 96 bits of data
0 commit comments