142 lines
3.5 KiB
Python
142 lines
3.5 KiB
Python
import time
|
|
|
|
|
|
def show_byte_matrix(char, matrix):
|
|
print(f'byte_matrix: char({char})')
|
|
matrix_str = [f'0x{byte:02X}' for byte in matrix]
|
|
[print(f'{matrix_str[idx]} {number_to_bitarray_msb(byte)}') for idx, byte in enumerate(matrix)]
|
|
|
|
|
|
def number_to_bitarray_msb(number):
|
|
"""Convert 8-bit number to bit array (MSB first)"""
|
|
return [(number >> i) & 1 for i in range(7, -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
|
|
|
|
Args:
|
|
format: "full", "date", "time", "short", "ticks"
|
|
"""
|
|
try:
|
|
year, month, day, hour, minute, second, weekday, yearday = time.localtime()
|
|
|
|
if format == 'full':
|
|
return f'{year:04d}-{month:02d}-{day:02d} {hour:02d}:{minute:02d}:{second:02d}'
|
|
elif format == 'date':
|
|
return f'{year:04d}-{month:02d}-{day:02d}'
|
|
elif format == 'time':
|
|
return f'{hour:02d}:{minute:02d}:{second:02d}'
|
|
elif format == 'short':
|
|
return f'{month:02d}/{day:02d} {hour:02d}:{minute:02d}'
|
|
else:
|
|
return f'Ticks: {time.ticks_ms()} ms'
|
|
|
|
except:
|
|
return f'Ticks: {time.ticks_ms()} ms'
|
|
|
|
|
|
def get_german_datetime():
|
|
"""Return German date and time"""
|
|
try:
|
|
year, month, day, hour, minute, second, weekday, yearday = time.localtime()
|
|
|
|
weekdays = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']
|
|
weekday_name = weekdays[weekday]
|
|
|
|
return f'{weekday_name}.{day:02d}.{month:02d}.{year} {hour:02d}:{minute:02d}'
|
|
|
|
except:
|
|
ticks = time.ticks_ms() // 1000
|
|
return f'Zeit: {ticks} sek'
|
|
|
|
|
|
def get_german_timestamp_short():
|
|
"""Get German timestamp with short months (for Wokwi)"""
|
|
ticks = time.ticks_ms()
|
|
day = (ticks // 86400000) % 31 + 1
|
|
month = (ticks // 2592000000) % 12 + 1
|
|
hour = (ticks // 3600000) % 24
|
|
minute = (ticks // 60000) % 60
|
|
|
|
months = ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez']
|
|
month_name = months[month - 1]
|
|
|
|
return f'{day}.{month_name} {hour:02d}:{minute:02d}'
|
|
|
|
|
|
def get_german_time_ticks():
|
|
"""Get German time using ticks (works in Wokwi)"""
|
|
ticks = time.ticks_ms()
|
|
|
|
# Simulate time progression
|
|
total_seconds = ticks // 1000
|
|
hours = (total_seconds // 3600) % 24
|
|
minutes = (total_seconds // 60) % 60
|
|
seconds = total_seconds % 60
|
|
|
|
return f'{hours:02d}:{minutes:02d}:{seconds:02d}'
|
|
|
|
|
|
def get_german_date_ticks():
|
|
"""Get German date using ticks"""
|
|
ticks = time.ticks_ms()
|
|
|
|
# Simulate date progression (starting from Jan 15, 2024)
|
|
days_passed = ticks // (24 * 3600 * 1000)
|
|
day = 15 + (days_passed % 28) # Simple month simulation
|
|
month = 1 + (days_passed // 28) % 12
|
|
year = 2024 + (days_passed // (28 * 12))
|
|
|
|
months = ['JAN', 'FEB', 'MAR', 'APR', 'MAI', 'JUN', 'JUL', 'AUG', 'SEP', 'OKT', 'NOV', 'DEZ']
|
|
month_name = months[month - 1]
|
|
|
|
return f'{day:02d}.{month_name}.{str(year)[-2:]}'
|