-
Notifications
You must be signed in to change notification settings - Fork 28
Port changes to the number() routine in the micropython library to _number() #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
05f7c24
84506be
c2615fc
3345cf7
7a56c85
56945d5
73165d4
3f2d74c
11fe810
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,8 @@ | |
""" | ||
|
||
from time import sleep | ||
from adafruit_ht16k33.ht16k33 import HT16K33 | ||
#from adafruit_ht16k33.ht16k33 import HT16K33 | ||
from adafruit_ht16k33.matrix import HT16K33 | ||
makermelissa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
__version__ = "0.0.0-auto.0" | ||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git" | ||
|
@@ -151,12 +152,15 @@ | |
|
||
class Seg14x4(HT16K33): | ||
"""Alpha-numeric, 14-segment display.""" | ||
def print(self, value): | ||
# If True, debugging code will be executed | ||
debug = False | ||
|
||
def print(self, value, decimal=0): | ||
"""Print the value to the display.""" | ||
if isinstance(value, (str)): | ||
self._text(value) | ||
elif isinstance(value, (int, float)): | ||
self._number(value) | ||
self._number(value, decimal) | ||
else: | ||
raise ValueError('Unsupported display value type: {}'.format(type(value))) | ||
if self._auto_write: | ||
|
@@ -211,21 +215,62 @@ def _text(self, text): | |
for character in text: | ||
self._push(character) | ||
|
||
def _number(self, number): | ||
"""Display the specified decimal number.""" | ||
''' | ||
Display a floating point or integer number on the Adafruit HT16K33 based displays | ||
|
||
Param: number - The floating point or integer number to be displayed, which must be | ||
in the range 0 (zero) to 9999 for integers and floating point or integer numbers | ||
and between 0.0 and 999.0 or 99.00 or 9.000 for floating point numbers. | ||
Param: decimal - The number of decimal places for a floating point number if decimal | ||
is greater than zero, or the input number is an integer if decimal is zero. | ||
|
||
Returns: The output text string to be displayed.''' | ||
makermelissa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def _number(self, number, decimal=0): | ||
auto_write = self._auto_write | ||
self._auto_write = False | ||
string = "{}".format(number) | ||
if len(string) > 4: | ||
if string.find('.') > 4: | ||
raise ValueError("Overflow") | ||
self.fill(False) | ||
places = 4 | ||
if '.' in string: | ||
places += 1 | ||
self._text(string[:places]) | ||
stnum = str(number) | ||
dot = stnum.find('.') | ||
|
||
if ((len(stnum) > 5) or ((len(stnum) > 4) and (dot < 0))): | ||
raise ValueError("Input overflow - {0} is too large for the display!".format(number)) | ||
|
||
if dot < 0: | ||
# No decimal point (Integer) | ||
places = len(stnum) | ||
else: | ||
places = len(stnum[:dot]) | ||
|
||
if self.debug: | ||
print("(1) number = {0}, places = {1}, decimal = {2}, dot = {3}, stnum = '{4}'".format(number, places, decimal, dot, stnum)) | ||
makermelissa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if ((places <= 0) and (decimal > 0)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is failing pylint because of the parenthesis and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment on zero checks. |
||
self.fill(False) | ||
places = 4 | ||
|
||
if '.' in stnum: | ||
places += 1 | ||
|
||
if self.debug: | ||
print("(2) places = {0}, dot = {1}, decimal = {2}, stnum = '{3}'".format(places, dot, decimal, stnum)) | ||
|
||
# Set decimal places, if number of decimal places is specified (decimal > 0) | ||
if ((places > 0) and (decimal > 0) and (dot > 0) and (len(stnum[places:]) > decimal)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is failing pylint because of all the parenthesis and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [code]if places and decimal and dot will be true as long as one of them is not zero. This is true for Python 3.7.3. I should be able to remove the parentheses without changing the meaning. |
||
txt = stnum[:dot + decimal + 1] | ||
elif places > 0: | ||
txt = stnum[:places] | ||
|
||
if self.debug: | ||
print("(3) places = {0}, stnum = '{1}', decimal = {2}, txt = '{3}'".format(places, stnum, decimal, txt)) | ||
print() | ||
|
||
if len(txt) > 5: | ||
raise ValueError("Output string ('{0}') is too long!".format(txt)) | ||
|
||
self._text(txt) | ||
self._auto_write = auto_write | ||
|
||
return txt | ||
|
||
def set_digit_raw(self, index, bitmask): | ||
"""Set digit at position to raw bitmask value. Position should be a value | ||
of 0 to 3 with 0 being the left most character on the display. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a minor nitpick, can we remove this commented out line please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! I would have nitpicked that too.