From 9ec2d8a246342a8165fcbd647a366fa89e0aa89c Mon Sep 17 00:00:00 2001 From: Joe Scotto Date: Thu, 15 Jan 2026 16:29:01 -0500 Subject: [PATCH] Update scripts --- .../OLED Video/create_frames_array.py | 59 +++++++++++++++++-- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/Extras/ScottoScripts/OLED Video/create_frames_array.py b/Extras/ScottoScripts/OLED Video/create_frames_array.py index 77b15a3..db80023 100644 --- a/Extras/ScottoScripts/OLED Video/create_frames_array.py +++ b/Extras/ScottoScripts/OLED Video/create_frames_array.py @@ -27,12 +27,17 @@ for line in data.splitlines(): if current_frame: frames.append(current_frame) -# Write formatted array to frames.c and overwrite on subsequent runs +num_frames = len(frames) +frame_size = len(frames[0]) + +# ---------------------------- +# Write frames.c +# ---------------------------- with open("frames.c", "w") as f: + f.write("#include \n") + f.write("#ifdef AVR\n#include \n#else\n#define PROGMEM\n#endif\n\n") f.write( - "const uint8_t PROGMEM frames[{}][{}] = {{\n".format( - len(frames), len(frames[0]) - ) + "const uint8_t PROGMEM frames[{}][{}] = {{\n".format(num_frames, frame_size) ) for f_idx, frame in enumerate(frames): @@ -42,4 +47,48 @@ with open("frames.c", "w") as f: f.write("};\n") -print("Export complete: frames.c with {} frames.".format(len(frames))) +print(f"Export complete: frames.c with {num_frames} frames.") + +# ---------------------------- +# Write oled.c +# ---------------------------- +oled_c_content = f"""#include "frames.c" +#include "quantum.h" + +#ifdef OLED_ENABLE + +oled_rotation_t oled_init_user(oled_rotation_t rotation) {{ + return OLED_ROTATION_180; // flips the display 180 degrees if offhand +}} + +#define NUM_FRAMES {num_frames} +#define FRAME_WIDTH {frame_size * 8 // 64} // Approximation; adjust as needed +#define FRAME_HEIGHT {64} // Adjust if necessary +#define FRAME_SIZE (FRAME_WIDTH * FRAME_HEIGHT / 8) // bytes per frame +#define FRAME_DELAY 100 // ms per frame, ~10 fps + +bool oled_task_user(void) {{ + static uint16_t frame_index = 0; + static uint32_t last_update = 0; + + if (timer_elapsed32(last_update) > FRAME_DELAY) {{ + last_update = timer_read32(); + + // Write current frame to OLED (cast to const char* to fix signedness) + oled_write_raw_P((const char *)frames[frame_index], FRAME_SIZE); + + frame_index++; + if (frame_index >= NUM_FRAMES) + frame_index = 0; + }} + + return false; // keep other OLED content disabled +}} + +#endif +""" + +with open("oled.c", "w") as f: + f.write(oled_c_content) + +print(f"Export complete: oled.c with NUM_FRAMES = {num_frames}")