initial
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import os
|
||||
import fcntl
|
||||
import struct
|
||||
import mmap
|
||||
from time import sleep
|
||||
|
||||
with open('/dev/tty1', 'w') as tty:
|
||||
tty.write("\033[?25l")
|
||||
|
||||
|
||||
# Constants for the ioctl call
|
||||
FBIOGET_VSCREENINFO = 0x4600
|
||||
|
||||
# Define a function to perform an ioctl call to get screen info
|
||||
def get_screen_info(fb_device):
|
||||
# We will get the variable screen info (resolution and bits per pixel)
|
||||
# The struct for variable screen info is defined in the Linux kernel headers
|
||||
# as fb_var_screeninfo, which is 56 bytes
|
||||
screen_info_format = '8I12I16I2I'
|
||||
screen_info = struct.pack(screen_info_format, *([0] * 38))
|
||||
screen_info = fcntl.ioctl(fb_device, FBIOGET_VSCREENINFO, screen_info)
|
||||
return struct.unpack(screen_info_format, screen_info)
|
||||
|
||||
# Open the framebuffer device in read-write mode
|
||||
with open("/dev/fb0", "r+b") as fb:
|
||||
# Get screen information using ioctl
|
||||
info = get_screen_info(fb)
|
||||
xres, yres, bits_per_pixel = info[0], info[1], info[6]
|
||||
screensize = xres * yres * bits_per_pixel // 8
|
||||
|
||||
# Create a memory-mapped area to the framebuffer
|
||||
fb_bytes = mmap.mmap(fb.fileno(), screensize, mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ)
|
||||
|
||||
# Now you can write pixel data to the framebuffer
|
||||
# Here is an example that just sets all pixels to black
|
||||
fb_bytes.seek(0) # Go to the beginning of the framebuffer
|
||||
fb_bytes.write(b'\x00' * screensize)
|
||||
|
||||
# Your framebuffer application code here
|
||||
|
||||
# Once your program is finished, you can unmap and close the framebuffer device
|
||||
fb_bytes.close()
|
||||
|
||||
import sys
|
||||
import termios
|
||||
import atexit
|
||||
from select import select
|
||||
|
||||
# Save the terminal settings
|
||||
fd = sys.stdin.fileno()
|
||||
old_settings = termios.tcgetattr(fd)
|
||||
atexit.register(lambda: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings))
|
||||
|
||||
def wait_for_key_press():
|
||||
# Disable canonical input and echo
|
||||
new_settings = termios.tcgetattr(fd)
|
||||
new_settings[3] = new_settings[3] & ~termios.ICANON & ~termios.ECHO
|
||||
termios.tcsetattr(fd, termios.TCSADRAIN, new_settings)
|
||||
|
||||
# Wait for input
|
||||
rlist, _, _ = select([sys.stdin], [], [], None)
|
||||
if rlist:
|
||||
sys.stdin.read(1)
|
||||
|
||||
# Call the function to wait for any key press
|
||||
wait_for_key_press()
|
||||
|
||||
with open('/dev/tty1', 'w') as tty:
|
||||
tty.write("\033[0;0H")
|
||||
tty.write("\033[?5h\033[?5l")
|
||||
tty.write("\033[?25h")
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import math
|
||||
|
||||
# Screen dimensions
|
||||
screen_width_pixels = 1440
|
||||
screen_height_pixels = 900
|
||||
screen_diagonal_inches = 19
|
||||
|
||||
# Calculate the aspect ratio dimensions
|
||||
aspect_ratio = 8 / 5
|
||||
height_inches = math.sqrt((screen_diagonal_inches**2) / (1 + aspect_ratio**2))
|
||||
width_inches = aspect_ratio * height_inches
|
||||
|
||||
# Calculate PPI (Pixels Per Inch)
|
||||
ppi_width = screen_width_pixels / width_inches
|
||||
ppi_height = screen_height_pixels / height_inches
|
||||
ppi = (ppi_width + ppi_height) / 2 # Average the PPI
|
||||
|
||||
# Convert PPI to PPCM (Pixels Per Centimeter)
|
||||
ppcm = ppi / 2.54
|
||||
|
||||
# Determine the pixel size for 1 cm tall characters
|
||||
font_pixel_height = int(ppcm * 1) # 1 cm
|
||||
|
||||
# Output the calculated font size in pixels
|
||||
print(f"The font size for 1 cm tall characters should be approximately {font_pixel_height} pixels.")
|
||||
@@ -0,0 +1,17 @@
|
||||
import fcntl
|
||||
import struct
|
||||
|
||||
|
||||
FBIOGET_VSCREENINFO = 0x4600
|
||||
|
||||
|
||||
with open('/dev/fb0', 'r+b') as fb:
|
||||
fb_var_screeninfo = '12sL9I'
|
||||
var_info = fcntl.ioctl(fb, FBIOGET_VSCREENINFO, struct.pack(fb_var_screeninfo, b'', 0, *[0]*9))
|
||||
|
||||
xres, yres, xres_virtual, yres_virtual, xoffset, yoffset, bits_per_pixel = struct.unpack('7I', var_info[:28])
|
||||
print(xres)
|
||||
print(yres)
|
||||
print(bits_per_pixel)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user