Skip to content

Commit

Permalink
Added times where chiming does not occur
Browse files Browse the repository at this point in the history
  • Loading branch information
voloved committed May 30, 2024
1 parent d51132f commit ceed39a
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 10 deletions.
18 changes: 18 additions & 0 deletions movement/movement.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@
#define MOVEMENT_DEFAULT_LED_DURATION 1
#endif

// Default to not always chiming every hour
#ifndef MOVEMENT_DEFAULT_HOURLY_CHIME_ALWAYS
#define MOVEMENT_DEFAULT_HOURLY_CHIME_ALWAYS 0
#endif

// Default to beginning a chime at 7am
#ifndef MOVEMENT_DEFAULT_HOURLY_CHIME_START
#define MOVEMENT_DEFAULT_HOURLY_CHIME_START 1
#endif

// Default to beginning a chime at 9pm
#ifndef MOVEMENT_DEFAULT_HOURLY_CHIME_END
#define MOVEMENT_DEFAULT_HOURLY_CHIME_END 1
#endif

#if __EMSCRIPTEN__
#include <emscripten.h>
#endif
Expand Down Expand Up @@ -384,6 +399,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;
movement_state.settings.bit.hourly_chime_always = MOVEMENT_DEFAULT_HOURLY_CHIME_ALWAYS;
movement_state.settings.bit.hourly_chime_start = MOVEMENT_DEFAULT_HOURLY_CHIME_START;
movement_state.settings.bit.hourly_chime_end = MOVEMENT_DEFAULT_HOURLY_CHIME_END;
movement_state.light_ticks = -1;
movement_state.alarm_ticks = -1;
movement_state.next_available_backup_register = 4;
Expand Down
21 changes: 20 additions & 1 deletion movement/movement.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ typedef union {
bool clock_mode_24h : 1; // indicates whether clock should use 12 or 24 hour mode.
bool use_imperial_units : 1; // indicates whether to use metric units (the default) or imperial.
bool alarm_enabled : 1; // indicates whether there is at least one alarm enabled.
uint8_t reserved : 6; // room for more preferences if needed.
bool hourly_chime_always : 1; // if true, then ignore the
uint8_t hourly_chime_start : 2; // 0: 6am; 1: 7am; 2: 10am; 3: 12pm;
uint8_t hourly_chime_end : 2; // 0: 8pm; 1: 9pm; 2: 10pm; 3: 12am;
bool reserved : 1; // room for more preferences if needed.
} bit;
uint32_t reg;
} movement_settings_t;
Expand Down Expand Up @@ -312,4 +315,20 @@ void movement_play_alarm_beeps(uint8_t rounds, BuzzerNote alarm_note);

uint8_t movement_claim_backup_register(void);

static const uint8_t Hourly_Chime_Start[] =
{
6, // 6am
7, // 7am
10, // 10am
12 // 12pm
};

static const uint8_t Hourly_Chime_End[] =
{
20, // 8pm
21, // 9pm
22, // 10pm
00 // 12am
};

#endif // MOVEMENT_H_
25 changes: 25 additions & 0 deletions movement/movement_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,29 @@ const watch_face_t watch_faces[] = {
*/
#define MOVEMENT_DEFAULT_LED_DURATION 1

/* Set if the watch will chime every hour and ignorethe start and end chimes
* Valid values are:
* 0: Use the Start and End values
* 1: Chime every hour
*/
#define MOVEMENT_DEFAULT_HOURLY_CHIME_ALWAYS 0

/* When hourly chiming should begin (MOVEMENT_DEFAULT_HOURLY_CHIME_ALWAYS must be 0)
* Valid values are:
* 0: 6am
* 1: 7am
* 2: 10am
* 3: 12pm
*/
#define MOVEMENT_DEFAULT_HOURLY_CHIME_START 1

/* When hourly chiming should end (MOVEMENT_DEFAULT_HOURLY_CHIME_ALWAYS must be 0)
* Valid values are:
* 0: 8pm
* 1: 9pm
* 2: 10pm
* 3: 12am
*/
#define MOVEMENT_DEFAULT_HOURLY_CHIME_END 1

#endif // MOVEMENT_CONFIG_H_
4 changes: 4 additions & 0 deletions movement/watch_faces/clock/simple_clock_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ bool simple_clock_face_wants_background_task(movement_settings_t *settings, void
if (!state->signal_enabled) return false;

watch_date_time date_time = watch_rtc_get_date_time();
uint8_t chime_start = Hourly_Chime_Start[settings->bit.hourly_chime_start];
uint8_t chime_end = Hourly_Chime_End[settings->bit.hourly_chime_end];
if (chime_end == 0) chime_end = 24;
if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false;

return date_time.unit.minute == 0;
}
77 changes: 68 additions & 9 deletions movement/watch_faces/settings/preferences_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@
#include "preferences_face.h"
#include "watch.h"

#define PREFERENCES_FACE_NUM_PREFEFENCES (7)
const char preferences_face_titles[PREFERENCES_FACE_NUM_PREFEFENCES][11] = {
#define PREFERENCES_FACE_NUM_PREFERENCES (9)
const char preferences_face_titles[PREFERENCES_FACE_NUM_PREFERENCES][11] = {
"CL ", // Clock: 12 or 24 hour
"BT Beep ", // Buttons: should they beep?
"TO ", // Timeout: how long before we snap back to the clock face?
"LE ", // Low Energy mode: how long before it engages?
"HCSt ", // Hourly Chime Start
"HCEn ", // Hourly Chime End
"LT ", // Light: duration
#ifdef WATCH_IS_BLUE_BOARD
"LT blu ", // Light: blue component (for watches with blue LED)
#else
"LT grn ", // Light: green component
#endif
"LT red ", // Light: red component
"LT red " // Light: red component
};

void preferences_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
Expand All @@ -53,6 +55,31 @@ void preferences_face_activate(movement_settings_t *settings, void *context) {
movement_request_tick_frequency(4); // we need to manually blink some pixels
}

static void _watch_display_hourly_chime_string(movement_settings_t *settings, uint8_t hour){
char buf[4];
if (settings->bit.hourly_chime_always){
watch_display_string(" Always", 4);
}
else{
if (!settings->bit.clock_mode_24h) {
// if we are in 12 hour mode, do some cleanup.
if (hour < 12) {
watch_clear_indicator(WATCH_INDICATOR_PM);
} else {
watch_set_indicator(WATCH_INDICATOR_PM);
}
hour %= 12;
if (hour == 0) hour = 12;
}
if (hour > 9)
sprintf(buf, "%2d", hour);
else
sprintf(buf, " %d", hour);
watch_display_string(buf, 6);
}
}


bool preferences_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
uint8_t current_page = *((uint8_t *)context);
switch (event.event_type) {
Expand All @@ -65,7 +92,7 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
movement_move_to_next_face();
return false;
case EVENT_LIGHT_BUTTON_DOWN:
current_page = (current_page + 1) % PREFERENCES_FACE_NUM_PREFEFENCES;
current_page = (current_page + 1) % PREFERENCES_FACE_NUM_PREFERENCES;
*((uint8_t *)context) = current_page;
break;
case EVENT_ALARM_BUTTON_UP:
Expand All @@ -83,12 +110,38 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
settings->bit.le_interval = settings->bit.le_interval + 1;
break;
case 4:
settings->bit.led_duration = settings->bit.led_duration + 1;
if (settings->bit.hourly_chime_always){
settings->bit.hourly_chime_always = false;
settings->bit.hourly_chime_start = 0;
}
else if (settings->bit.hourly_chime_start == 3){
settings->bit.hourly_chime_always = true;
settings->bit.hourly_chime_start = 0;
}
else{
settings->bit.hourly_chime_start = settings->bit.hourly_chime_start + 1;
}
break;
case 5:
settings->bit.led_green_color = settings->bit.led_green_color + 1;
if (settings->bit.hourly_chime_always){
settings->bit.hourly_chime_always = false;
settings->bit.hourly_chime_end = 0;
}
else if (settings->bit.hourly_chime_end == 3){
settings->bit.hourly_chime_always = true;
settings->bit.hourly_chime_end = 0;
}
else{
settings->bit.hourly_chime_end = settings->bit.hourly_chime_end + 1;
}
break;
case 6:
settings->bit.led_duration = settings->bit.led_duration + 1;
break;
case 7:
settings->bit.led_green_color = settings->bit.led_green_color + 1;
break;
case 8:
settings->bit.led_red_color = settings->bit.led_red_color + 1;
break;
}
Expand Down Expand Up @@ -159,26 +212,32 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
}
break;
case 4:
_watch_display_hourly_chime_string(settings, Hourly_Chime_Start[settings->bit.hourly_chime_start]);
break;
case 5:
_watch_display_hourly_chime_string(settings, Hourly_Chime_End[settings->bit.hourly_chime_end]);
break;
case 6:
if (settings->bit.led_duration) {
sprintf(buf, " %1d SeC", settings->bit.led_duration * 2 - 1);
watch_display_string(buf, 4);
} else {
watch_display_string("no LEd", 4);
}
break;
case 5:
case 7:
sprintf(buf, "%2d", settings->bit.led_green_color);
watch_display_string(buf, 8);
break;
case 6:
case 8:
sprintf(buf, "%2d", settings->bit.led_red_color);
watch_display_string(buf, 8);
break;
}
}

// on LED color select screns, preview the color.
if (current_page >= 5) {
if (current_page >= 7) {
watch_set_led_color(settings->bit.led_red_color ? (0xF | settings->bit.led_red_color << 4) : 0,
settings->bit.led_green_color ? (0xF | settings->bit.led_green_color << 4) : 0);
// return false so the watch stays awake (needed for the PWM driver to function).
Expand Down

0 comments on commit ceed39a

Please sign in to comment.