@@ -88,7 +88,7 @@ def toggle_unit_button(self, switch_units=False):
88
88
while toggle_times < toggle_amt :
89
89
self .units_pin .value ^= 1
90
90
time .sleep (2 )
91
- toggle_times += 1
91
+ toggle_times += 1
92
92
93
93
def get_scale_data (self ):
94
94
"""Read a pulse of SPI data on a pin that corresponds to DYMO scale
@@ -102,18 +102,20 @@ def get_scale_data(self):
102
102
if (time .monotonic () - timestamp ) > self .timeout :
103
103
raise RuntimeError ("Timed out waiting for data - is the scale turned on?" )
104
104
self .dymo .pause ()
105
- bits = [0 ] * 96 # there are 12 bytes = 96 bits of data
106
- bit_idx = 0 # we will count a bit at a time
107
- bit_val = False # first pulses will be LOW
105
+ bits = [0 ] * 96 # there are 12 bytes = 96 bits of data
106
+ bit_idx = 0 # we will count a bit at a time
107
+ bit_val = False # first pulses will be LOW
108
108
for i in range (len (self .dymo )):
109
109
if self .dymo [i ] == 65535 : # check for the pulse between transmits
110
110
break
111
- num_bits = int (self .dymo [i ] / PULSE_WIDTH + 0.5 ) # ~14KHz == ~7.5us per clock
112
- for bit in range (num_bits ):
111
+ num_bits = int (self .dymo [i ] / PULSE_WIDTH + 0.5 ) # ~14KHz == ~7.5us per clock
112
+ bit = 0
113
+ while bit < num_bits :
113
114
bits [bit_idx ] = bit_val
114
115
bit_idx += 1
115
- if bit_idx == 96 : # we have read all the data we wanted
116
+ if bit_idx == 96 : # we have read all the data we wanted
116
117
break
118
+ bit += 1
117
119
bit_val = not bit_val
118
120
data_bytes = [0 ] * 12 # alllocate data array
119
121
for byte_n in range (12 ):
@@ -142,4 +144,4 @@ def get_scale_data(self):
142
144
data_bytes [4 ] -= 0x100
143
145
print ('Tare - press the tare button to reset the scale to zero.' )
144
146
weight *= 10 ** data_bytes [4 ]
145
- return weight
147
+ return weight
0 commit comments