Skip to content

Commit 24fb972

Browse files
committed
Manual merge of #63
1 parent 25a4d8d commit 24fb972

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

adafruit_ht16k33/segments.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def _number(self, number, decimal=0):
231231
raise ValueError("Input overflow - {0} is too large for the display!".format(number))
232232

233233
if dot < 0:
234-
# No decimal point (Integer)
234+
# No decimal point (Integer)
235235
places = len(stnum)
236236
else:
237237
places = len(stnum[:dot])
@@ -243,7 +243,7 @@ def _number(self, number, decimal=0):
243243
if '.' in stnum:
244244
places += 1
245245

246-
# Set decimal places, if number of decimal places is specified (decimal > 0)
246+
# Set decimal places, if number of decimal places is specified (decimal > 0)
247247
if (places > 0 and decimal > 0 and dot > 0 and (len(stnum[places:]) > decimal)):
248248
txt = stnum[:dot + decimal + 1]
249249
elif places > 0:
@@ -264,12 +264,15 @@ def set_digit_raw(self, index, bitmask):
264264
bitmask should be 2 bytes such as: 0xFFFF
265265
If can be passed as an integer, list, or tuple
266266
"""
267-
if not 0 <= index <= 3:
268-
return
267+
if not isinstance(index, int) or not 0 <= index <= 3:
268+
raise ValueError('Index value must be an integer in the range: 0-3')
269269

270270
if isinstance(bitmask, (tuple, list)):
271271
bitmask = ((bitmask[0] & 0xFF) << 8) | (bitmask[1] & 0xFF)
272272

273+
# Use only the valid potion of bitmask
274+
bitmask &= 0xFFFF
275+
273276
# Set the digit bitmask value at the appropriate position.
274277
self._set_buffer(index * 2, bitmask & 0xFF)
275278
self._set_buffer(index * 2 + 1, (bitmask >> 8) & 0xFF)
@@ -368,8 +371,8 @@ def set_digit_raw(self, index, bitmask):
368371
"""Set digit at position to raw bitmask value. Position should be a value
369372
of 0 to 3 with 0 being the left most digit on the display.
370373
"""
371-
if not 0 <= index <= 3:
372-
return
374+
if not isinstance(index, int) or not 0 <= index <= 3:
375+
raise ValueError('Index value must be an integer in the range: 0-3')
373376

374377
# Set the digit bitmask value at the appropriate position.
375378
self._set_buffer(self.POSITIONS[index], bitmask & 0xFF)

0 commit comments

Comments
 (0)