This commit is contained in:
2026-07-09 14:15:38 +03:00
commit 8127789b08
8 changed files with 368 additions and 0 deletions
+72
View File
@@ -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")