initial
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
def convert_rgb_to_rgb565_numpy(image):
|
||||
if image.mode != 'RGB':
|
||||
raise ValueError('Image must be in RGB mode')
|
||||
|
||||
# Convert image to NumPy array
|
||||
img_array = np.array(image)
|
||||
|
||||
# Extract the individual RGB components
|
||||
r = img_array[:,:,0].astype(np.uint16)
|
||||
g = img_array[:,:,1].astype(np.uint16)
|
||||
b = img_array[:,:,2].astype(np.uint16)
|
||||
|
||||
# Shift the bits into the correct positions for RGB565
|
||||
# rgb565_array = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3)
|
||||
# Shift the bits into the correct positions for RGB565 using NumPy's bitwise functions
|
||||
rgb565_array = np.bitwise_or(np.bitwise_or(np.left_shift(np.bitwise_and(r, 0xF8), 8),
|
||||
np.left_shift(np.bitwise_and(g, 0xFC), 3)),
|
||||
np.right_shift(b, 3))
|
||||
|
||||
# Flatten the array to a 1D array of bytes and return
|
||||
return rgb565_array.flatten().tobytes()
|
||||
@@ -0,0 +1,9 @@
|
||||
import requests
|
||||
|
||||
|
||||
|
||||
def get_status_data():
|
||||
url = 'https://life.itguy.ro/lifeapi/status.html'
|
||||
data = requests.get(url).json()
|
||||
return data
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import select
|
||||
import sys
|
||||
import termios
|
||||
import tty
|
||||
|
||||
def disable_cursor(tty):
|
||||
with open(tty, 'w') as t:
|
||||
t.write("\033[?25l")
|
||||
|
||||
def enable_cursor(tty):
|
||||
with open(tty, 'w') as t:
|
||||
t.write("\033[?25h")
|
||||
|
||||
def restore_screen(tty):
|
||||
with open(tty, 'w') as t:
|
||||
t.write("\033[?5h\033[?5l")
|
||||
|
||||
|
||||
def was_key_pressed():
|
||||
# Save the terminal settings
|
||||
fd = sys.stdin.fileno()
|
||||
old_settings = termios.tcgetattr(fd)
|
||||
|
||||
try:
|
||||
# Set the terminal to raw mode to read key press
|
||||
tty.setraw(sys.stdin.fileno())
|
||||
|
||||
# Use select to check if there's any input
|
||||
rlist, _, _ = select.select([sys.stdin], [], [], 0)
|
||||
finally:
|
||||
# Restore the terminal settings
|
||||
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
||||
|
||||
return bool(rlist)
|
||||
Reference in New Issue
Block a user