Skip to content

Commit

Permalink
change the way getting time img is done
Browse files Browse the repository at this point in the history
  • Loading branch information
jcksnvllxr80 committed Dec 6, 2021
1 parent a7c96fc commit e26a35f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
26 changes: 20 additions & 6 deletions img/img_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
eight_ba = bytearray(b'\x00\x00\x00\x03\xfc\x00\x03\xfc\x00\x1f\xff\x80\x3e\x0f\xc0\x3e\x0f\xc0\x7c\x07\xc0\x7c\x07\xc0\x7c\x07\xc0\x7c\x07\xc0\x7c\x07\xc0\x7c\x07\xc0\x3e\x0f\x80\x1f\xfc\x00\x1f\xfc\x00\x07\xfe\x00\x3e\x0f\x80\x3e\x0f\x80\x3c\x07\xc0\x7c\x07\xc0\x7c\x07\xc0\x7c\x07\xc0\x7c\x07\xc0\x7c\x07\xc0\x7c\x07\xc0\x3e\x0f\x80\x3e\x0f\x80\x1f\xfe\x00\x03\xf8\x00\x03\xf8\x00\x00\x00\x00\x00\x00\x00') # '8', 24x32px
nine_ba = bytearray(b'\x00\x00\x00\x03\xfc\x00\x03\xfc\x00\x0f\xff\x00\x3e\x0f\x80\x3e\x0f\x80\x3e\x0f\x80\x3c\x0f\x80\x7c\x03\xe0\x7c\x03\xe0\x7c\x03\xe0\x7c\x03\xe0\x7c\x03\xe0\x7c\x03\xe0\x7c\x03\xe0\x3e\x0f\xe0\x3f\xff\xe0\x3f\xff\xe0\x3f\xff\xe0\x07\xe3\xe0\x00\x0f\x80\x00\x0f\x80\x00\x0f\x80\x00\x0f\x00\x00\x1f\x00\x00\x7e\x00\x00\x7e\x00\x07\xf0\x00\x07\xf0\x00\x07\xc0\x00\x00\x00\x00\x00\x00\x00') # '9', 24x32px
colon_ba = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x07\xc0\x07\xc0\x07\xc0\x07\xc0\x07\xc0\x07\xc0\x07\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\xc0\x07\xc0\x07\xc0\x07\xc0\x07\xc0\x07\xc0\x07\xc0\x00\x00\x00\x00\x00\x00\x00\x00') # 'colon', 16x32px

none_ba = bytearray(b'\x00') # '', 8x1px
led_style_list = [
"rainbow", "chase", "fill", "off", "red", "yellow", "green", "cyan", "blue", "purple",
"white", "firefly", "blend", "flash"
]

ba_dict = {
style_ba_dict = {
led_style_list[0]: rainbow_ba,
led_style_list[1]: chase_ba,
led_style_list[2]: fill_ba,
Expand All @@ -46,7 +46,8 @@
led_style_list[13]: flash_ba
}

num_ba_dict={
time_ba_dict = {
":": colon_ba,
0: zero_ba,
1: one_ba,
2: two_ba,
Expand All @@ -56,7 +57,8 @@
6: six_ba,
7: seven_ba,
8: eight_ba,
9: nine_ba
9: nine_ba,
None: none_ba
}

months_dict = {
Expand Down Expand Up @@ -89,5 +91,17 @@ def get_style_list():
return led_style_list


def get_img(string_id):
return ba_dict.get(string_id, rainbow_ba)
def get_style_img(string_id):
return style_ba_dict.get(string_id, rainbow_ba)


def get_time_img(id):
return time_ba_dict.get(id, None)


def get_month(month_id):
return months_dict.get(month_id, month_id)


def get_day_of_week(day_of_week_id):
return days_dict.get(day_of_week_id, str(day_of_week_id))
28 changes: 19 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
SPI_FREQ = 115_200
SPI_PORT = 0
UART_BAUD = 115200
COLON = ':'
uart_port = 1
uart_tx_pin = 4
uart_rx_pin = 5
Expand Down Expand Up @@ -58,6 +59,8 @@
ones_min_digit_start_x = 100
mini_style_start_x = 0
mini_style_start_y = 56
none_px_x = 8
none_px_y = 1

button = Pin(15, Pin.IN, Pin.PULL_UP)
onboard_led = Pin(25, Pin.OUT)
Expand Down Expand Up @@ -214,7 +217,7 @@ def color_chase(color, wait):

def update_oled_display(oled_timer):
if (time() - last_button_press) < INACTIVITY_TIMER:
display_image(img_utils.get_img(led_style))
display_image(img_utils.get_style_img(led_style))
else:
display_date_and_time()

Expand Down Expand Up @@ -378,7 +381,7 @@ def do_flash():

def display_image(byte_array):
# Load image into the framebuffer64)
fb = framebuf.FrameBuffer(byte_array, fullscreen_px_x,fullscreen_px_y, framebuf.MONO_HLSB)
fb = get_frame_buffer(byte_array, fullscreen_px_x,fullscreen_px_y)
# Clear oled display
oled.fill(0)
oled.blit(fb, 1, 1)
Expand All @@ -387,9 +390,9 @@ def display_image(byte_array):

def get_date_string(now):
year = str(now[0])
month = img_utils.months_dict[now[1]]
month = img_utils.get_month(now[1])
day = now[2]
day_of_wk = img_utils.days_dict[now[3]]
day_of_wk = img_utils.get_day_of_week(now[3])
return ''.join([day_of_wk, ', ', "{0}{1:2}".format(month, day), ', ', year])


Expand Down Expand Up @@ -417,14 +420,21 @@ def create_date_text(date_str):
oled.text(date_str, date_start_x, date_start_y)


def get_frame_buffer(img_ba, x_px, y_px):
if img_ba is None:
return framebuf.FrameBuffer(img_utils.get_time_img(None), none_px_x, none_px_y, framebuf.MONO_HLSB)
else:
return framebuf.FrameBuffer(img_ba, x_px, y_px, framebuf.MONO_HLSB)


def create_time_image(digits_tuple):
(tens_hr, ones_hr, tens_min, ones_min) = digits_tuple
# load frame buffs for time image
tens_hr_fb = framebuf.FrameBuffer(img_utils.num_ba_dict[tens_hr], digit_px_x, digit_px_y, framebuf.MONO_HLSB)
ones_hr_fb = framebuf.FrameBuffer(img_utils.num_ba_dict[ones_hr], digit_px_x, digit_px_y, framebuf.MONO_HLSB)
colon_fb = framebuf.FrameBuffer(img_utils.colon_ba, colon_px_x, digit_px_y, framebuf.MONO_HLSB)
tens_min_fb = framebuf.FrameBuffer(img_utils.num_ba_dict[tens_min], digit_px_x, digit_px_y, framebuf.MONO_HLSB)
ones_min_fb = framebuf.FrameBuffer(img_utils.num_ba_dict[ones_min], digit_px_x, digit_px_y, framebuf.MONO_HLSB)
tens_hr_fb = get_frame_buffer(img_utils.get_time_img(tens_hr), digit_px_x, digit_px_y)
ones_hr_fb = get_frame_buffer(img_utils.get_time_img(ones_hr), digit_px_x, digit_px_y)
colon_fb = get_frame_buffer(img_utils.get_time_img(COLON), colon_px_x, digit_px_y)
tens_min_fb = get_frame_buffer(img_utils.get_time_img(tens_min), digit_px_x, digit_px_y)
ones_min_fb = get_frame_buffer(img_utils.get_time_img(ones_min), digit_px_x, digit_px_y)
# add image chunks
oled.blit(tens_hr_fb, tens_hr_digit_start_x, digit_start_y)
oled.blit(ones_hr_fb, ones_hr_digit_start_x, digit_start_y)
Expand Down

0 comments on commit e26a35f

Please sign in to comment.