From 9d8ef5c2e8a0aa0b9c27034a1dde0051a385220a Mon Sep 17 00:00:00 2001 From: George Hahn Date: Fri, 29 Apr 2022 22:55:36 -0600 Subject: Parallelize builds --- movement/make/make_alternate_fw.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/movement/make/make_alternate_fw.sh b/movement/make/make_alternate_fw.sh index 575c9e52..bd8154ef 100755 --- a/movement/make/make_alternate_fw.sh +++ b/movement/make/make_alternate_fw.sh @@ -22,11 +22,11 @@ do do COLOR=$(echo "$color" | tr '[:lower:]' '[:upper:]') make clean - make LED=$COLOR FIRMWARE=$VARIANT + make LED=$COLOR FIRMWARE=$VARIANT -j `nproc` mv "build/watch.uf2" "$fw_dir/$variant-$color.uf2" done make clean - emmake make FIRMWARE=$VARIANT + emmake make FIRMWARE=$VARIANT -j `nproc` mkdir "$sim_dir/$variant/" mv "build/watch.wasm" "$sim_dir/$variant/" mv "build/watch.js" "$sim_dir/$variant/" -- cgit v1.2.3 From 0269681ac323bf09f130132454258d279c92f89f Mon Sep 17 00:00:00 2001 From: George Hahn Date: Tue, 10 May 2022 00:37:02 -0600 Subject: Perform OS detection in makefile --- make.mk | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/make.mk b/make.mk index ac5be775..d7fecd20 100644 --- a/make.mk +++ b/make.mk @@ -9,7 +9,21 @@ endif ############################################################################## .PHONY: all directory clean size -ifeq ($(OS), Windows_NT) +# OS detection, adapted from https://gist.github.com/sighingnow/deee806603ec9274fd47 +DETECTED_OS := +ifeq ($(OS),Windows_NT) + DETECTED_OS = WINDOWS +else + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + DETECTED_OS = LINUX + endif + ifeq ($(UNAME_S),Darwin) + DETECTED_OS = OSX + endif +endif +$(if ${VERBOSE},$(info OS detected: $(DETECTED_OS))) + MKDIR = gmkdir else MKDIR = mkdir -- cgit v1.2.3 From 0ab63691f20eafe5544787b7c7d867925bae4eb8 Mon Sep 17 00:00:00 2001 From: George Hahn Date: Tue, 10 May 2022 00:37:37 -0600 Subject: Move parallel flag into makefile with crossplatform support --- make.mk | 11 +++++++++++ movement/make/make_alternate_fw.sh | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/make.mk b/make.mk index d7fecd20..3424f9c9 100644 --- a/make.mk +++ b/make.mk @@ -29,6 +29,17 @@ else MKDIR = mkdir endif +ifeq ($(DETECTED_OS), LINUX) + MAKEFLAGS += -j `nproc` +endif +ifeq ($(DETECTED_OS), OSX) + NPROCS = $(shell sysctl hw.ncpu | grep -o '[0-9]\+') + MAKEFLAGS += -j $(NPROCS) +endif +ifeq ($(DETECTED_OS), WINDOWS) + MAKEFLAGS += -j $(NUMBER_OF_PROCESSORS) +endif + ifndef EMSCRIPTEN CC = arm-none-eabi-gcc OBJCOPY = arm-none-eabi-objcopy diff --git a/movement/make/make_alternate_fw.sh b/movement/make/make_alternate_fw.sh index bd8154ef..575c9e52 100755 --- a/movement/make/make_alternate_fw.sh +++ b/movement/make/make_alternate_fw.sh @@ -22,11 +22,11 @@ do do COLOR=$(echo "$color" | tr '[:lower:]' '[:upper:]') make clean - make LED=$COLOR FIRMWARE=$VARIANT -j `nproc` + make LED=$COLOR FIRMWARE=$VARIANT mv "build/watch.uf2" "$fw_dir/$variant-$color.uf2" done make clean - emmake make FIRMWARE=$VARIANT -j `nproc` + emmake make FIRMWARE=$VARIANT mkdir "$sim_dir/$variant/" mv "build/watch.wasm" "$sim_dir/$variant/" mv "build/watch.js" "$sim_dir/$variant/" -- cgit v1.2.3 From 190dca0a777a8961460faaf993c9e34f921a9a1a Mon Sep 17 00:00:00 2001 From: George Hahn Date: Tue, 10 May 2022 00:42:43 -0600 Subject: fixup: restore deleted line --- make.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/make.mk b/make.mk index 3424f9c9..d8e2bf8a 100644 --- a/make.mk +++ b/make.mk @@ -24,6 +24,7 @@ else endif $(if ${VERBOSE},$(info OS detected: $(DETECTED_OS))) +ifeq ($(OS), Windows_NT) MKDIR = gmkdir else MKDIR = mkdir -- cgit v1.2.3 From 96aaa47c8ec3c25d1ae2d4ee292ef5b83c8423fc Mon Sep 17 00:00:00 2001 From: Spencer Bywater Date: Wed, 18 May 2022 08:11:34 -0700 Subject: Probability watch face (#69) * Initial work on probability watch face * Complete probability watch face * Restore default movement_config * PR feedback: PR watch face title, use arc4random, clean up warnings * Use rand instead of arc4random when building on emulator * Accidentally overwrote movement_config --- movement/make/Makefile | 1 + movement/movement_faces.h | 1 + .../watch_faces/complication/probability_face.c | 182 +++++++++++++++++++++ .../watch_faces/complication/probability_face.h | 51 ++++++ 4 files changed, 235 insertions(+) create mode 100644 movement/watch_faces/complication/probability_face.c create mode 100644 movement/watch_faces/complication/probability_face.h diff --git a/movement/make/Makefile b/movement/make/Makefile index 0936a26c..7c7cf2d6 100755 --- a/movement/make/Makefile +++ b/movement/make/Makefile @@ -61,6 +61,7 @@ SRCS += \ ../watch_faces/complication/orrery_face.c \ ../watch_faces/complication/astronomy_face.c \ ../watch_faces/complication/tomato_face.c \ + ../watch_faces/complication/probability_face.c \ # New watch faces go above this line. # Leave this line at the bottom of the file; it has all the targets for making your project. diff --git a/movement/movement_faces.h b/movement/movement_faces.h index e7e78ff4..7c51b6ff 100644 --- a/movement/movement_faces.h +++ b/movement/movement_faces.h @@ -52,6 +52,7 @@ #include "orrery_face.h" #include "astronomy_face.h" #include "tomato_face.h" +#include "probability_face.h" // New includes go above this line. #endif // MOVEMENT_FACES_H_ diff --git a/movement/watch_faces/complication/probability_face.c b/movement/watch_faces/complication/probability_face.c new file mode 100644 index 00000000..db193fb1 --- /dev/null +++ b/movement/watch_faces/complication/probability_face.c @@ -0,0 +1,182 @@ +/* + * MIT License + * + * Copyright (c) 2022 Spencer Bywater + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// Emulator only: need time() to seed the random number generator. +#if __EMSCRIPTEN__ +#include +#endif + +#include +#include +#include "probability_face.h" + +#define DEFAULT_DICE_SIDES 2 +#define PROBABILITY_ANIMATION_TICK_FREQUENCY 8 +const uint16_t NUM_DICE_TYPES = 8; // Keep this consistent with # of dice types below +const uint16_t DICE_TYPES[] = {2, 4, 6, 8, 10, 12, 20, 100}; + + +// -------------- +// Custom methods +// -------------- + +static void display_dice_roll(probability_state_t *state) { + char buf[8]; + if (state->rolled_value == 0) { + if (state->dice_sides == 100) { + sprintf(buf, " C "); + } else { + sprintf(buf, "%2d ", state->dice_sides); + } + } else if (state->dice_sides == 2) { + if (state->rolled_value == 1) { + sprintf(buf, "%2d H", state->dice_sides); + } else { + sprintf(buf, "%2d T", state->dice_sides); + } + } else if (state->dice_sides == 100) { + sprintf(buf, " C %3d", state->rolled_value); + } else { + sprintf(buf, "%2d %3d", state->dice_sides, state->rolled_value); + } + watch_display_string(buf, 4); +} + +static void generate_random_number(probability_state_t *state) { + // Emulator: use rand. Hardware: use arc4random. + #if __EMSCRIPTEN__ + state->rolled_value = rand() % state->dice_sides + 1; + #else + state->rolled_value = arc4random_uniform(state->dice_sides) + 1; + #endif +} + +static void display_dice_roll_animation(probability_state_t *state) { + if (state->is_rolling) { + if (state->animation_frame == 0) { + watch_display_string(" ", 7); + watch_set_pixel(1, 4); + watch_set_pixel(1, 6); + state->animation_frame = 1; + } else if (state->animation_frame == 1) { + watch_clear_pixel(1, 4); + watch_clear_pixel(1, 6); + watch_set_pixel(2, 4); + watch_set_pixel(0, 6); + state->animation_frame = 2; + } else if (state->animation_frame == 2) { + watch_clear_pixel(2, 4); + watch_clear_pixel(0, 6); + watch_set_pixel(2, 5); + watch_set_pixel(0, 5); + state->animation_frame = 3; + } else if (state->animation_frame == 3) { + state->animation_frame = 0; + state->is_rolling = false; + movement_request_tick_frequency(1); + display_dice_roll(state); + } + } +} + + +// --------------------------- +// Standard watch face methods +// --------------------------- +void probability_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { + (void) settings; + (void) watch_face_index; + if (*context_ptr == NULL) { + *context_ptr = malloc(sizeof(probability_state_t)); + memset(*context_ptr, 0, sizeof(probability_state_t)); + } + // Emulator only: Seed random number generator + #if __EMSCRIPTEN__ + srand(time(NULL)); + #endif +} + +void probability_face_activate(movement_settings_t *settings, void *context) { + (void) settings; + probability_state_t *state = (probability_state_t *)context; + + state->dice_sides = DEFAULT_DICE_SIDES; + state->rolled_value = 0; + watch_display_string("PR", 0); +} + +bool probability_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { + (void) settings; + probability_state_t *state = (probability_state_t *)context; + + if (state->is_rolling && event.event_type != EVENT_TICK) { + return true; + } + + switch (event.event_type) { + case EVENT_ACTIVATE: + display_dice_roll(state); + break; + case EVENT_TICK: + display_dice_roll_animation(state); + break; + case EVENT_MODE_BUTTON_UP: + movement_move_to_next_face(); + break; + case EVENT_LIGHT_BUTTON_UP: + // Change how many sides the die has + for (int i = 0; i < NUM_DICE_TYPES; i++) { + if (DICE_TYPES[i] == state->dice_sides) { + if (i == NUM_DICE_TYPES - 1) { + state->dice_sides = DICE_TYPES[0]; + } else { + state->dice_sides = DICE_TYPES[i + 1]; + } + break; + } + } + state->rolled_value = 0; + display_dice_roll(state); + break; + case EVENT_ALARM_BUTTON_UP: + // Roll the die + generate_random_number(state); + state->is_rolling = true; + // Dice rolling animation begins on next tick and new roll will be displayed on completion + movement_request_tick_frequency(PROBABILITY_ANIMATION_TICK_FREQUENCY); + break; + case EVENT_TIMEOUT: + movement_move_to_face(0); + break; + default: + break; + } + + return true; +} + +void probability_face_resign(movement_settings_t *settings, void *context) { + (void) settings; + (void) context; +} diff --git a/movement/watch_faces/complication/probability_face.h b/movement/watch_faces/complication/probability_face.h new file mode 100644 index 00000000..c6d3638f --- /dev/null +++ b/movement/watch_faces/complication/probability_face.h @@ -0,0 +1,51 @@ +/* + * MIT License + * + * Copyright (c) 2022 Spencer Bywater + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef PROBABILITY_FACE_H_ +#define PROBABILITY_FACE_H_ + +#include "movement.h" + +typedef struct { + uint8_t dice_sides; + uint8_t rolled_value; + uint8_t animation_frame; + bool is_rolling; +} probability_state_t; + +void probability_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr); +void probability_face_activate(movement_settings_t *settings, void *context); +bool probability_face_loop(movement_event_t event, movement_settings_t *settings, void *context); +void probability_face_resign(movement_settings_t *settings, void *context); + +#define probability_face ((const watch_face_t){ \ + probability_face_setup, \ + probability_face_activate, \ + probability_face_loop, \ + probability_face_resign, \ + NULL, \ +}) + +#endif // PROBABILITY_FACE_H_ + -- cgit v1.2.3 From 1f6f11eb602c7f4fa2b9849de0c55cc6e45e9053 Mon Sep 17 00:00:00 2001 From: George Hahn Date: Wed, 18 May 2022 09:17:51 -0600 Subject: Add Devcontainer as an easy dev environment option (#65) --- .devcontainer/Dockerfile | 50 +++++++++++++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 17 ++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..55565a07 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,50 @@ +FROM ubuntu:22.10 + +# TODO: install emscripten (https://emscripten.org/docs/getting_started/downloads.html) + +# TODO: Clean this up once buildkit is supported gracefully in devcontainers +# https://github.com/microsoft/vscode-remote-release/issues/1409 + +ARG X86_64_TOOLCHAIN_FILENAME="gcc-arm-none-eabi-10.3-2021.07-x86_64-linux.tar.bz2" +ARG X86_64_TOOLCHAIN="https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.07/gcc-arm-none-eabi-10.3-2021.07-x86_64-linux.tar.bz2" +ARG X86_64_TOOLCHAIN_CHECKSUM="b56ae639d9183c340f065ae114a30202" + +ARG AARCH64_TOOLCHAIN_FILENAME="gcc-arm-none-eabi-10.3-2021.07-aarch64-linux.tar.bz2" +ARG AARCH64_TOOLCHAIN="https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.07/gcc-arm-none-eabi-10.3-2021.07-aarch64-linux.tar.bz2" +ARG AARCH64_TOOLCHAIN_CHECKSUM="c20b0535d01f8d4418341d893c62a782" + +WORKDIR /setup + +# Install required packages +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + # make is used as the build system + make \ + # git is used for fetching submodules & interactive development + git \ + # bzip2 is required to extract the Arm toolchain + bzip2 \ + # ca certs need to be available for fetching git submodules + ca-certificates \ + # python is used to convert binaries to uf2 files + python3 python-is-python3 + +# Download and verify both x86-64 and aarch64 toolchains. This is unfortunate and +# slows down the build, but it's a clean-ish option until buildkit can be used. +ADD $X86_64_TOOLCHAIN $X86_64_TOOLCHAIN_FILENAME +ADD $AARCH64_TOOLCHAIN $AARCH64_TOOLCHAIN_FILENAME + +RUN echo "${X86_64_TOOLCHAIN_CHECKSUM} ${X86_64_TOOLCHAIN_FILENAME}" | md5sum --check +RUN echo "${AARCH64_TOOLCHAIN_CHECKSUM} ${AARCH64_TOOLCHAIN_FILENAME}" | md5sum --check + +# Extract toolchain directly into /usr +RUN /bin/sh -c 'set -ex && \ + ARCH=`uname -m` && \ + if [ "$ARCH" = "x86_64" ]; then \ + tar --strip-components=1 -C /usr -xjf $X86_64_TOOLCHAIN_FILENAME ; \ + else \ + tar --strip-components=1 -C /usr -xjf $AARCH64_TOOLCHAIN_FILENAME ; \ + fi' + +RUN rm $X86_64_TOOLCHAIN_FILENAME +RUN rm $AARCH64_TOOLCHAIN_FILENAME \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..a71a0f22 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,17 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.231.6/containers/docker-existing-dockerfile +{ + "name": "GNU Arm Embedded Environment", + // Sets the run context to one level up instead of the .devcontainer folder. + "context": "..", + // Set the location of the dockerfile to use + "dockerFile": "Dockerfile", + // Set *default* container specific settings.json values on container create. + "settings": {}, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-vscode.cpptools" + ] + // Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root. + // "remoteUser": "vscode" +} \ No newline at end of file -- cgit v1.2.3 From c40d75b8765a2972bb6a80a7c6f56865b52063e4 Mon Sep 17 00:00:00 2001 From: George Hahn Date: Thu, 19 May 2022 00:33:31 -0600 Subject: Make submodule and directory rules order-only prerequisites on objects This instructs make to run the tinyusb and directory rules before building any objects. Docs: [1]. After this change, `make clean` started running the tinyusb submodule rule before cleaning. This appears to have been caused by one of the `build/*.d` files overlapping with the `tinyusb` name, triggering that rule. I didn't trace this all the way down to a root cause, but switching the include to something less broad solved the issue. Roughly guided by [2]. 1: https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html 2: http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ --- rules.mk | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rules.mk b/rules.mk index 2f2f3922..8de3fc1e 100644 --- a/rules.mk +++ b/rules.mk @@ -7,9 +7,9 @@ SUBMODULES = tinyusb COBRA = cobra -f ifndef EMSCRIPTEN -all: directory $(SUBMODULES) $(BUILD)/$(BIN).elf $(BUILD)/$(BIN).hex $(BUILD)/$(BIN).bin $(BUILD)/$(BIN).uf2 size +all: $(BUILD)/$(BIN).elf $(BUILD)/$(BIN).hex $(BUILD)/$(BIN).bin $(BUILD)/$(BIN).uf2 size else -all: directory $(SUBMODULES) $(BUILD)/$(BIN).html +all: $(BUILD)/$(BIN).html endif $(BUILD)/$(BIN).html: $(OBJS) @@ -35,13 +35,14 @@ $(BUILD)/$(BIN).uf2: $(BUILD)/$(BIN).bin @echo UF2CONV $@ @$(UF2) $^ -co $@ +.phony: $(SUBMODULES) $(SUBMODULES): git submodule update --init install: @$(UF2) -D $(BUILD)/$(BIN).uf2 -%.o: +$(BUILD)/%.o: | $(SUBMODULES) directory @echo CC $@ @$(CC) $(CFLAGS) $(filter %/$(subst .o,.c,$(notdir $@)), $(SRCS)) -c -o $@ @@ -59,4 +60,6 @@ clean: analyze: @$(COBRA) basic $(INCLUDES) $(DEFINES) $(SRCS) --include $(wildcard $(BUILD)/*.d) +DEPFILES := $(SRCS:%.c=$(BUILD)/%.d) + +-include $(wildcard $(DEPFILES)) -- cgit v1.2.3 From 6ed757af2b7778e6944a5a8761672bc8d03620e2 Mon Sep 17 00:00:00 2001 From: Spencer Bywater Date: Sun, 22 May 2022 16:42:37 -0700 Subject: Adjust probability watch face timeout/LE behavior (#72) Display SLEEP instead of timing out --- movement/watch_faces/complication/probability_face.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/movement/watch_faces/complication/probability_face.c b/movement/watch_faces/complication/probability_face.c index db193fb1..7b056b33 100644 --- a/movement/watch_faces/complication/probability_face.c +++ b/movement/watch_faces/complication/probability_face.c @@ -166,8 +166,8 @@ bool probability_face_loop(movement_event_t event, movement_settings_t *settings // Dice rolling animation begins on next tick and new roll will be displayed on completion movement_request_tick_frequency(PROBABILITY_ANIMATION_TICK_FREQUENCY); break; - case EVENT_TIMEOUT: - movement_move_to_face(0); + case EVENT_LOW_ENERGY_UPDATE: + watch_display_string("SLEEP ", 4); break; default: break; -- cgit v1.2.3 From a4fc6204ce27a4fcce071515ee9e5757818b4af5 Mon Sep 17 00:00:00 2001 From: George Hahn Date: Sun, 29 May 2022 20:30:02 -0600 Subject: Parallelize alternate fw builds (#66) --- make.mk | 26 ++++++++++++++++++++++++++ rules.mk | 11 +++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/make.mk b/make.mk index ac5be775..d8e2bf8a 100644 --- a/make.mk +++ b/make.mk @@ -9,12 +9,38 @@ endif ############################################################################## .PHONY: all directory clean size +# OS detection, adapted from https://gist.github.com/sighingnow/deee806603ec9274fd47 +DETECTED_OS := +ifeq ($(OS),Windows_NT) + DETECTED_OS = WINDOWS +else + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + DETECTED_OS = LINUX + endif + ifeq ($(UNAME_S),Darwin) + DETECTED_OS = OSX + endif +endif +$(if ${VERBOSE},$(info OS detected: $(DETECTED_OS))) + ifeq ($(OS), Windows_NT) MKDIR = gmkdir else MKDIR = mkdir endif +ifeq ($(DETECTED_OS), LINUX) + MAKEFLAGS += -j `nproc` +endif +ifeq ($(DETECTED_OS), OSX) + NPROCS = $(shell sysctl hw.ncpu | grep -o '[0-9]\+') + MAKEFLAGS += -j $(NPROCS) +endif +ifeq ($(DETECTED_OS), WINDOWS) + MAKEFLAGS += -j $(NUMBER_OF_PROCESSORS) +endif + ifndef EMSCRIPTEN CC = arm-none-eabi-gcc OBJCOPY = arm-none-eabi-objcopy diff --git a/rules.mk b/rules.mk index 2f2f3922..8de3fc1e 100644 --- a/rules.mk +++ b/rules.mk @@ -7,9 +7,9 @@ SUBMODULES = tinyusb COBRA = cobra -f ifndef EMSCRIPTEN -all: directory $(SUBMODULES) $(BUILD)/$(BIN).elf $(BUILD)/$(BIN).hex $(BUILD)/$(BIN).bin $(BUILD)/$(BIN).uf2 size +all: $(BUILD)/$(BIN).elf $(BUILD)/$(BIN).hex $(BUILD)/$(BIN).bin $(BUILD)/$(BIN).uf2 size else -all: directory $(SUBMODULES) $(BUILD)/$(BIN).html +all: $(BUILD)/$(BIN).html endif $(BUILD)/$(BIN).html: $(OBJS) @@ -35,13 +35,14 @@ $(BUILD)/$(BIN).uf2: $(BUILD)/$(BIN).bin @echo UF2CONV $@ @$(UF2) $^ -co $@ +.phony: $(SUBMODULES) $(SUBMODULES): git submodule update --init install: @$(UF2) -D $(BUILD)/$(BIN).uf2 -%.o: +$(BUILD)/%.o: | $(SUBMODULES) directory @echo CC $@ @$(CC) $(CFLAGS) $(filter %/$(subst .o,.c,$(notdir $@)), $(SRCS)) -c -o $@ @@ -59,4 +60,6 @@ clean: analyze: @$(COBRA) basic $(INCLUDES) $(DEFINES) $(SRCS) --include $(wildcard $(BUILD)/*.d) +DEPFILES := $(SRCS:%.c=$(BUILD)/%.d) + +-include $(wildcard $(DEPFILES)) -- cgit v1.2.3 From 5b650b9efeedd73c770149dd3fd6d92189c0a701 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Mon, 4 Jul 2022 11:23:09 -0500 Subject: reduce flicker of LED by default --- watch-library/hardware/watch/watch_private.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/watch-library/hardware/watch/watch_private.c b/watch-library/hardware/watch/watch_private.c index e4a03926..4b010d4a 100644 --- a/watch-library/hardware/watch/watch_private.c +++ b/watch-library/hardware/watch/watch_private.c @@ -142,7 +142,7 @@ void _watch_enable_tcc(void) { #endif // The buzzer will set the period depending on the tone it wants to play, but we have to set some period here to // get the LED working. Almost any period will do, tho it should be below 20000 (i.e. 50 Hz) to avoid flickering. - hri_tcc_write_PER_reg(TCC0, 4096); + hri_tcc_write_PER_reg(TCC0, 1024); // Set the duty cycle of all pins to 0: LED's off, buzzer not buzzing. hri_tcc_write_CC_reg(TCC0, WATCH_BUZZER_TCC_CHANNEL, 0); hri_tcc_write_CC_reg(TCC0, WATCH_RED_TCC_CHANNEL, 0); -- cgit v1.2.3 From 3c5114ba4c087f85ff500696519d309298675bb0 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Tue, 5 Jul 2022 22:51:30 -0500 Subject: WIP new tests --- apps/functional-test/app.c | 88 ++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 65 deletions(-) diff --git a/apps/functional-test/app.c b/apps/functional-test/app.c index b4ee0412..18599512 100644 --- a/apps/functional-test/app.c +++ b/apps/functional-test/app.c @@ -2,15 +2,6 @@ #include #include "watch.h" -bool even = false; -bool beep = false; -uint32_t i = 0; - -static void cb_tick(void) { - beep = true; - even = !even; -} - void app_init(void) { } @@ -22,30 +13,12 @@ void app_setup(void) { watch_enable_buzzer(); - watch_enable_digital_output(A0); - watch_enable_digital_output(SCL); - watch_enable_digital_output(SDA); - watch_enable_digital_output(A1); - watch_enable_digital_output(A2); - watch_enable_digital_output(A3); - watch_enable_digital_output(A4); - watch_enable_digital_input(BTN_ALARM); watch_enable_digital_input(BTN_LIGHT); watch_enable_digital_input(BTN_MODE); watch_enable_pull_down(BTN_ALARM); watch_enable_pull_down(BTN_LIGHT); watch_enable_pull_down(BTN_MODE); - - watch_set_pin_level(A0, false); - watch_set_pin_level(SCL, false); - watch_set_pin_level(SDA, false); - watch_set_pin_level(A1, false); - watch_set_pin_level(A2, false); - watch_set_pin_level(A3, false); - watch_set_pin_level(A4, false); - - watch_rtc_register_periodic_callback(cb_tick, 2); } void app_prepare_for_standby(void) { @@ -55,51 +28,36 @@ void app_wake_from_standby(void) { } bool app_loop(void) { - char buf[14]; + static int last_button = 0; + static int button = 0; + static int16_t loop = 0; - if (beep) watch_buzzer_play_note(BUZZER_NOTE_E5, 100); - - if (even) { - printf("Flashing even lights\n"); - #ifdef WATCH_SWAP_LED_PINS - sprintf(buf, "WT%2d'blu_E", (uint8_t)(i++ % 40)); - #else - sprintf(buf, "WT%2d'Grn_E", (uint8_t)(i++ % 40)); - #endif - watch_set_led_green(); - watch_set_pin_level(A0, true); - watch_set_pin_level(SCL, false); - watch_set_pin_level(SDA, true); - watch_set_pin_level(A1, false); - watch_set_pin_level(A2, true); - watch_set_pin_level(A3, false); - watch_set_pin_level(A4, true); - } else { - printf("Flashing odd lights\n"); - sprintf(buf, "WT%2d-red~O", (uint8_t)(i++ % 40)); - watch_display_string(buf, 0); - watch_set_led_red(); - watch_set_pin_level(A0, false); - watch_set_pin_level(SCL, true); - watch_set_pin_level(SDA, false); - watch_set_pin_level(A1, true); - watch_set_pin_level(A2, false); - watch_set_pin_level(A3, true); - watch_set_pin_level(A4, false); - } if (watch_get_pin_level(BTN_ALARM)) { - buf[2] = 'a'; - buf[3] = 'L'; + button = 1; } if (watch_get_pin_level(BTN_LIGHT)) { - buf[2] = '1'; - buf[3] = 'i'; + button = 2; } if (watch_get_pin_level(BTN_MODE)) { - buf[2] = '-'; - buf[3] = 'O'; + button = 3; + } + + if (button != last_button) { + last_button = button; + watch_buzzer_play_note(BUZZER_NOTE_C8, 50); + } + + for(int com = 0; com < 3; com++) { + for(int seg = 0; seg < 24; seg++) { + if (loop > 0) { + if (seg % 2 == 0) watch_set_pixel(com, seg); + else watch_set_pixel(com, seg); + } else { + if (seg % 2 == 1) watch_set_pixel(com, seg); + else watch_set_pixel(com, seg); + } + } } - watch_display_string(buf, 0); return true; } -- cgit v1.2.3 From 87da5f15ea314d53d97cee5f9fd13b4f83455256 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Tue, 5 Jul 2022 22:53:04 -0500 Subject: new tests --- apps/functional-test/app.c | 38 +++++++++++------- apps/sensor-board-test/app.c | 75 ++++++++++++++++++++++++++++++++++++ apps/sensor-board-test/make/Makefile | 10 +++++ 3 files changed, 109 insertions(+), 14 deletions(-) create mode 100644 apps/sensor-board-test/app.c create mode 100755 apps/sensor-board-test/make/Makefile diff --git a/apps/functional-test/app.c b/apps/functional-test/app.c index 18599512..179bea8b 100644 --- a/apps/functional-test/app.c +++ b/apps/functional-test/app.c @@ -13,6 +13,8 @@ void app_setup(void) { watch_enable_buzzer(); + watch_enable_digital_output(RED); + watch_enable_digital_output(GREEN); watch_enable_digital_input(BTN_ALARM); watch_enable_digital_input(BTN_LIGHT); watch_enable_digital_input(BTN_MODE); @@ -30,34 +32,42 @@ void app_wake_from_standby(void) { bool app_loop(void) { static int last_button = 0; static int button = 0; - static int16_t loop = 0; + static int8_t loop = 0; + watch_set_pin_level(GREEN, false); + watch_set_pin_level(RED, false); if (watch_get_pin_level(BTN_ALARM)) { + watch_set_pin_level(GREEN, true); button = 1; - } - if (watch_get_pin_level(BTN_LIGHT)) { + } else if (watch_get_pin_level(BTN_LIGHT)) { + watch_set_pin_level(RED, true); button = 2; - } - if (watch_get_pin_level(BTN_MODE)) { + } else if (watch_get_pin_level(BTN_MODE)) { + watch_set_pin_level(GREEN, true); + watch_set_pin_level(RED, true); button = 3; } if (button != last_button) { last_button = button; - watch_buzzer_play_note(BUZZER_NOTE_C8, 50); + watch_buzzer_play_note(BUZZER_NOTE_C8, 100); } + static const bool segmap[3][24] = { + //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 + {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0}, + {0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1}, + {1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1} + }; + for(int com = 0; com < 3; com++) { for(int seg = 0; seg < 24; seg++) { - if (loop > 0) { - if (seg % 2 == 0) watch_set_pixel(com, seg); - else watch_set_pixel(com, seg); - } else { - if (seg % 2 == 1) watch_set_pixel(com, seg); - else watch_set_pixel(com, seg); - } + if (segmap[com][seg]) (loop >= 0) ? watch_set_pixel(com, seg) : watch_clear_pixel(com, seg); + else (loop < 0) ? watch_set_pixel(com, seg) : watch_clear_pixel(com, seg); } } - return true; + loop++; + + return false; } diff --git a/apps/sensor-board-test/app.c b/apps/sensor-board-test/app.c new file mode 100644 index 00000000..d7da190a --- /dev/null +++ b/apps/sensor-board-test/app.c @@ -0,0 +1,75 @@ +#include +#include +#include "watch.h" + +bool even = false; + +static void cb_tick(void) { + even = !even; +} + +void app_init(void) { +} + +void app_wake_from_backup(void) { +} + +void app_setup(void) { + watch_enable_digital_output(RED); + watch_enable_digital_output(GREEN); + watch_enable_digital_output(A0); + watch_enable_digital_output(SCL); + watch_enable_digital_output(SDA); + watch_enable_digital_output(A1); + watch_enable_digital_output(A2); + watch_enable_digital_output(A3); + watch_enable_digital_output(A4); + + watch_set_pin_level(A0, false); + watch_set_pin_level(SCL, false); + watch_set_pin_level(SDA, false); + watch_set_pin_level(A1, false); + watch_set_pin_level(A2, false); + watch_set_pin_level(A3, false); + watch_set_pin_level(A4, false); + + watch_rtc_register_periodic_callback(cb_tick, 2); +} + +void app_prepare_for_standby(void) { +} + +void app_wake_from_standby(void) { +} + +bool app_loop(void) { + watch_date_time date_time = watch_rtc_get_date_time(); + char buf[16]; + sprintf(buf, "%2d:%02d:%02d: ", date_time.unit.hour, date_time.unit.minute, date_time.unit.second); + printf(buf); + if (even) { + printf("Even\n"); + watch_set_pin_level(RED, false); + watch_set_pin_level(GREEN, true); + watch_set_pin_level(A0, true); + watch_set_pin_level(SCL, false); + watch_set_pin_level(SDA, true); + watch_set_pin_level(A1, false); + watch_set_pin_level(A2, true); + watch_set_pin_level(A3, false); + watch_set_pin_level(A4, true); + } else { + printf("Odd\n"); + watch_set_pin_level(RED, true); + watch_set_pin_level(GREEN, false); + watch_set_pin_level(A0, false); + watch_set_pin_level(SCL, true); + watch_set_pin_level(SDA, false); + watch_set_pin_level(A1, true); + watch_set_pin_level(A2, false); + watch_set_pin_level(A3, true); + watch_set_pin_level(A4, false); + } + + return true; +} diff --git a/apps/sensor-board-test/make/Makefile b/apps/sensor-board-test/make/Makefile new file mode 100755 index 00000000..c66ad20c --- /dev/null +++ b/apps/sensor-board-test/make/Makefile @@ -0,0 +1,10 @@ +TOP = ../../.. +include $(TOP)/make.mk + +INCLUDES += \ + -I../ + +SRCS += \ + ../app.c + +include $(TOP)/rules.mk -- cgit v1.2.3 From 6f96e848c233abd39e12e15bcf1cd32f48331894 Mon Sep 17 00:00:00 2001 From: Wesley Ellis Date: Thu, 14 Jul 2022 14:42:32 -0400 Subject: Replace python with python3 for calling uf2conv Instead of calling python use python3. On a default debian 11 install there is no python binary, only python3. Given that the uf2conv script is written for python 3 I think this is a safe change to make --- make.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make.mk b/make.mk index d8e2bf8a..dacce3fa 100644 --- a/make.mk +++ b/make.mk @@ -45,7 +45,7 @@ ifndef EMSCRIPTEN CC = arm-none-eabi-gcc OBJCOPY = arm-none-eabi-objcopy SIZE = arm-none-eabi-size -UF2 = python $(TOP)/utils/uf2conv.py +UF2 = python3 $(TOP)/utils/uf2conv.py CFLAGS += -W -Wall -Wextra -Wmissing-prototypes -Wmissing-declarations CFLAGS += --std=gnu99 -Os -- cgit v1.2.3 From b234db74fe3f70254860715cc4bb828a30290fb2 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Sun, 17 Jul 2022 00:22:03 -0500 Subject: movement: wake programmatically from background and play alarm --- movement/movement.c | 43 +++++++++++++++++++++++++++++++------------ movement/movement.h | 3 +++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/movement/movement.c b/movement/movement.c index 4a5bc04e..361a7aa1 100644 --- a/movement/movement.c +++ b/movement/movement.c @@ -222,6 +222,11 @@ void movement_cancel_background_task(void) { movement_state.has_scheduled_background_task = other_tasks_scheduled; } +void movement_request_wake() { + movement_state.needs_wake = true; + _movement_reset_inactivity_countdown(); +} + void movement_play_signal(void) { watch_buzzer_play_note(BUZZER_NOTE_C8, 75); watch_buzzer_play_note(BUZZER_NOTE_REST, 100); @@ -229,7 +234,11 @@ void movement_play_signal(void) { } void movement_play_alarm(void) { - movement_state.alarm_ticks = 128 * 5 - 80; // 80 ticks short of 5 seconds, or 4.375 seconds (our beep is 0.375 seconds) + movement_request_wake(); + // alarm length: 75 ticks short of 5 seconds, or 4.414 seconds: + // our tone is 0.375 seconds of beep and 0.625 of silence, repeated five times. + // so 4.375 + a few ticks to wake up from sleep mode. + movement_state.alarm_ticks = 128 * 5 - 75; _movement_enable_fast_tick_if_needed(); } @@ -319,6 +328,23 @@ void app_prepare_for_standby(void) { void app_wake_from_standby(void) { } +static void _sleep_mode_app_loop(void) { + movement_state.needs_wake = false; + // as long as le_mode_ticks is -1 (i.e. we are in low energy mode), we wake up here, update the screen, and go right back to sleep. + while (movement_state.le_mode_ticks == -1) { + // we also have to handle background tasks here in the mini-runloop + if (movement_state.needs_background_tasks_handled) _movement_handle_background_tasks(); + + event.event_type = EVENT_LOW_ENERGY_UPDATE; + watch_faces[movement_state.current_watch_face].loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_watch_face]); + + // if we need to wake immediately, do it! + if (movement_state.needs_wake) return; + // otherwise enter sleep mode, and when the extwake handler is called, it will reset le_mode_ticks and force us out at the next loop. + else watch_enter_sleep_mode(); + } +} + bool app_loop(void) { if (movement_state.watch_face_changed) { if (movement_state.settings.bit.button_should_sound) { @@ -360,17 +386,10 @@ bool app_loop(void) { event.event_type = EVENT_NONE; event.subsecond = 0; - // this is a little mini-runloop. - // as long as le_mode_ticks is -1 (i.e. we are in low energy mode), we wake up here, update the screen, and go right back to sleep. - while (movement_state.le_mode_ticks == -1) { - // we also have to handle background tasks here in the mini-runloop - if (movement_state.needs_background_tasks_handled) _movement_handle_background_tasks(); - - event.event_type = EVENT_LOW_ENERGY_UPDATE; - watch_faces[movement_state.current_watch_face].loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_watch_face]); - watch_enter_sleep_mode(); - } - // as soon as le_mode_ticks is reset by the extwake handler, we bail out of the loop and reactivate ourselves. + // _sleep_mode_app_loop takes over at this point and loops until le_mode_ticks is reset by the extwake handler, + // or wake is requested using the movement_request_wake function. + _sleep_mode_app_loop(); + // as soon as _sleep_mode_app_loop returns, we reactivate ourselves. event.event_type = EVENT_ACTIVATE; // this is a hack tho: waking from sleep mode, app_setup does get called, but it happens before we have reset our ticks. // need to figure out if there's a better heuristic for determining how we woke up. diff --git a/movement/movement.h b/movement/movement.h index a29c4469..255db057 100644 --- a/movement/movement.h +++ b/movement/movement.h @@ -257,6 +257,7 @@ typedef struct { // background task handling bool needs_background_tasks_handled; bool has_scheduled_background_task; + bool needs_wake; // low energy mode countdown int32_t le_mode_ticks; @@ -287,6 +288,8 @@ void movement_schedule_background_task(watch_date_time date_time); // movement will associate the scheduled task with the currently active face. void movement_cancel_background_task(void); +void movement_request_wake(); + void movement_play_signal(void); void movement_play_alarm(void); -- cgit v1.2.3 From b07b54868149e5b1465227e6b25b0f07dc4aad71 Mon Sep 17 00:00:00 2001 From: Jack Bond-Preston Date: Mon, 25 Jul 2022 15:17:02 +0100 Subject: movement: fix movement_request_wake() prototype This function has `void` args, currently it can throw a compiler warning --- movement/movement.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/movement/movement.h b/movement/movement.h index 255db057..0442f607 100644 --- a/movement/movement.h +++ b/movement/movement.h @@ -288,7 +288,7 @@ void movement_schedule_background_task(watch_date_time date_time); // movement will associate the scheduled task with the currently active face. void movement_cancel_background_task(void); -void movement_request_wake(); +void movement_request_wake(void); void movement_play_signal(void); void movement_play_alarm(void); -- cgit v1.2.3 From f120d66a98cac17fd69169500e148ffbc6eccd69 Mon Sep 17 00:00:00 2001 From: joshber <800692+joshber@users.noreply.github.com> Date: Mon, 25 Jul 2022 11:57:12 -0400 Subject: Wake Face (#77) Co-authored-by: Josh Berson --- movement/alt_fw/focus.h | 1 + movement/alt_fw/timers.h | 43 +++++++ movement/make/Makefile | 2 + movement/movement_faces.h | 2 + movement/watch_faces/complication/wake_face.c | 159 ++++++++++++++++++++++++++ movement/watch_faces/complication/wake_face.h | 53 +++++++++ 6 files changed, 260 insertions(+) create mode 100644 movement/alt_fw/timers.h create mode 100644 movement/watch_faces/complication/wake_face.c create mode 100644 movement/watch_faces/complication/wake_face.h diff --git a/movement/alt_fw/focus.h b/movement/alt_fw/focus.h index 865459e8..ab5525a5 100644 --- a/movement/alt_fw/focus.h +++ b/movement/alt_fw/focus.h @@ -32,6 +32,7 @@ const watch_face_t watch_faces[] = { tomato_face, stopwatch_face, countdown_face, + wake_face, // added by @joshber 2022-07-23, per @joeycastillo preferences_face, set_time_face, diff --git a/movement/alt_fw/timers.h b/movement/alt_fw/timers.h new file mode 100644 index 00000000..c4d27f50 --- /dev/null +++ b/movement/alt_fw/timers.h @@ -0,0 +1,43 @@ +/* + * MIT License + * + * Copyright (c) 2022 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef MOVEMENT_CONFIG_H_ +#define MOVEMENT_CONFIG_H_ + +#include "movement_faces.h" + +const watch_face_t watch_faces[] = { + simple_clock_face, + wake_face, + interval_face, + stopwatch_face, + sunrise_sunset_face, + + preferences_face, + set_time_face, +}; + +#define MOVEMENT_NUM_FACES (sizeof(watch_faces) / sizeof(watch_face_t)) + +#endif // MOVEMENT_CONFIG_H_ diff --git a/movement/make/Makefile b/movement/make/Makefile index 7c7cf2d6..22e5f31b 100755 --- a/movement/make/Makefile +++ b/movement/make/Makefile @@ -62,6 +62,8 @@ SRCS += \ ../watch_faces/complication/astronomy_face.c \ ../watch_faces/complication/tomato_face.c \ ../watch_faces/complication/probability_face.c \ + ../watch_faces/complication/wake_face.c \ +# wake_face.c: Josh Berson, 2022-07-04 # New watch faces go above this line. # Leave this line at the bottom of the file; it has all the targets for making your project. diff --git a/movement/movement_faces.h b/movement/movement_faces.h index 7c51b6ff..e18f3683 100644 --- a/movement/movement_faces.h +++ b/movement/movement_faces.h @@ -53,6 +53,8 @@ #include "astronomy_face.h" #include "tomato_face.h" #include "probability_face.h" +#include "wake_face.h" +// #include "interval_face.h" // New includes go above this line. #endif // MOVEMENT_FACES_H_ diff --git a/movement/watch_faces/complication/wake_face.c b/movement/watch_faces/complication/wake_face.c new file mode 100644 index 00000000..4c265c75 --- /dev/null +++ b/movement/watch_faces/complication/wake_face.c @@ -0,0 +1,159 @@ +/* + * MIT License + * + * Copyright (c) 2022 Josh Berson, building on Wesley Ellis’ countdown_face.c + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +//----------------------------------------------------------------------------- + +#include +#include +// #include + +#include "wake_face.h" +#include "watch.h" +#include "watch_utility.h" + +/* + UI Notes + º Light advances hour by 1 + º Light long press advances hour by 6 + º Alarm advances minute by 10 + º Alarm long press cycles through signal modes (just one at the moment) +*/ + +// +// Private +// + +static +void _wake_face_update_display(movement_settings_t *settings, wake_face_state_t *state) { + (void) settings; + uint8_t hour = state->hour; + + watch_clear_display(); + if ( settings->bit.clock_mode_24h ) + watch_set_indicator(WATCH_INDICATOR_24H); + else { + if ( hour >= 12 ) + watch_set_indicator(WATCH_INDICATOR_PM); + hour = hour % 12 ? hour % 12 : 12; + } + + if ( state->mode ) + watch_set_indicator(WATCH_INDICATOR_BELL); + + static char lcdbuf[11]; + sprintf(lcdbuf, "WA %2d%02d ", hour, state->minute); + + watch_set_colon(); + watch_display_string(lcdbuf, 0); +} + +// +// Exported +// + +void wake_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void **context_ptr) { + (void) settings; + (void) watch_face_index; + + if (*context_ptr == NULL) { + *context_ptr = malloc(sizeof(wake_face_state_t)); + wake_face_state_t *state = (wake_face_state_t *)*context_ptr; + memset(*context_ptr, 0, sizeof(wake_face_state_t)); + + state->hour = 5; + state->minute = 0; + state->mode = 0; + } +} + +void wake_face_activate(movement_settings_t *settings, void *context) { + (void) settings; + (void) context; +} +void wake_face_resign(movement_settings_t *settings, void *context) { + (void) settings; + (void) context; +} + +bool wake_face_wants_background_task(movement_settings_t *settings, void *context) { + (void) settings; + wake_face_state_t *state = (wake_face_state_t *)context; + + bool rc = false; + if ( state->mode ) { + watch_date_time now = watch_rtc_get_date_time(); + rc = state->hour==now.unit.hour && state->minute==now.unit.minute; + // We’re at the mercy of the wants_background_task handler + // In Safari, the emulator triggers at the ›end‹ of the minute + // Converting to Unix timestamps and taking a difference between now and wake + // is not an easy win — because the timestamp for wake has to rely on now + // for its date. So first we’d have to see if the TOD of wake is after that + // of now. If it is, take tomorrow’s date, calculating month and year rollover + // if need be. + } + return rc; +} + +bool wake_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { + (void) settings; + wake_face_state_t *state = (wake_face_state_t *)context; + + switch (event.event_type) { + case EVENT_ACTIVATE: + case EVENT_TICK: + _wake_face_update_display(settings, state); + break; + case EVENT_LIGHT_BUTTON_UP: + state->hour = (state->hour + 1) % 24; + _wake_face_update_display(settings, state); + break; + case EVENT_LIGHT_LONG_PRESS: + state->hour = (state->hour + 6) % 24; + _wake_face_update_display(settings, state); + break; + case EVENT_ALARM_BUTTON_UP: + state->minute = (state->minute + 10) % 60; + _wake_face_update_display(settings, state); + break; + case EVENT_ALARM_LONG_PRESS: + state->mode ^= 1; + _wake_face_update_display(settings, state); + break; + case EVENT_BACKGROUND_TASK: + movement_play_alarm(); + // 2022-07-23: Thx @joeycastillo for the dedicated “alarm” signal + break; + case EVENT_MODE_BUTTON_UP: + movement_move_to_next_face(); + break; + case EVENT_TIMEOUT: + movement_move_to_face(0); + break; + case EVENT_LOW_ENERGY_UPDATE: + default: + break; + } + + return true; +} \ No newline at end of file diff --git a/movement/watch_faces/complication/wake_face.h b/movement/watch_faces/complication/wake_face.h new file mode 100644 index 00000000..c091c8f3 --- /dev/null +++ b/movement/watch_faces/complication/wake_face.h @@ -0,0 +1,53 @@ +/* + * MIT License + * + * Copyright (c) 2022 Josh Berson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +//----------------------------------------------------------------------------- + +#ifndef WAKE_FACE_H_ +#define WAKE_FACE_H_ + +#include "movement.h" + +typedef struct { + uint32_t hour : 5; + uint32_t minute : 6; + uint32_t mode : 1; +} wake_face_state_t; + +void wake_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void **context_ptr); +void wake_face_activate(movement_settings_t *settings, void *context); +bool wake_face_loop(movement_event_t event, movement_settings_t *settings, void *context); +void wake_face_resign(movement_settings_t *settings, void *context); +bool wake_face_wants_background_task(movement_settings_t *settings, void *context); + +#define wake_face ((const watch_face_t){ \ + wake_face_setup, \ + wake_face_activate, \ + wake_face_loop, \ + wake_face_resign, \ + wake_face_wants_background_task \ +}) + +#endif // WAKE_FACE_H_ + -- cgit v1.2.3