v.0.3.1 font 3x5 pretty

This commit is contained in:
tiijay
2025-10-23 19:06:30 +02:00
parent a66b00989f
commit 9fcc7712e6
7 changed files with 334 additions and 592 deletions

View File

@@ -1,90 +1,98 @@
font_3x5 = {
# Uppercase Letters
'A': [0x07, 0x05, 0x07],
'B': [0x07, 0x07, 0x07],
'C': [0x07, 0x01, 0x07],
'D': [0x06, 0x05, 0x06],
'E': [0x07, 0x03, 0x07],
'F': [0x07, 0x03, 0x01],
'G': [0x07, 0x05, 0x07],
'H': [0x05, 0x07, 0x05],
'I': [0x07, 0x02, 0x07],
'J': [0x04, 0x05, 0x07],
'K': [0x05, 0x03, 0x05],
'L': [0x01, 0x01, 0x07],
'M': [0x07, 0x07, 0x05],
'N': [0x07, 0x05, 0x05],
'O': [0x07, 0x05, 0x07],
'P': [0x07, 0x07, 0x01],
'Q': [0x07, 0x05, 0x07],
'R': [0x07, 0x07, 0x05],
'S': [0x07, 0x07, 0x07],
'T': [0x07, 0x02, 0x02],
'U': [0x05, 0x05, 0x07],
'V': [0x05, 0x05, 0x02],
'W': [0x05, 0x07, 0x07],
'X': [0x05, 0x02, 0x05],
'Y': [0x05, 0x07, 0x02],
'Z': [0x07, 0x02, 0x07],
# Numbers
'0': [0x07, 0x05, 0x07],
'1': [0x02, 0x02, 0x02],
'2': [0x07, 0x07, 0x07],
'3': [0x07, 0x07, 0x07],
'4': [0x05, 0x07, 0x04],
'5': [0x07, 0x07, 0x07],
'6': [0x07, 0x07, 0x07],
'7': [0x07, 0x04, 0x04],
'8': [0x07, 0x07, 0x07],
'9': [0x07, 0x07, 0x07],
# Lowercase (limited)
'a': [0x06, 0x07, 0x07],
'b': [0x01, 0x07, 0x07],
'c': [0x07, 0x01, 0x07],
'd': [0x04, 0x07, 0x07],
'e': [0x07, 0x07, 0x03],
'f': [0x06, 0x07, 0x02],
'g': [0x07, 0x07, 0x06],
'h': [0x01, 0x07, 0x05],
'i': [0x02, 0x00, 0x02],
'j': [0x04, 0x00, 0x06],
'k': [0x01, 0x06, 0x05],
'l': [0x02, 0x02, 0x02],
'm': [0x07, 0x07, 0x05],
'n': [0x07, 0x05, 0x05],
'o': [0x07, 0x05, 0x07],
'p': [0x07, 0x07, 0x01],
'q': [0x07, 0x07, 0x04],
'r': [0x07, 0x01, 0x01],
's': [0x07, 0x07, 0x07],
't': [0x02, 0x07, 0x02],
'u': [0x05, 0x05, 0x07],
'v': [0x05, 0x05, 0x02],
'w': [0x05, 0x07, 0x07],
'x': [0x05, 0x02, 0x05],
'y': [0x05, 0x07, 0x02],
'z': [0x07, 0x02, 0x07],
# Punctuation
' ': [0x00, 0x00, 0x00],
'.': [0x00, 0x00, 0x02],
',': [0x00, 0x00, 0x02],
'!': [0x02, 0x02, 0x00],
'?': [0x07, 0x06, 0x02],
':': [0x00, 0x02, 0x00],
';': [0x00, 0x02, 0x02],
'-': [0x00, 0x07, 0x00],
'_': [0x00, 0x00, 0x07],
'+': [0x02, 0x07, 0x02],
'=': [0x07, 0x00, 0x07],
'(': [0x02, 0x01, 0x02],
')': [0x02, 0x04, 0x02],
'[': [0x03, 0x01, 0x03],
']': [0x06, 0x04, 0x06],
'/': [0x04, 0x02, 0x01],
'\\': [0x01, 0x02, 0x04],
'*': [0x05, 0x02, 0x05],
'"': [0x05, 0x00, 0x00],
"'": [0x02, 0x00, 0x00],
'°': [0x02, 0x05, 0x02], # Degree symbol
'|': [0x02, 0x02, 0x02], # Vertical bar
' ': [0x00, 0x00, 0x00, 0x00, 0x00],
'!': [0x01, 0x01, 0x01, 0x00, 0x01],
'"': [0x05, 0x05, 0x00, 0x00, 0x00],
'#': [0x05, 0x07, 0x05, 0x07, 0x05],
'$': [0x07, 0x06, 0x07, 0x03, 0x07],
'%': [0x05, 0x01, 0x02, 0x04, 0x05],
'&': [0x02, 0x05, 0x02, 0x05, 0x03],
"'": [0x01, 0x01, 0x00, 0x00, 0x00],
'(': [0x01, 0x02, 0x02, 0x02, 0x01],
')': [0x02, 0x01, 0x01, 0x01, 0x02],
'*': [0x00, 0x05, 0x02, 0x05, 0x00],
'+': [0x00, 0x02, 0x07, 0x02, 0x00],
',': [0x00, 0x00, 0x00, 0x01, 0x02],
'-': [0x00, 0x00, 0x07, 0x00, 0x00],
'.': [0x00, 0x00, 0x00, 0x00, 0x01],
'/': [0x01, 0x01, 0x02, 0x04, 0x04],
'0': [0x07, 0x05, 0x05, 0x05, 0x07],
'1': [0x02, 0x06, 0x02, 0x02, 0x07],
'2': [0x07, 0x01, 0x07, 0x04, 0x07],
'3': [0x07, 0x01, 0x07, 0x01, 0x07],
'4': [0x05, 0x05, 0x07, 0x01, 0x01],
'5': [0x07, 0x04, 0x07, 0x01, 0x07],
'6': [0x07, 0x04, 0x07, 0x05, 0x07],
'7': [0x07, 0x01, 0x01, 0x01, 0x01],
'8': [0x07, 0x05, 0x07, 0x05, 0x07],
'9': [0x07, 0x05, 0x07, 0x01, 0x07],
':': [0x00, 0x01, 0x00, 0x01, 0x00],
';': [0x00, 0x01, 0x00, 0x01, 0x02],
'<': [0x01, 0x02, 0x04, 0x02, 0x01],
'=': [0x00, 0x07, 0x00, 0x07, 0x00],
'>': [0x04, 0x02, 0x01, 0x02, 0x04],
'?': [0x07, 0x01, 0x02, 0x00, 0x02],
'@': [0x07, 0x05, 0x07, 0x04, 0x07],
'A': [0x02, 0x05, 0x07, 0x05, 0x05],
'B': [0x06, 0x05, 0x06, 0x05, 0x06],
'C': [0x07, 0x04, 0x04, 0x04, 0x07],
'D': [0x06, 0x05, 0x05, 0x05, 0x06],
'E': [0x07, 0x04, 0x06, 0x04, 0x07],
'F': [0x07, 0x04, 0x06, 0x04, 0x04],
'G': [0x07, 0x04, 0x05, 0x05, 0x07],
'H': [0x05, 0x05, 0x07, 0x05, 0x05],
'I': [0x07, 0x02, 0x02, 0x02, 0x07],
'J': [0x01, 0x01, 0x01, 0x05, 0x02],
'K': [0x05, 0x05, 0x06, 0x05, 0x05],
'L': [0x04, 0x04, 0x04, 0x04, 0x07],
'M': [0x05, 0x07, 0x07, 0x05, 0x05],
'N': [0x05, 0x07, 0x07, 0x07, 0x05],
'O': [0x02, 0x05, 0x05, 0x05, 0x02],
'P': [0x06, 0x05, 0x06, 0x04, 0x04],
'Q': [0x02, 0x05, 0x05, 0x06, 0x03],
'R': [0x06, 0x05, 0x06, 0x05, 0x05],
'S': [0x07, 0x04, 0x02, 0x01, 0x07],
'T': [0x07, 0x02, 0x02, 0x02, 0x02],
'U': [0x05, 0x05, 0x05, 0x05, 0x07],
'V': [0x05, 0x05, 0x05, 0x05, 0x02],
'W': [0x05, 0x05, 0x07, 0x07, 0x05],
'X': [0x05, 0x05, 0x02, 0x05, 0x05],
'Y': [0x05, 0x05, 0x02, 0x02, 0x02],
'Z': [0x07, 0x01, 0x02, 0x04, 0x07],
'[': [0x03, 0x02, 0x02, 0x02, 0x03],
'\\': [0x04, 0x04, 0x02, 0x01, 0x01],
']': [0x03, 0x01, 0x01, 0x01, 0x03],
'^': [0x02, 0x05, 0x00, 0x00, 0x00],
'_': [0x00, 0x00, 0x00, 0x00, 0x07],
'`': [0x02, 0x01, 0x00, 0x00, 0x00],
'a': [0x00, 0x07, 0x05, 0x05, 0x03],
'b': [0x04, 0x04, 0x06, 0x05, 0x06],
'c': [0x00, 0x07, 0x04, 0x04, 0x07],
'd': [0x01, 0x01, 0x07, 0x05, 0x07],
'e': [0x00, 0x07, 0x07, 0x04, 0x07],
'f': [0x03, 0x04, 0x06, 0x04, 0x04],
'g': [0x00, 0x07, 0x05, 0x07, 0x01],
'h': [0x04, 0x04, 0x06, 0x05, 0x05],
'i': [0x01, 0x00, 0x01, 0x01, 0x01],
'j': [0x01, 0x00, 0x01, 0x01, 0x06],
'k': [0x04, 0x05, 0x06, 0x05, 0x05],
'l': [0x06, 0x02, 0x02, 0x02, 0x07],
'm': [0x00, 0x05, 0x07, 0x05, 0x05],
'n': [0x00, 0x06, 0x05, 0x05, 0x05],
'o': [0x00, 0x02, 0x05, 0x05, 0x02],
'p': [0x00, 0x06, 0x05, 0x06, 0x04],
'q': [0x00, 0x07, 0x05, 0x07, 0x01],
'r': [0x00, 0x03, 0x04, 0x04, 0x04],
's': [0x00, 0x07, 0x06, 0x03, 0x07],
't': [0x04, 0x07, 0x04, 0x04, 0x03],
'u': [0x00, 0x05, 0x05, 0x05, 0x07],
'v': [0x00, 0x05, 0x05, 0x05, 0x02],
'w': [0x00, 0x05, 0x05, 0x07, 0x05],
'x': [0x00, 0x05, 0x02, 0x02, 0x05],
'y': [0x00, 0x05, 0x05, 0x07, 0x01],
'z': [0x00, 0x07, 0x02, 0x04, 0x07],
'|': [0x01, 0x01, 0x01, 0x01, 0x01],
'~': [0x00, 0x03, 0x06, 0x00, 0x00],
'°': [0x02, 0x05, 0x02, 0x00, 0x00],
'': [0x07, 0x05, 0x05, 0x05, 0x05],
'': [0x00, 0x00, 0x01, 0x00, 0x00],
}

View File

@@ -1,109 +1,114 @@
# fonts.py - Ready-to-use fonts for LED matrix
# fonts.py - Optimized fonts for LED matrix with character width adjustment
# 5x7 Font (Medium)
# 5x7 Font (Optimized Width)
font_5x7 = {
# Uppercase letters (A-Z)
'A': [0x0E, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11],
'B': [0x1E, 0x11, 0x11, 0x1E, 0x11, 0x11, 0x1E],
'C': [0x0E, 0x11, 0x10, 0x10, 0x10, 0x11, 0x0E],
'D': [0x1E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1E],
'E': [0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x1F],
'F': [0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x10],
'G': [0x0E, 0x11, 0x10, 0x13, 0x11, 0x11, 0x0F],
'H': [0x11, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11],
'I': [0x0E, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0E],
'J': [0x07, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0C],
'K': [0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11],
'L': [0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F],
'M': [0x11, 0x1B, 0x15, 0x15, 0x11, 0x11, 0x11],
'N': [0x11, 0x19, 0x19, 0x15, 0x13, 0x13, 0x11],
'O': [0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E],
'P': [0x1E, 0x11, 0x11, 0x1E, 0x10, 0x10, 0x10],
'Q': [0x0E, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0D],
'R': [0x1E, 0x11, 0x11, 0x1E, 0x14, 0x12, 0x11],
'S': [0x0F, 0x10, 0x10, 0x0E, 0x01, 0x01, 0x1E],
'T': [0x1F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04],
'U': [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E],
'V': [0x11, 0x11, 0x11, 0x11, 0x11, 0x0A, 0x04],
'W': [0x11, 0x11, 0x11, 0x15, 0x15, 0x15, 0x0A],
'X': [0x11, 0x11, 0x0A, 0x04, 0x0A, 0x11, 0x11],
'Y': [0x11, 0x11, 0x0A, 0x04, 0x04, 0x04, 0x04],
'Z': [0x1F, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1F],
# Lowercase letters (a-z)
'a': [0x00, 0x00, 0x0E, 0x01, 0x0F, 0x11, 0x0F],
'b': [0x10, 0x10, 0x16, 0x19, 0x11, 0x11, 0x1E],
'c': [0x00, 0x00, 0x0E, 0x11, 0x10, 0x11, 0x0E],
'd': [0x01, 0x01, 0x0D, 0x13, 0x11, 0x11, 0x0F],
'e': [0x00, 0x00, 0x0E, 0x11, 0x1F, 0x10, 0x0E],
'f': [0x06, 0x09, 0x08, 0x1C, 0x08, 0x08, 0x08],
'g': [0x00, 0x0F, 0x11, 0x11, 0x0F, 0x01, 0x0E],
'h': [0x10, 0x10, 0x16, 0x19, 0x11, 0x11, 0x11],
'i': [0x04, 0x00, 0x0C, 0x04, 0x04, 0x04, 0x0E],
'j': [0x02, 0x00, 0x06, 0x02, 0x02, 0x12, 0x0C],
'k': [0x10, 0x10, 0x12, 0x14, 0x18, 0x14, 0x12],
'l': [0x0C, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0E],
'm': [0x00, 0x00, 0x1A, 0x15, 0x15, 0x15, 0x15],
'n': [0x00, 0x00, 0x16, 0x19, 0x11, 0x11, 0x11],
'o': [0x00, 0x00, 0x0E, 0x11, 0x11, 0x11, 0x0E],
'p': [0x00, 0x00, 0x1E, 0x11, 0x1E, 0x10, 0x10],
'q': [0x00, 0x00, 0x0D, 0x13, 0x0F, 0x01, 0x01],
'r': [0x00, 0x00, 0x16, 0x19, 0x10, 0x10, 0x10],
's': [0x00, 0x00, 0x0E, 0x10, 0x0E, 0x01, 0x1E],
't': [0x08, 0x08, 0x1C, 0x08, 0x08, 0x09, 0x06],
'u': [0x00, 0x00, 0x11, 0x11, 0x11, 0x13, 0x0D],
'v': [0x00, 0x00, 0x11, 0x11, 0x11, 0x0A, 0x04],
'w': [0x00, 0x00, 0x11, 0x11, 0x15, 0x15, 0x0A],
'x': [0x00, 0x00, 0x11, 0x0A, 0x04, 0x0A, 0x11],
'y': [0x00, 0x00, 0x11, 0x11, 0x0F, 0x01, 0x0E],
'z': [0x00, 0x00, 0x1F, 0x02, 0x04, 0x08, 0x1F],
# Numbers (0-9)
'0': [0x0E, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0E],
'1': [0x04, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x0E],
'2': [0x0E, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1F],
'3': [0x1F, 0x02, 0x04, 0x02, 0x01, 0x11, 0x0E],
'4': [0x02, 0x06, 0x0A, 0x12, 0x1F, 0x02, 0x02],
'5': [0x1F, 0x10, 0x1E, 0x01, 0x01, 0x11, 0x0E],
'6': [0x06, 0x08, 0x10, 0x1E, 0x11, 0x11, 0x0E],
'7': [0x1F, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08],
'8': [0x0E, 0x11, 0x11, 0x0E, 0x11, 0x11, 0x0E],
'9': [0x0E, 0x11, 0x11, 0x0F, 0x01, 0x02, 0x0C],
# Punctuation and symbols
' ': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
'!': [0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x04],
'?': [0x0E, 0x11, 0x02, 0x04, 0x04, 0x00, 0x04],
'.': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04],
',': [0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08],
':': [0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00],
';': [0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x08],
"'": [0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00],
'"': [0x0A, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00],
'-': [0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00],
'_': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F],
'+': [0x00, 0x04, 0x04, 0x1F, 0x04, 0x04, 0x00],
'=': [0x00, 0x00, 0x1F, 0x00, 0x1F, 0x00, 0x00],
'*': [0x00, 0x0A, 0x04, 0x1F, 0x04, 0x0A, 0x00],
'/': [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x00],
'\\': [0x00, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00],
'(': [0x02, 0x04, 0x08, 0x08, 0x08, 0x04, 0x02],
')': [0x08, 0x04, 0x02, 0x02, 0x02, 0x04, 0x08],
'[': [0x0E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0E],
']': [0x0E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x0E],
'{': [0x06, 0x04, 0x04, 0x08, 0x04, 0x04, 0x06],
'}': [0x0C, 0x04, 0x04, 0x02, 0x04, 0x04, 0x0C],
'<': [0x00, 0x01, 0x02, 0x04, 0x02, 0x01, 0x00],
'>': [0x00, 0x08, 0x04, 0x02, 0x04, 0x08, 0x00],
'@': [0x0E, 0x11, 0x17, 0x15, 0x17, 0x10, 0x0E],
'#': [0x0A, 0x0A, 0x1F, 0x0A, 0x1F, 0x0A, 0x0A],
'$': [0x04, 0x0F, 0x14, 0x0E, 0x05, 0x1E, 0x04],
'%': [0x18, 0x19, 0x02, 0x04, 0x08, 0x13, 0x03],
'&': [0x0C, 0x12, 0x14, 0x08, 0x15, 0x12, 0x0D],
'^': [0x04, 0x0A, 0x11, 0x00, 0x00, 0x00, 0x00],
'~': [0x00, 0x00, 0x00, 0x0D, 0x12, 0x00, 0x00],
# Uppercase letters (A-Z) - Optimized for better spacing
'A': [0x0E, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11], # Width: 5
'B': [0x1E, 0x11, 0x11, 0x1E, 0x11, 0x11, 0x1E], # Width: 5
'C': [0x0E, 0x11, 0x10, 0x10, 0x10, 0x11, 0x0E], # Width: 5
'D': [0x1E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1E], # Width: 5
'E': [0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x1F], # Width: 5
'F': [0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x10], # Width: 5
'G': [0x0E, 0x11, 0x10, 0x13, 0x11, 0x11, 0x0F], # Width: 5
'H': [0x11, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11], # Width: 5
# 'I': [0x0E, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0E], # Width: 3
'I': [0x07, 0x02, 0x02, 0x02, 0x02, 0x02, 0x07], # Width: 3
'J': [0x07, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0C], # Width: 4
'K': [0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11], # Width: 5
'L': [0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F], # Width: 5
'M': [0x11, 0x1B, 0x15, 0x15, 0x11, 0x11, 0x11], # Width: 5
'N': [0x11, 0x19, 0x19, 0x15, 0x13, 0x13, 0x11], # Width: 5
'O': [0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E], # Width: 5
'P': [0x1E, 0x11, 0x11, 0x1E, 0x10, 0x10, 0x10], # Width: 5
'Q': [0x0E, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0D], # Width: 5
'R': [0x1E, 0x11, 0x11, 0x1E, 0x14, 0x12, 0x11], # Width: 5
'S': [0x0F, 0x10, 0x10, 0x0E, 0x01, 0x01, 0x1E], # Width: 5
'T': [0x1F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04], # Width: 5
'U': [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E], # Width: 5
'V': [0x11, 0x11, 0x11, 0x11, 0x11, 0x0A, 0x04], # Width: 5
'W': [0x11, 0x11, 0x11, 0x15, 0x15, 0x15, 0x0A], # Width: 5
'X': [0x11, 0x11, 0x0A, 0x04, 0x0A, 0x11, 0x11], # Width: 5
'Y': [0x11, 0x11, 0x0A, 0x04, 0x04, 0x04, 0x04], # Width: 5
'Z': [0x1F, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1F], # Width: 5
# Lowercase letters (a-z) - Optimized for compact display
'a': [0x00, 0x00, 0x0E, 0x01, 0x0F, 0x11, 0x0F], # Width: 4
'b': [0x10, 0x10, 0x16, 0x19, 0x11, 0x11, 0x1E], # Width: 5
'c': [0x00, 0x00, 0x0E, 0x11, 0x10, 0x11, 0x0E], # Width: 4
'd': [0x01, 0x01, 0x0D, 0x13, 0x11, 0x11, 0x0F], # Width: 5
'e': [0x00, 0x00, 0x0E, 0x11, 0x1F, 0x10, 0x0E], # Width: 4
'f': [0x06, 0x09, 0x08, 0x1C, 0x08, 0x08, 0x08], # Width: 4
'g': [0x00, 0x0F, 0x11, 0x11, 0x0F, 0x01, 0x0E], # Width: 5
'h': [0x10, 0x10, 0x16, 0x19, 0x11, 0x11, 0x11], # Width: 5
# 'i': [0x00, 0x04, 0x00, 0x0C, 0x04, 0x04, 0x0E], # Width: 2
'i': [0x00, 0x02, 0x00, 0x06, 0x02, 0x02, 0x07], # Width: 2
'j': [0x00, 0x02, 0x00, 0x06, 0x02, 0x12, 0x0C], # Width: 3
'k': [0x10, 0x10, 0x12, 0x14, 0x18, 0x14, 0x12], # Width: 4
# 'l': [0x0C, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0E], # Width: 3
'l': [0x06, 0x02, 0x02, 0x02, 0x02, 0x02, 0x07], # Width: 3
'm': [0x00, 0x00, 0x1A, 0x15, 0x15, 0x15, 0x15], # Width: 5
'n': [0x00, 0x00, 0x16, 0x19, 0x11, 0x11, 0x11], # Width: 5
'o': [0x00, 0x00, 0x0E, 0x11, 0x11, 0x11, 0x0E], # Width: 4
'p': [0x00, 0x00, 0x1E, 0x11, 0x1E, 0x10, 0x10], # Width: 5
'q': [0x00, 0x00, 0x0D, 0x13, 0x0F, 0x01, 0x01], # Width: 5
'r': [0x00, 0x00, 0x16, 0x19, 0x10, 0x10, 0x10], # Width: 5
's': [0x00, 0x00, 0x0E, 0x10, 0x0E, 0x01, 0x1E], # Width: 4
't': [0x08, 0x08, 0x1C, 0x08, 0x08, 0x09, 0x06], # Width: 4
'u': [0x00, 0x00, 0x11, 0x11, 0x11, 0x13, 0x0D], # Width: 5
'v': [0x00, 0x00, 0x11, 0x11, 0x11, 0x0A, 0x04], # Width: 5
'w': [0x00, 0x00, 0x11, 0x11, 0x15, 0x15, 0x0A], # Width: 5
'x': [0x00, 0x00, 0x11, 0x0A, 0x04, 0x0A, 0x11], # Width: 5
'y': [0x00, 0x00, 0x11, 0x11, 0x0F, 0x01, 0x0E], # Width: 5
'z': [0x00, 0x00, 0x1F, 0x02, 0x04, 0x08, 0x1F], # Width: 5
# Numbers (0-9) - Optimized for consistent width
'0': [0x0E, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0E], # Width: 5
'1': [0x02, 0x06, 0x02, 0x02, 0x02, 0x02, 0x07], # Width: 3
# '1': [0x04, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x0E], # Width: 3
# '1': [0x08, 0x18, 0x08, 0x08, 0x08, 0x08, 0x1C], # Width: 3
'2': [0x0E, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1F], # Width: 5
'3': [0x1F, 0x02, 0x04, 0x02, 0x01, 0x11, 0x0E], # Width: 5
'4': [0x02, 0x06, 0x0A, 0x12, 0x1F, 0x02, 0x02], # Width: 5
'5': [0x1F, 0x10, 0x1E, 0x01, 0x01, 0x11, 0x0E], # Width: 5
'6': [0x06, 0x08, 0x10, 0x1E, 0x11, 0x11, 0x0E], # Width: 5
'7': [0x1F, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08], # Width: 5
'8': [0x0E, 0x11, 0x11, 0x0E, 0x11, 0x11, 0x0E], # Width: 5
'9': [0x0E, 0x11, 0x11, 0x0F, 0x01, 0x02, 0x0C], # Width: 5
# Punctuation and symbols - Optimized widths
' ': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # Width: 2
# '!': [0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x04], # Width: 1
'!': [0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01], # Width: 1
'?': [0x0E, 0x11, 0x02, 0x04, 0x04, 0x00, 0x04], # Width: 5
'.': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01], # Width: 1
',': [0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02], # Width: 1
':': [0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00], # Width: 1
';': [0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x02], # Width: 1
"'": [0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00], # Width: 1
'"': [0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00], # Width: 3
'-': [0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00], # Width: 5
'_': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F], # Width: 5
'+': [0x00, 0x04, 0x04, 0x1F, 0x04, 0x04, 0x00], # Width: 5
'=': [0x00, 0x00, 0x1F, 0x00, 0x1F, 0x00, 0x00], # Width: 5
'*': [0x00, 0x0A, 0x04, 0x1F, 0x04, 0x0A, 0x00], # Width: 5
'/': [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x00], # Width: 5
'\\': [0x00, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00], # Width: 5
'(': [0x01, 0x02, 0x04, 0x04, 0x04, 0x02, 0x01], # Width: 3
')': [0x04, 0x02, 0x01, 0x01, 0x01, 0x02, 0x04], # Width: 3
'[': [0x07, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07], # Width: 3
']': [0x07, 0x01, 0x01, 0x01, 0x01, 0x01, 0x07], # Width: 3
'{': [0x03, 0x02, 0x02, 0x04, 0x02, 0x02, 0x03], # Width: 3
'}': [0x06, 0x02, 0x02, 0x01, 0x02, 0x02, 0x06], # Width: 3
'<': [0x00, 0x01, 0x02, 0x04, 0x02, 0x01, 0x00], # Width: 4
'>': [0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00], # Width: 4
'@': [0x0E, 0x11, 0x17, 0x15, 0x17, 0x10, 0x0E], # Width: 5
'#': [0x0A, 0x0A, 0x1F, 0x0A, 0x1F, 0x0A, 0x0A], # Width: 5
'$': [0x04, 0x0F, 0x14, 0x0E, 0x05, 0x1E, 0x04], # Width: 5
'%': [0x18, 0x19, 0x02, 0x04, 0x08, 0x13, 0x03], # Width: 5
'&': [0x0C, 0x12, 0x14, 0x08, 0x15, 0x12, 0x0D], # Width: 5
'^': [0x04, 0x0A, 0x11, 0x00, 0x00, 0x00, 0x00], # Width: 5
'~': [0x00, 0x00, 0x00, 0x0D, 0x12, 0x00, 0x00], # Width: 5
# Special characters
'°': [0x0E, 0x0A, 0x0E, 0x00, 0x00, 0x00, 0x00], # Degree symbol
'|': [0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04], # Vertical bar
'`': [0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00], # Backtick
'': [0x1E, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A], # Paragraph symbol
'': [0x00, 0x00, 0x04, 0x0E, 0x04, 0x00, 0x00], # Bullet point
'°': [0x07, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00], # Width: 3 (Degree symbol)
'|': [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01], # Width: 1 (Vertical bar)
'`': [0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00], # Width: 2 (Backtick)
'': [0x0F, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D], # Width: 5 (Paragraph symbol)
'': [0x00, 0x00, 0x02, 0x07, 0x02, 0x00, 0x00], # Width: 3 (Bullet point)
}

View File

@@ -1,237 +0,0 @@
# fonts.py - Optimized fonts for LED matrix with character width adjustment
# 5x7 Font (Optimized Width)
font_5x7 = {
# Uppercase letters (A-Z) - Optimized for better spacing
'A': [0x0E, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11], # Width: 5
'B': [0x1E, 0x11, 0x11, 0x1E, 0x11, 0x11, 0x1E], # Width: 5
'C': [0x0E, 0x11, 0x10, 0x10, 0x10, 0x11, 0x0E], # Width: 5
'D': [0x1E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1E], # Width: 5
'E': [0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x1F], # Width: 5
'F': [0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x10], # Width: 5
'G': [0x0E, 0x11, 0x10, 0x13, 0x11, 0x11, 0x0F], # Width: 5
'H': [0x11, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11], # Width: 5
# 'I': [0x0E, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0E], # Width: 3
'I': [0x07, 0x02, 0x02, 0x02, 0x02, 0x02, 0x07], # Width: 3
'J': [0x07, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0C], # Width: 4
'K': [0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11], # Width: 5
'L': [0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F], # Width: 5
'M': [0x11, 0x1B, 0x15, 0x15, 0x11, 0x11, 0x11], # Width: 5
'N': [0x11, 0x19, 0x19, 0x15, 0x13, 0x13, 0x11], # Width: 5
'O': [0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E], # Width: 5
'P': [0x1E, 0x11, 0x11, 0x1E, 0x10, 0x10, 0x10], # Width: 5
'Q': [0x0E, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0D], # Width: 5
'R': [0x1E, 0x11, 0x11, 0x1E, 0x14, 0x12, 0x11], # Width: 5
'S': [0x0F, 0x10, 0x10, 0x0E, 0x01, 0x01, 0x1E], # Width: 5
'T': [0x1F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04], # Width: 5
'U': [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E], # Width: 5
'V': [0x11, 0x11, 0x11, 0x11, 0x11, 0x0A, 0x04], # Width: 5
'W': [0x11, 0x11, 0x11, 0x15, 0x15, 0x15, 0x0A], # Width: 5
'X': [0x11, 0x11, 0x0A, 0x04, 0x0A, 0x11, 0x11], # Width: 5
'Y': [0x11, 0x11, 0x0A, 0x04, 0x04, 0x04, 0x04], # Width: 5
'Z': [0x1F, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1F], # Width: 5
# Lowercase letters (a-z) - Optimized for compact display
'a': [0x00, 0x00, 0x0E, 0x01, 0x0F, 0x11, 0x0F], # Width: 4
'b': [0x10, 0x10, 0x16, 0x19, 0x11, 0x11, 0x1E], # Width: 5
'c': [0x00, 0x00, 0x0E, 0x11, 0x10, 0x11, 0x0E], # Width: 4
'd': [0x01, 0x01, 0x0D, 0x13, 0x11, 0x11, 0x0F], # Width: 5
'e': [0x00, 0x00, 0x0E, 0x11, 0x1F, 0x10, 0x0E], # Width: 4
'f': [0x06, 0x09, 0x08, 0x1C, 0x08, 0x08, 0x08], # Width: 4
'g': [0x00, 0x0F, 0x11, 0x11, 0x0F, 0x01, 0x0E], # Width: 5
'h': [0x10, 0x10, 0x16, 0x19, 0x11, 0x11, 0x11], # Width: 5
# 'i': [0x00, 0x04, 0x00, 0x0C, 0x04, 0x04, 0x0E], # Width: 2
'i': [0x00, 0x02, 0x00, 0x06, 0x02, 0x02, 0x07], # Width: 2
'j': [0x00, 0x02, 0x00, 0x06, 0x02, 0x12, 0x0C], # Width: 3
'k': [0x10, 0x10, 0x12, 0x14, 0x18, 0x14, 0x12], # Width: 4
# 'l': [0x0C, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0E], # Width: 3
'l': [0x06, 0x02, 0x02, 0x02, 0x02, 0x02, 0x07], # Width: 3
'm': [0x00, 0x00, 0x1A, 0x15, 0x15, 0x15, 0x15], # Width: 5
'n': [0x00, 0x00, 0x16, 0x19, 0x11, 0x11, 0x11], # Width: 5
'o': [0x00, 0x00, 0x0E, 0x11, 0x11, 0x11, 0x0E], # Width: 4
'p': [0x00, 0x00, 0x1E, 0x11, 0x1E, 0x10, 0x10], # Width: 5
'q': [0x00, 0x00, 0x0D, 0x13, 0x0F, 0x01, 0x01], # Width: 5
'r': [0x00, 0x00, 0x16, 0x19, 0x10, 0x10, 0x10], # Width: 5
's': [0x00, 0x00, 0x0E, 0x10, 0x0E, 0x01, 0x1E], # Width: 4
't': [0x08, 0x08, 0x1C, 0x08, 0x08, 0x09, 0x06], # Width: 4
'u': [0x00, 0x00, 0x11, 0x11, 0x11, 0x13, 0x0D], # Width: 5
'v': [0x00, 0x00, 0x11, 0x11, 0x11, 0x0A, 0x04], # Width: 5
'w': [0x00, 0x00, 0x11, 0x11, 0x15, 0x15, 0x0A], # Width: 5
'x': [0x00, 0x00, 0x11, 0x0A, 0x04, 0x0A, 0x11], # Width: 5
'y': [0x00, 0x00, 0x11, 0x11, 0x0F, 0x01, 0x0E], # Width: 5
'z': [0x00, 0x00, 0x1F, 0x02, 0x04, 0x08, 0x1F], # Width: 5
# Numbers (0-9) - Optimized for consistent width
'0': [0x0E, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0E], # Width: 5
'1': [0x02, 0x06, 0x02, 0x02, 0x02, 0x02, 0x07], # Width: 3
# '1': [0x04, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x0E], # Width: 3
# '1': [0x08, 0x18, 0x08, 0x08, 0x08, 0x08, 0x1C], # Width: 3
'2': [0x0E, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1F], # Width: 5
'3': [0x1F, 0x02, 0x04, 0x02, 0x01, 0x11, 0x0E], # Width: 5
'4': [0x02, 0x06, 0x0A, 0x12, 0x1F, 0x02, 0x02], # Width: 5
'5': [0x1F, 0x10, 0x1E, 0x01, 0x01, 0x11, 0x0E], # Width: 5
'6': [0x06, 0x08, 0x10, 0x1E, 0x11, 0x11, 0x0E], # Width: 5
'7': [0x1F, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08], # Width: 5
'8': [0x0E, 0x11, 0x11, 0x0E, 0x11, 0x11, 0x0E], # Width: 5
'9': [0x0E, 0x11, 0x11, 0x0F, 0x01, 0x02, 0x0C], # Width: 5
# Punctuation and symbols - Optimized widths
' ': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # Width: 2
# '!': [0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x04], # Width: 1
'!': [0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01], # Width: 1
'?': [0x0E, 0x11, 0x02, 0x04, 0x04, 0x00, 0x04], # Width: 5
'.': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01], # Width: 1
',': [0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02], # Width: 1
':': [0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00], # Width: 1
';': [0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x02], # Width: 1
"'": [0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00], # Width: 1
'"': [0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00], # Width: 3
'-': [0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00], # Width: 5
'_': [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F], # Width: 5
'+': [0x00, 0x04, 0x04, 0x1F, 0x04, 0x04, 0x00], # Width: 5
'=': [0x00, 0x00, 0x1F, 0x00, 0x1F, 0x00, 0x00], # Width: 5
'*': [0x00, 0x0A, 0x04, 0x1F, 0x04, 0x0A, 0x00], # Width: 5
'/': [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x00], # Width: 5
'\\': [0x00, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00], # Width: 5
'(': [0x01, 0x02, 0x04, 0x04, 0x04, 0x02, 0x01], # Width: 3
')': [0x04, 0x02, 0x01, 0x01, 0x01, 0x02, 0x04], # Width: 3
'[': [0x07, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07], # Width: 3
']': [0x07, 0x01, 0x01, 0x01, 0x01, 0x01, 0x07], # Width: 3
'{': [0x03, 0x02, 0x02, 0x04, 0x02, 0x02, 0x03], # Width: 3
'}': [0x06, 0x02, 0x02, 0x01, 0x02, 0x02, 0x06], # Width: 3
'<': [0x00, 0x01, 0x02, 0x04, 0x02, 0x01, 0x00], # Width: 4
'>': [0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00], # Width: 4
'@': [0x0E, 0x11, 0x17, 0x15, 0x17, 0x10, 0x0E], # Width: 5
'#': [0x0A, 0x0A, 0x1F, 0x0A, 0x1F, 0x0A, 0x0A], # Width: 5
'$': [0x04, 0x0F, 0x14, 0x0E, 0x05, 0x1E, 0x04], # Width: 5
'%': [0x18, 0x19, 0x02, 0x04, 0x08, 0x13, 0x03], # Width: 5
'&': [0x0C, 0x12, 0x14, 0x08, 0x15, 0x12, 0x0D], # Width: 5
'^': [0x04, 0x0A, 0x11, 0x00, 0x00, 0x00, 0x00], # Width: 5
'~': [0x00, 0x00, 0x00, 0x0D, 0x12, 0x00, 0x00], # Width: 5
# Special characters
'°': [0x07, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00], # Width: 3 (Degree symbol)
'|': [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01], # Width: 1 (Vertical bar)
'`': [0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00], # Width: 2 (Backtick)
'': [0x0F, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D], # Width: 5 (Paragraph symbol)
'': [0x00, 0x00, 0x02, 0x07, 0x02, 0x00, 0x00], # Width: 3 (Bullet point)
}
# Character width mapping for optimized spacing
char_width = {
# Wide characters (5 pixels)
'A': 5,
'B': 5,
'C': 5,
'D': 5,
'E': 5,
'F': 5,
'G': 5,
'H': 5,
'K': 5,
'L': 5,
'M': 5,
'N': 5,
'O': 5,
'P': 5,
'Q': 5,
'R': 5,
'S': 5,
'T': 5,
'U': 5,
'V': 5,
'W': 5,
'X': 5,
'Y': 5,
'Z': 5,
'b': 5,
'd': 5,
'g': 5,
'h': 5,
'm': 5,
'n': 5,
'p': 5,
'q': 5,
'u': 5,
'v': 5,
'w': 5,
'x': 5,
'y': 5,
'z': 5,
'0': 5,
'2': 5,
'3': 5,
'4': 5,
'5': 5,
'6': 5,
'7': 5,
'8': 5,
'9': 5,
'?': 5,
'-': 5,
'_': 5,
'+': 5,
'=': 5,
'*': 5,
'/': 5,
'\\': 5,
'@': 5,
'#': 5,
'$': 5,
'%': 5,
'&': 5,
'^': 5,
'~': 5,
'': 4,
# Medium characters (4 pixels)
'J': 5,
'a': 5,
'c': 5,
'e': 5,
'f': 5,
'k': 5,
'o': 5,
's': 5,
't': 5,
'<': 4,
'>': 4,
# Narrow characters (3 pixels)
'I': 3,
'1': 3,
'l': 3,
'j': 4,
'(': 3,
')': 3,
'[': 3,
']': 3,
'{': 3,
'}': 3,
'°': 3,
'': 3,
# Very narrow characters (2 pixels)
'i': 3,
' ': 1,
'`': 2,
# Single pixel characters
'!': 1,
'.': 1,
',': 2,
':': 1,
';': 2,
"'": 1,
'|': 1,
# Special cases
'"': 3,
}
def get_char_width(char, default_witdth=5):
"""Get the display width of a character for proper spacing"""
return char_width.get(char, default_witdth) # Default to 5 if character not found
def get_text_width(text):
"""Calculate total width of text including character spacing"""
width = 0
for char in text:
if char in char_width:
width += char_width[char] + 1 # +1 for spacing between characters
else:
width += 6 # Default width + spacing
return max(0, width - 1) # Remove last spacing

View File

@@ -1,40 +1,4 @@
from .font_3x5 import font_3x5
from .font_5x7 import font_5x7
from .font_5x7_opt import font_5x7 as font_5x7_opt
from .font_8x8 import font_8x8
from .font_16x16 import font_16x16
from ..emoji.emoji_5x7 import emoji_5x7
from ..emoji.emoji_8x8 import emoji_8x8
from ..emoji.emoji_16x16 import emoji_16x16
from ...utils.utils import number_to_bitarray_msb
fonts_meta_ = {
3: {'w': 3, 'h': 5},
5: {'w': 5, 'h': 7},
8: {'w': 8, 'h': 8},
16: {'w': 16, 'h': 16},
}
def fonts_meta(font):
if font == font_3x5:
return fonts_meta_[3]
elif font == font_5x7:
return fonts_meta_[5]
elif font == font_5x7_opt:
return fonts_meta_[5]
elif font == font_8x8:
return fonts_meta_[8]
elif font == font_16x16:
return fonts_meta_[16]
elif font == emoji_5x7:
return fonts_meta_[5]
elif font == emoji_8x8:
return fonts_meta_[8]
elif font == emoji_16x16:
return fonts_meta_[16]
else:
return None
import app.utils.utils as utils
def char_width(char_matrix) -> int:
@@ -56,3 +20,66 @@ def char_width(char_matrix) -> int:
cw += 1
return cw
def shift_letter_right(char, letter, debug=False) -> bool:
"""Prüfe ob das Zeichen auch komplett nach rechts gezogen ist
Args:
letter (_type_): Array[0..nBytes]
Returns:
bool: _description_
"""
def isLetterRight(letter):
def isByteRight(byte):
return True if 1 & byte == 1 else False
for byte in letter:
if isByteRight(byte):
return True
return False
def shiftLetterRight(letter):
def shift(letter):
return [byte >> 1 for byte in letter]
shifted = letter
for i in range(8): # max 1 Bit's
shifted = shift(shifted)
if isLetterRight(shifted):
break
return shifted
if isLetterRight(letter):
return letter
# letter is not right shifted
shifted = shiftLetterRight(letter)
if debug:
print('origin:')
utils.show_byte_matrix(char, letter)
print('shifted')
utils.show_byte_matrix(char, shifted)
return shifted
def align_font(font):
chars = [char for char in font]
print(chars)
# Print the dictionary
print('font_pretty = {')
for char in sorted(font.keys()):
shifted = shift_letter_right(char=char, letter=font[char])
hex_values = [f'0x{val:02X}' for val in shifted]
print(f"\t'{char}': [{', '.join(hex_values)}],")
print('}')
# return f'#keys: {len(list(font.keys()))}'
return f'#keys: {len(font)}'

View File

@@ -1,9 +1,8 @@
from machine import Pin, RTC
from neopixel import NeoPixel
from .fonts.fonts_utils import fonts_meta, char_width as charwidth
from .fonts.fonts_utils import char_width as charwidth
from .fonts.font_5x7 import font_5x7
from .fonts.font_5x7_opt import font_5x7 as font_5x7_opt, get_char_width
from ..utils.colors import GRAY, RAINBOW, BLACK, WHITE, LIME
from ..utils.utils import (
get_german_timestamp_short,
@@ -32,7 +31,7 @@ class NeoPixel_64x64(NeoPixel):
super().__init__(Pin(pin), self.MATRIX_WIDTH * self.MATRIX_HEIGHT)
# Font configuration
self.set_font(font_5x7_opt)
self.set_font(font_5x7)
def set_font(self, font):
"""
@@ -43,10 +42,10 @@ class NeoPixel_64x64(NeoPixel):
"""
self.selected_font = font
self.selected_font_meta = fonts_meta(font)
self.font_width = self.selected_font_meta['w']
self.font_height = self.selected_font_meta['h']
print(f'Font set: width: {self.font_width}; height: {self.font_height}')
# Höhe des Fonts, Anzahl der Zeilen für jedes Zeichen
# wir holen den Wert aus "A"
self.font_height = len(self.selected_font['A'])
print(f'Font set: width: per char; height: {self.font_height}')
def set_pixel(self, x, y, color):
"""
@@ -92,27 +91,6 @@ class NeoPixel_64x64(NeoPixel):
self.write()
def draw_letter___obsolet(self, letter, x, y, color):
"""
Draw a single letter using current font
Args:
letter: Character to draw
x: X position
y: Y position
color: RGB color tuple
"""
if letter in self.selected_font:
char_data = self.selected_font[letter]
for row in range(self.font_height):
row_data = char_data[row]
for col in range(self.font_width):
# Check if pixel should be lit (MSB first)
if row_data & (1 << ((self.font_width - 1) - col)):
self.set_pixel(x + col, y + row, color)
else:
print(f'oops, letter does not exist in the font -> {letter}')
def draw_letter(self, letter, x, y, color):
"""
Draw a single letter using current font with optimized width
@@ -126,7 +104,6 @@ class NeoPixel_64x64(NeoPixel):
if letter in self.selected_font:
char_data = self.selected_font[letter]
# char_width = get_char_width(letter, default_witdth=16)
char_width = charwidth(char_data)
# background for the letter (full font size)
@@ -150,21 +127,6 @@ class NeoPixel_64x64(NeoPixel):
else:
print(f'oops, letter does not exist in the font -> {letter}')
def draw_text___obsolete(self, text, x, y, color=RAINBOW[2], spacing=1):
"""
Draw text string at specified position
Args:
text: String to display
x: Starting X position
y: Starting Y position
color: RGB color tuple
spacing: Pixels between characters
"""
for idx, char in enumerate(text):
char_x = x + (idx * (self.font_width + spacing))
self.draw_letter(char, char_x, y, color)
def draw_text(self, text, x, y, color):
"""
Draw text with optimized character spacing
@@ -179,7 +141,7 @@ class NeoPixel_64x64(NeoPixel):
for char in text:
self.draw_letter(char, current_x, y, color)
# Move cursor by character width + 1 pixel spacing
char_width = get_char_width(char)
char_width = charwidth(self.selected_font[char])
current_x += char_width + 1
def show_hello(self):
@@ -243,7 +205,6 @@ class NeoPixel_64x64(NeoPixel):
duration: How long to run animation in seconds
"""
start_time = time.time()
text_width = len(text) * (self.font_width + 1)
counter = 0
while time.time() - start_time < duration:
@@ -255,9 +216,10 @@ class NeoPixel_64x64(NeoPixel):
# Draw text at floating position
for i, char in enumerate(text):
char_x = current_x + (i * (self.font_width + 1))
char_width = charwidth(self.selected_font[char])
char_x = current_x + (i * (char_width + 1))
# Keep text within matrix bounds
if 0 <= char_x < self.MATRIX_WIDTH - self.font_width:
if 0 <= char_x < self.MATRIX_WIDTH - char_width:
self.draw_letter(char, char_x, y, color)
self.write()
@@ -276,7 +238,12 @@ class NeoPixel_64x64(NeoPixel):
duration: How long to run animation in seconds
"""
start_time = time.time()
text_width = len(text) * (self.font_width + 1)
# hier müssen wir die Länge/Breite in Pixel des gesamten Textes berechnen
# text_width_overall = len(text) * (self.font_width + 1)
### TODO: ACHTUNG: noch zu testen !!!
# Breite jedes Zeichens
text_width_overall = sum([charwidth(self.selected_font[char]) for char in text])
position = 0
while time.time() - start_time < duration:
@@ -284,10 +251,11 @@ class NeoPixel_64x64(NeoPixel):
# Draw text at current position
for i, char in enumerate(text):
char_x = int(position + (i * (self.font_width + 1)))
char_width = charwidth(self.selected_font[char])
char_x = int(position + (i * (char_width + 1)))
# Handle wrapping
if char_x < -self.font_width:
char_x += self.MATRIX_WIDTH + text_width
if char_x < -char_width:
char_x += self.MATRIX_WIDTH + text_width_overall
if 0 <= char_x < self.MATRIX_WIDTH:
self.draw_letter(char, char_x, y, color)
@@ -295,7 +263,7 @@ class NeoPixel_64x64(NeoPixel):
# Move left and wrap around
position -= speed
if position < -text_width:
if position < -text_width_overall:
position = self.MATRIX_WIDTH
time.sleep(0.05)

View File

@@ -12,52 +12,6 @@ def number_to_bitarray_msb(number, bits=8):
return [(number >> i) & 1 for i in range(bits - 1, -1, -1)]
def is_letter_assigned_right(char, letter) -> bool:
"""Prüfe ob das Zeichen auch komplett nach rechts gezogen ist
Args:
letter (_type_): Array[0..nBytes]
Returns:
bool: _description_
"""
def isLetterRight(letter):
def isByteRight(byte):
return True if 1 & byte == 1 else False
for byte in letter:
if isByteRight(byte):
return True
return False
def shiftLetterRight(letter):
def shift(letter):
return [byte >> 1 for byte in letter]
shifted = letter
for i in range(8): # max 1 Bit's
shifted = shift(shifted)
if isLetterRight(shifted):
break
return shifted
if isLetterRight(letter):
return True
# letter is not right shifted
shifted = shiftLetterRight(letter)
print('origin:')
show_byte_matrix(char, letter)
print('shifted')
show_byte_matrix(char, shifted)
return False
def get_datetime_string(format='full'):
"""
Return date/time as string with different formats