Read and write fps for oled.c

This commit is contained in:
Joe Scotto
2026-01-15 16:55:03 -05:00
parent 9ec2d8a246
commit de370b9e08
2 changed files with 24 additions and 14 deletions
@@ -6,14 +6,22 @@ with open("frames.txt", "r") as f:
frames = []
current_frame = []
fps = None # will store the FPS extracted from the first frame comment
for line in data.splitlines():
line = line.strip()
# Skip empty lines
if not line.strip():
if not line:
continue
# If line is a frame comment, start a new frame
if line.strip().startswith("// 'out_"):
match = re.match(r"// '(\d+)fps_", line)
if match:
# Extract FPS from the first frame comment
if fps is None:
fps = int(match.group(1))
if current_frame:
frames.append(current_frame)
current_frame = []
@@ -30,21 +38,21 @@ if current_frame:
num_frames = len(frames)
frame_size = len(frames[0])
# Calculate FRAME_DELAY in ms
if fps:
frame_delay = int(round(1000 / fps)) # milliseconds per frame
else:
frame_delay = 67 # default to ~15 fps if no fps found
# ----------------------------
# Write frames.c
# ----------------------------
with open("frames.c", "w") as f:
f.write("#include <stdint.h>\n")
f.write("#ifdef AVR\n#include <avr/pgmspace.h>\n#else\n#define PROGMEM\n#endif\n\n")
f.write(
"const uint8_t PROGMEM frames[{}][{}] = {{\n".format(num_frames, frame_size)
)
f.write(f"const uint8_t PROGMEM frames[{num_frames}][{frame_size}] = {{\n")
for f_idx, frame in enumerate(frames):
f.write(" {")
f.write(", ".join(frame))
f.write("}}, // frame {}\n".format(f_idx + 1))
f.write(f"}}, // frame {f_idx + 1}\n")
f.write("};\n")
print(f"Export complete: frames.c with {num_frames} frames.")
@@ -65,7 +73,7 @@ oled_rotation_t oled_init_user(oled_rotation_t rotation) {{
#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
#define FRAME_DELAY {frame_delay} // ms per frame, ~{fps} fps
bool oled_task_user(void) {{
static uint16_t frame_index = 0;
@@ -91,4 +99,6 @@ bool oled_task_user(void) {{
with open("oled.c", "w") as f:
f.write(oled_c_content)
print(f"Export complete: oled.c with NUM_FRAMES = {num_frames}")
print(
f"Export complete: oled.c with NUM_FRAMES = {num_frames} and FRAME_DELAY = {frame_delay}ms (~{fps} fps)"
)
@@ -44,8 +44,8 @@ if os.path.exists(output_dir):
shutil.rmtree(output_dir)
os.makedirs(output_dir)
# Create ffmpeg command
output_pattern = os.path.join(output_dir, "out_%03d.png")
# Create ffmpeg command with FPS in filename
output_pattern = os.path.join(output_dir, f"{int(args.fps)}fps_%03d.png")
# setpts expression: PTS = 1/speed * PTS
setpts_expr = f"setpts={1/args.speed}*PTS"