Add christmas edition
This commit is contained in:
parent
2f1c7d9e82
commit
b62af486a7
74 changed files with 3422 additions and 1 deletions
121
christmas/text_generator/main.py
Normal file
121
christmas/text_generator/main.py
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
import io
|
||||
import os
|
||||
import zipfile
|
||||
from math import ceil
|
||||
from sys import argv
|
||||
from typing import Tuple
|
||||
|
||||
from PIL import Image
|
||||
|
||||
c_header = """#include "texts.h"
|
||||
|
||||
#include <avr/eeprom.h>
|
||||
|
||||
|
||||
// AUTO-GENERATED
|
||||
|
||||
"""
|
||||
|
||||
h_header = """#ifndef TEXTS_H
|
||||
#define TEXTS_H
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
|
||||
// AUTO-GENERATED
|
||||
|
||||
"""
|
||||
|
||||
h_footer = """
|
||||
#endif
|
||||
"""
|
||||
|
||||
letters = [
|
||||
"a",
|
||||
"á",
|
||||
"b",
|
||||
"c",
|
||||
"d",
|
||||
"e",
|
||||
"é",
|
||||
"f",
|
||||
"g",
|
||||
"h",
|
||||
"i",
|
||||
"í",
|
||||
"j",
|
||||
"k",
|
||||
"l",
|
||||
"m",
|
||||
"n",
|
||||
"o",
|
||||
"ó",
|
||||
"ö",
|
||||
"ő",
|
||||
"p",
|
||||
"q",
|
||||
"r",
|
||||
"s",
|
||||
"t",
|
||||
"u",
|
||||
"ú",
|
||||
"ü",
|
||||
"ű",
|
||||
"v",
|
||||
"w",
|
||||
"x",
|
||||
"y",
|
||||
"z",
|
||||
"0",
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
"6",
|
||||
"7",
|
||||
"8",
|
||||
"9",
|
||||
",",
|
||||
".",
|
||||
"!",
|
||||
"?",
|
||||
" ",
|
||||
]
|
||||
|
||||
|
||||
def generate(input_text: str) -> Tuple[str, str]:
|
||||
indices = []
|
||||
for line in input_text.split("\n"):
|
||||
for char in line.strip().lower().replace(", ", ","):
|
||||
indices.append(letters.index(char))
|
||||
indices.append(255)
|
||||
indices.append(255)
|
||||
|
||||
if len(indices) > 512:
|
||||
print(f"Input is too long ({len(indices)} > 512)")
|
||||
exit()
|
||||
|
||||
output_h = h_header + f"const uint8_t texts[{len(indices)}];\n" + h_footer
|
||||
output_c = c_header + f"const uint8_t texts[{len(indices)}] EEMEM = {{"
|
||||
|
||||
output_c += ", ".join(str(i) for i in indices)
|
||||
output_c += "};\n"
|
||||
|
||||
return output_h, output_c
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(argv) == 1:
|
||||
print("Specify an input file")
|
||||
exit()
|
||||
|
||||
with open(argv[1], "r", encoding="utf-8") as f:
|
||||
input_text = f.read()
|
||||
|
||||
dot_h, dot_c = generate(input_text)
|
||||
|
||||
with open("output/texts.h", "w+") as f:
|
||||
f.write(dot_h)
|
||||
with open("output/texts.c", "w+") as f:
|
||||
f.write(dot_c)
|
||||
Loading…
Add table
Add a link
Reference in a new issue