summaryrefslogtreecommitdiffstats
path: root/movement
diff options
context:
space:
mode:
authorDavid Keck <davidskeck@fastmail.com>2022-01-26 18:59:48 -0500
committerDavid Keck <davidskeck@fastmail.com>2022-01-26 18:59:48 -0500
commit23610430b31bce8e147080d9a9d660b98e28b418 (patch)
treeec0b0e47280d885a8c8b2540174d07dee101f5f6 /movement
parent725f17bfb60e402dc0efc2e58cdcfc592ed5ff45 (diff)
downloadSensor-Watch-23610430b31bce8e147080d9a9d660b98e28b418.tar.gz
Sensor-Watch-23610430b31bce8e147080d9a9d660b98e28b418.tar.bz2
Sensor-Watch-23610430b31bce8e147080d9a9d660b98e28b418.zip
Added rough draft of watch_face script to generate custom watch faces from template. Corrected template file's missing includes and incorrect memset placeholder.
Diffstat (limited to 'movement')
-rw-r--r--movement/template/template.c4
-rw-r--r--movement/template/watch_face.py73
2 files changed, 76 insertions, 1 deletions
diff --git a/movement/template/template.c b/movement/template/template.c
index 3f60be97..34c6dbf5 100644
--- a/movement/template/template.c
+++ b/movement/template/template.c
@@ -22,13 +22,15 @@
* SOFTWARE.
*/
+#include <stdlib.h>
+#include <string.h>
#include "<#watch_face_name#>_face.h"
void <#watch_face_name#>_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
(void) settings;
if (*context_ptr == NULL) {
*context_ptr = malloc(sizeof(<#watch_face_name#>_state_t));
- memset(*context_ptr, 0, sizeof(<#watch_face_name#>));
+ memset(*context_ptr, 0, sizeof(<#watch_face_name#>_state_t));
// Do any one-time tasks in here; the inside of this conditional happens only at boot.
}
// Do any pin or peripheral setup here; this will be called whenever the watch wakes from deep sleep.
diff --git a/movement/template/watch_face.py b/movement/template/watch_face.py
new file mode 100644
index 00000000..673e1f19
--- /dev/null
+++ b/movement/template/watch_face.py
@@ -0,0 +1,73 @@
+import os
+import re
+import argparse
+
+
+MAKEFILE_INDICATOR = "# New watch faces go above this line.\n"
+INCLUDE_INDICATOR = "// New includes go above this line.\n"
+
+
+def replace_placeholders(contents, args):
+ modified_contents = contents.replace("<#WATCH_FACE_NAME#>", args.watch_face_name.upper())
+ modified_contents = modified_contents.replace("<#watch_face_name#>", args.watch_face_name)
+ if args.author_name:
+ modified_contents = modified_contents.replace("<#author_name#>", " ".join(args.author_name))
+ if args.year:
+ modified_contents = modified_contents.replace("<#year#>", args.year)
+
+ return modified_contents
+
+
+def write_output_file(args, file_type, output_dir):
+ with open(f"template.{file_type}", 'r') as file_template:
+ file_contents = file_template.read()
+ modified_template = replace_placeholders(file_contents, args)
+ file_path = f"{output_dir}{args.watch_face_name}_face.{file_type}"
+ if not os.path.exists(file_path):
+ with open(file_path, 'w') as output_file:
+ output_file.write(modified_template)
+ else:
+ print(f"Generation failed: the watch face \"{args.watch_face_name}\" already exists at {file_path}. Unable to generate new files. Exiting...")
+ exit(0)
+
+
+def write_include_file(file_path, file_type, indicator_line, line_to_insert):
+ with open(file_path, 'r+') as include_file:
+ include_contents = include_file.readlines()
+ if line_to_insert in include_contents:
+ print(f"Generation failed: {file_path} already has an entry for {line_to_insert.strip()}. Unable to generate new files. Exiting...")
+ exit(0)
+ new_face_index = include_contents.index(indicator_line)
+ include_contents.insert(new_face_index, line_to_insert)
+ include_file.seek(0)
+ include_file.writelines(include_contents)
+
+
+def main():
+ parser = argparse.ArgumentParser(description="Create a new watch face.")
+ parser.add_argument("watch_face_type", metavar="face_type", type=str, choices=["complication", "clock"], help="The type of watch face to create, either \"complication\" or \"clock\"")
+ parser.add_argument("watch_face_name", metavar="face_name", type=str, help="The name of the watch face")
+ parser.add_argument("--author_name", metavar="author_name", type=str, nargs='*', help="The name of the author")
+ parser.add_argument("--year", metavar="year", type=str, help="The copyright year")
+
+ args = parser.parse_args()
+
+ name_valid = re.fullmatch(r'[a-zA-Z_][a-zA-Z0-9_]*', args.watch_face_name)
+ if name_valid == None:
+ print(f"Generation failed: {args.watch_face_name} is not a valid C variable name. Exiting...")
+ exit(0)
+
+ line_to_insert = f"#include \"{args.watch_face_name}_face.h\"\n"
+ write_include_file(f"..{os.sep}movement_faces.h", "h", INCLUDE_INDICATOR, line_to_insert)
+
+ line_to_insert = f" ..{os.sep}watch_faces{os.sep}{args.watch_face_type}{os.sep}{args.watch_face_name}_face.c \\\n"
+ write_include_file(f"..{os.sep}make{os.sep}Makefile", "c", MAKEFILE_INDICATOR, line_to_insert)
+
+ output_dir = f"..{os.sep}watch_faces{os.sep}{args.watch_face_type}{os.sep}"
+ write_output_file(args, "h", output_dir)
+ write_output_file(args, "c", output_dir)
+
+
+if __name__ == "__main__":
+ main()
+
"n">address + pdb_linux_syscall_enter_bkpt_offset); pdb_system_call = 1; } void pdb_linux_syscall_exit_bkpt (struct xen_regs *regs, struct pdb_context *pdb_ctx) { /* we've hit an int 0x80 in a user's program, jumped into xen (traps.c::do_general_protection()) which re-wrote the next instruction in the os kernel to 0xcc, and then hit that exception. we need to re-write the return instruction in the user's program so that we know when we have finished the system call and are back in the user's program. at this point our stack should look something like this: esp = 0x80a59f0 esp + 4 = 0x0 esp + 8 = 0x80485a0 esp + 12 = 0x2d esp + 16 = 0x80485f4 esp + 20 = 0xbffffa48 esp + 24 = 0xd esp + 28 = 0xc00a0833 esp + 32 = 0x833 esp + 36 = 0xd esp + 40 = 0x804dcdd saved eip esp + 44 = 0x82b saved cs esp + 48 = 0x213392 saved eflags esp + 52 = 0xbffffa2c saved esp esp + 56 = 0x833 saved ss esp + 60 = 0x1000000 */ /* restore the entry instruction for the system call */ pdb_linux_clr_bkpt(regs->eip - 1, pdb_system_call_enter_instr); /* save the address of eflags that was saved on the stack */ pdb_system_call_eflags_addr = (regs->esp + pdb_linux_syscall_eflags_offset); /* muck with the return instruction so that we trap back into the debugger when re-entering user space */ pdb_system_call_next_addr = *(unsigned long *)(regs->esp + pdb_linux_syscall_eip_offset); pdb_linux_get_values (&pdb_system_call_leave_instr, 1, pdb_system_call_next_addr, pdb_ctx->process, pdb_ctx->ptbr); pdb_linux_set_values ("cc", 1, pdb_system_call_next_addr, pdb_ctx->process, pdb_ctx->ptbr); }