Skip to content

Commit

Permalink
Added check for if not using Linux; renamed defines
Browse files Browse the repository at this point in the history
  • Loading branch information
voloved committed Jul 18, 2024
1 parent 2f10a8f commit da59f6b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 31 deletions.
27 changes: 15 additions & 12 deletions make.mk
Original file line number Diff line number Diff line change
Expand Up @@ -248,29 +248,32 @@ 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")
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.)
Expand Down
4 changes: 2 additions & 2 deletions movement/movement.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
67 changes: 50 additions & 17 deletions watch-library/hardware/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit da59f6b

Please sign in to comment.