Skip to content

Commit f18507a

Browse files
author
brentru
committed
remove unused bit variable
1 parent 0cef113 commit f18507a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

adafruit_dymoscale.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def toggle_unit_button(self, switch_units=False):
8888
while toggle_times < toggle_amt:
8989
self.units_pin.value ^= 1
9090
time.sleep(2)
91-
toggle_times+=1
91+
toggle_times += 1
9292

9393
def get_scale_data(self):
9494
"""Read a pulse of SPI data on a pin that corresponds to DYMO scale
@@ -102,18 +102,20 @@ def get_scale_data(self):
102102
if (time.monotonic() - timestamp) > self.timeout:
103103
raise RuntimeError("Timed out waiting for data - is the scale turned on?")
104104
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
108108
for i in range(len(self.dymo)):
109109
if self.dymo[i] == 65535: # check for the pulse between transmits
110110
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:
113114
bits[bit_idx] = bit_val
114115
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
116117
break
118+
bit += 1
117119
bit_val = not bit_val
118120
data_bytes = [0] * 12 # alllocate data array
119121
for byte_n in range(12):
@@ -142,4 +144,4 @@ def get_scale_data(self):
142144
data_bytes[4] -= 0x100
143145
print('Tare - press the tare button to reset the scale to zero.')
144146
weight *= 10 ** data_bytes[4]
145-
return weight
147+
return weight

0 commit comments

Comments
 (0)