added comments + minor changes

This commit is contained in:
Louis Heredero 2023-07-11 15:46:42 +02:00
parent ec5c21552a
commit 635bb8c16e

View File

@ -10,6 +10,9 @@ import os
import re
import time
def ucfirst(s):
return s[0].upper() + s[1:]
def get_input(title, default=None, non_null=False):
"""Prompts user for an input
@ -92,6 +95,7 @@ def main():
locale.setlocale(locale.LC_TIME, "en_GB.utf8")
dir_ = os.path.dirname(__file__)
# Load config if it exists
conf_path = os.path.join(dir_, "config.json")
if os.path.exists(conf_path):
with open(conf_path, "r") as f:
@ -127,7 +131,7 @@ def main():
states_cases = []
for i, state in enumerate(states):
for state in states:
case_ = f"case {state}:\n"
case_ += " break;"
states_cases.append(case_)
@ -155,7 +159,7 @@ def main():
events_enum[0] += " // TODO change this number (< 256)"
variables["EVENTS_ENUM"] = "\n".join(events_enum)
events_emits = []
events_emits_def = []
emit_def = ""
emit_def += "void {filename}_emit{Event}({filename}* me, uint16_t t) {\n"
@ -164,13 +168,13 @@ def main():
emit_def = emit_def.replace("{filename}", variables["filename"]).replace("{fn}", variables["fn"])
for event in events[1:]:
events_emits.append(
events_emits_def.append(
emit_def.replace("{event}", event).replace("{Event}", event.capitalize())
)
variables["EVENTS_EMITS_DEF"] = "\n\n".join(events_emits)
variables["EVENTS_EMITS_DEF"] = "\n\n".join(events_emits_def)
events_emits = []
events_emits_dec = []
emit_dec = ""
emit_dec += "/**\n"
emit_dec += " * Emit the {event} event\n"
@ -181,11 +185,15 @@ def main():
emit_dec = emit_dec.replace("{filename}", variables["filename"])
for event in events[1:]:
events_emits.append(
events_emits_dec.append(
emit_dec.replace("{event}", event).replace("{Event}", event.capitalize())
)
variables["EVENTS_EMITS_DEC"] = "\n\n".join(events_emits)
variables["EVENTS_EMITS_DEC"] = "\n\n".join(events_emits_dec)
##################
# Fill templates #
##################
file_c = fill_template(dir_, variables, "file.c")
file_h = fill_template(dir_, variables, "file.h")
@ -193,6 +201,7 @@ def main():
output_file(dir_, variables["filename_lc"]+".c", file_c)
output_file(dir_, variables["filename_lc"]+".h", file_h)
# Save config
with open(conf_path, "w") as f:
conf = {
"author": variables["author"]