From da59f6b10ac6c5d6a945cbf71c8f8a86cf847200 Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Wed, 17 Jul 2024 22:47:24 -0400 Subject: [PATCH] Added check for if not using Linux; renamed defines --- make.mk | 27 +++++++------- movement/movement.c | 4 +-- watch-library/hardware/main.c | 67 ++++++++++++++++++++++++++--------- 3 files changed, 67 insertions(+), 31 deletions(-) diff --git a/make.mk b/make.mk index 1bf1a4323..9817ffc05 100644 --- a/make.mk +++ b/make.mk @@ -248,6 +248,9 @@ endif # DAY = Sets the default time down to the day (year, month, day, timezone) # MIN = Sets the default time down to the minute (year, month, day, timezone, hour, minute) ifdef DATE +ifneq ($(DETECTED_OS), LINUX) +$(error DATE parameter only works with Linux.) +endif TIMEZONE := $(shell date +%z | awk '{print substr($$0, 1, 3) * 60 + substr($$0, 4, 2)}') CURRENT_YEAR := $(shell echo $$(($(shell date +"%Y") - 2020))) CURRENT_MONTH := $(shell date +"%-m") @@ -255,22 +258,22 @@ CURRENT_DAY := $(shell date +"%-d") CURRENT_HOUR := $(shell date +"%-H") CURRENT_MINUTE := $(shell date +"%-M") ifeq ($(DATE), YEAR) -CFLAGS += -DMAKEFILE_TIMEZONE=$(TIMEZONE) -CFLAGS += -DMAKEFILE_CURR_YEAR=$(CURRENT_YEAR) +CFLAGS += -DINITIAL_TIMEZONE=$(TIMEZONE) +CFLAGS += -DINITIAL_YEAR=$(CURRENT_YEAR) $(info Default year and timezone are set to $(shell date +"%Y") $(shell date +%Z)) else ifeq ($(DATE), DAY) -CFLAGS += -DMAKEFILE_TIMEZONE=$(TIMEZONE) -CFLAGS += -DMAKEFILE_CURR_YEAR=$(CURRENT_YEAR) -CFLAGS += -DMAKEFILE_CURR_MONTH=$(CURRENT_MONTH) -CFLAGS += -DMAKEFILE_CURR_DAY=$(CURRENT_DAY) +CFLAGS += -DINITIAL_TIMEZONE=$(TIMEZONE) +CFLAGS += -DINITIAL_YEAR=$(CURRENT_YEAR) +CFLAGS += -DINITIAL_MONTH=$(CURRENT_MONTH) +CFLAGS += -DINITIAL_DAY=$(CURRENT_DAY) $(info Default date set to $(shell date +"%b") $(CURRENT_DAY) $(shell date +"%Y") $(shell date +%Z)) else ifeq ($(DATE), MIN) -CFLAGS += -DMAKEFILE_TIMEZONE=$(TIMEZONE) -CFLAGS += -DMAKEFILE_CURR_YEAR=$(CURRENT_YEAR) -CFLAGS += -DMAKEFILE_CURR_MONTH=$(CURRENT_MONTH) -CFLAGS += -DMAKEFILE_CURR_DAY=$(CURRENT_DAY) -CFLAGS += -DMAKEFILE_CURR_HOUR=$(CURRENT_HOUR) -CFLAGS += -DMAKEFILE_CURR_MINUTE=$(CURRENT_MINUTE) +CFLAGS += -DINITIAL_TIMEZONE=$(TIMEZONE) +CFLAGS += -DINITIAL_YEAR=$(CURRENT_YEAR) +CFLAGS += -DINITIAL_MONTH=$(CURRENT_MONTH) +CFLAGS += -DINITIAL_DAY=$(CURRENT_DAY) +CFLAGS += -DINITIAL_HOUR=$(CURRENT_HOUR) +CFLAGS += -DINITIAL_MINUTE=$(CURRENT_MINUTE) $(info Default time set to $(CURRENT_HOUR):$(CURRENT_MINUTE) on $(shell date +"%b") $(CURRENT_DAY) $(shell date +"%Y") $(shell date +%Z)) else $(error DATE must be YEAR, DAY, or MIN if used.) diff --git a/movement/movement.c b/movement/movement.c index cabfb7e49..9266b4f57 100644 --- a/movement/movement.c +++ b/movement/movement.c @@ -384,9 +384,9 @@ void app_init(void) { movement_state.settings.bit.to_interval = MOVEMENT_DEFAULT_TIMEOUT_INTERVAL; movement_state.settings.bit.le_interval = MOVEMENT_DEFAULT_LOW_ENERGY_INTERVAL; movement_state.settings.bit.led_duration = MOVEMENT_DEFAULT_LED_DURATION; -#ifdef MAKEFILE_TIMEZONE +#ifdef INITIAL_TIMEZONE for (int i = 0, count = sizeof(movement_timezone_offsets) / sizeof(movement_timezone_offsets[0]); i < count; i++) { - if (movement_timezone_offsets[i] == MAKEFILE_TIMEZONE) { + if (movement_timezone_offsets[i] == INITIAL_TIMEZONE) { movement_state.settings.bit.time_zone = i; break; } diff --git a/watch-library/hardware/main.c b/watch-library/hardware/main.c index 599be4ba7..818caabc7 100755 --- a/watch-library/hardware/main.c +++ b/watch-library/hardware/main.c @@ -33,6 +33,51 @@ #include "watch.h" #include "tusb.h" +static inline uint32_t get_initial_year(void) +{ +#ifdef INITIAL_YEAR + return INITIAL_YEAR; +#else + return 4; +#endif +} + +static inline uint32_t get_initial_month(void) +{ +#ifdef INITIAL_MONTH + return INITIAL_MONTH; +#else + return 0; +#endif +} + +static inline uint32_t get_inital_day(void) +{ +#ifdef INITIAL_DAY + return INITIAL_DAY; +#else + return 0; +#endif +} + +static inline uint32_t get_inital_hour(void) +{ +#ifdef INITIAL_HOUR + return INITIAL_HOUR; +#else + return 0; +#endif +} + +static inline uint32_t get_inital_minute(void) +{ +#ifdef INITIAL_MINUTE + return INITIAL_MINUTE; +#else + return 0; +#endif +} + int main(void) { // ASF code. Initialize the MCU with configuration options from Atmel Studio. init_mcu(); @@ -69,23 +114,11 @@ int main(void) { // if date/time register is 0 (power on reset state), default year to 2023. watch_date_time date_time = watch_rtc_get_date_time(); if (date_time.reg == 0) { -#ifdef MAKEFILE_CURR_YEAR - date_time.unit.year = MAKEFILE_CURR_YEAR; -#else - date_time.unit.year = 3; -#endif -#ifdef MAKEFILE_CURR_MONTH - date_time.unit.month = MAKEFILE_CURR_MONTH; -#endif -#ifdef MAKEFILE_CURR_DAY - date_time.unit.day = MAKEFILE_CURR_DAY; -#endif -#ifdef MAKEFILE_CURR_HOUR - date_time.unit.hour = MAKEFILE_CURR_HOUR; -#endif -#ifdef MAKEFILE_CURR_MINUTE - date_time.unit.minute = MAKEFILE_CURR_MINUTE; -#endif + date_time.unit.year = get_initial_year(); + date_time.unit.month = get_initial_month(); + date_time.unit.day = get_inital_day(); + date_time.unit.hour = get_inital_hour(); + date_time.unit.minute = get_inital_minute(); watch_rtc_set_date_time(date_time); }