@@ -231,7 +231,7 @@ def _number(self, number, decimal=0):
231
231
raise ValueError ("Input overflow - {0} is too large for the display!" .format (number ))
232
232
233
233
if dot < 0 :
234
- # No decimal point (Integer)
234
+ # No decimal point (Integer)
235
235
places = len (stnum )
236
236
else :
237
237
places = len (stnum [:dot ])
@@ -243,7 +243,7 @@ def _number(self, number, decimal=0):
243
243
if '.' in stnum :
244
244
places += 1
245
245
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)
247
247
if (places > 0 and decimal > 0 and dot > 0 and (len (stnum [places :]) > decimal )):
248
248
txt = stnum [:dot + decimal + 1 ]
249
249
elif places > 0 :
@@ -264,12 +264,15 @@ def set_digit_raw(self, index, bitmask):
264
264
bitmask should be 2 bytes such as: 0xFFFF
265
265
If can be passed as an integer, list, or tuple
266
266
"""
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' )
269
269
270
270
if isinstance (bitmask , (tuple , list )):
271
271
bitmask = ((bitmask [0 ] & 0xFF ) << 8 ) | (bitmask [1 ] & 0xFF )
272
272
273
+ # Use only the valid potion of bitmask
274
+ bitmask &= 0xFFFF
275
+
273
276
# Set the digit bitmask value at the appropriate position.
274
277
self ._set_buffer (index * 2 , bitmask & 0xFF )
275
278
self ._set_buffer (index * 2 + 1 , (bitmask >> 8 ) & 0xFF )
@@ -368,8 +371,8 @@ def set_digit_raw(self, index, bitmask):
368
371
"""Set digit at position to raw bitmask value. Position should be a value
369
372
of 0 to 3 with 0 being the left most digit on the display.
370
373
"""
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' )
373
376
374
377
# Set the digit bitmask value at the appropriate position.
375
378
self ._set_buffer (self .POSITIONS [index ], bitmask & 0xFF )
0 commit comments