new preferences face with support for RGB LED

This commit is contained in:
joeycastillo 2024-09-22 22:26:59 -04:00
parent 608d6e2e9d
commit 687f1d9f60
8 changed files with 301 additions and 220 deletions

View File

@ -377,6 +377,22 @@ void app_init(void) {
#endif
movement_state.settings.bit.led_red_color = MOVEMENT_DEFAULT_RED_COLOR;
movement_state.settings.bit.led_green_color = MOVEMENT_DEFAULT_GREEN_COLOR;
#if defined(WATCH_BLUE_TCC_CHANNEL) && !defined(WATCH_GREEN_TCC_CHANNEL)
// If there is a blue LED but no green LED, this is a blue Special Edition board.
// In the past, the "green color" showed up as the blue color on the blue board.
if (MOVEMENT_DEFAULT_RED_COLOR == 0 && MOVEMENT_DEFAULT_BLUE_COLOR == 0) {
// If the red color is 0 and the blue color is 0, we'll fall back to the old
// behavior, since otherwise there would be no default LED color.
movement_state.settings.bit.led_blue_color = MOVEMENT_DEFAULT_GREEN_COLOR;
} else {
// however if either the red or blue color is nonzero, we'll assume the user
// has used the new defaults and knows what color they want. this could be red
// if blue is 0, or a custom color if both are nonzero.
movement_state.settings.bit.led_blue_color = MOVEMENT_DEFAULT_BLUE_COLOR;
}
#else
movement_state.settings.bit.led_blue_color = MOVEMENT_DEFAULT_BLUE_COLOR;
#endif
movement_state.settings.bit.button_should_sound = MOVEMENT_DEFAULT_BUTTON_SOUND;
movement_state.settings.bit.to_interval = MOVEMENT_DEFAULT_TIMEOUT_INTERVAL;
movement_state.settings.bit.le_interval = MOVEMENT_DEFAULT_LOW_ENERGY_INTERVAL;

View File

@ -41,9 +41,7 @@
// This allows these preferences to be stored before entering BACKUP mode and and restored after waking from reset.
// movement_settings_t contains global settings that cover watch behavior, including preferences around clock and unit
// display, time zones, buzzer behavior, LED color and low energy mode timeouts. These settings are stored in BKUP[0].
// If your watch face changes one of these settings, you should store your changes in either your loop or resign
// function by calling `watch_store_backup_data(settings->reg, 0)`. Otherwise it may not persist after a reset event.
// display, time zones, buzzer behavior, LED color and low energy mode timeouts.
typedef union {
struct {
bool button_should_sound : 1; // if true, pressing a button emits a sound.
@ -53,6 +51,7 @@ typedef union {
uint8_t led_duration : 3; // how many seconds to shine the LED for (x2), 0 to shine only while the button is depressed, or all bits set to disable the LED altogether.
uint8_t led_red_color : 4; // for general purpose illumination, the red LED value (0-15)
uint8_t led_green_color : 4; // for general purpose illumination, the green LED value (0-15)
uint8_t led_blue_color : 4; // for general purpose illumination, the green LED value (0-15)
uint8_t time_zone : 6; // an integer representing an index in the time zone table.
// while Movement itself doesn't implement a clock or display units, it may make sense to include some
@ -61,8 +60,10 @@ typedef union {
// altimeter to display feet or meters as easily as it tells a thermometer to display degrees in F or C.
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.
/// TODO: for #SecondMovement: move alarm_enabled out of preferences
bool alarm_enabled : 1; // indicates whether there is at least one alarm enabled.
uint8_t reserved : 6; // room for more preferences if needed.
uint8_t reserved : 1; // room for more preferences if needed.
} bit;
uint32_t reg;
} movement_settings_t;

View File

@ -1,204 +0,0 @@
/*
* 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.
*/
#include <stdlib.h>
#include "preferences_face.h"
#include "watch.h"
#define PREFERENCES_FACE_NUM_PREFERENCES (7)
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?
"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
};
void preferences_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(uint8_t));
}
void preferences_face_activate(movement_settings_t *settings, void *context) {
(void) settings;
*((uint8_t *)context) = 0;
movement_request_tick_frequency(4); // we need to manually blink some pixels
}
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) {
case EVENT_TICK:
case EVENT_ACTIVATE:
// Do nothing; handled below.
break;
case EVENT_MODE_BUTTON_UP:
watch_set_led_off();
movement_move_to_next_face();
return false;
case EVENT_LIGHT_BUTTON_DOWN:
current_page = (current_page + 1) % PREFERENCES_FACE_NUM_PREFERENCES;
*((uint8_t *)context) = current_page;
break;
case EVENT_ALARM_BUTTON_UP:
switch (current_page) {
case 0:
settings->bit.clock_mode_24h = !(settings->bit.clock_mode_24h);
break;
case 1:
settings->bit.button_should_sound = !(settings->bit.button_should_sound);
break;
case 2:
settings->bit.to_interval = settings->bit.to_interval + 1;
break;
case 3:
settings->bit.le_interval = settings->bit.le_interval + 1;
break;
case 4:
settings->bit.led_duration = settings->bit.led_duration + 1;
if (settings->bit.led_duration > 3) {
settings->bit.led_duration = 0b111;
}
break;
case 5:
settings->bit.led_green_color = settings->bit.led_green_color + 1;
break;
case 6:
settings->bit.led_red_color = settings->bit.led_red_color + 1;
break;
}
break;
case EVENT_TIMEOUT:
movement_move_to_face(0);
break;
default:
return movement_default_loop_handler(event, settings);
}
#ifdef CLOCK_FACE_24H_ONLY
if (current_page == 0) current_page++; // Skips past 12/24HR mode
#endif
watch_display_string((char *)preferences_face_titles[current_page], 0);
// blink active setting on even-numbered quarter-seconds
if (event.subsecond % 2) {
char buf[8];
switch (current_page) {
case 0:
if (settings->bit.clock_mode_24h) watch_display_string("24h", 4);
else watch_display_string("12h", 4);
break;
case 1:
if (settings->bit.button_should_sound) watch_display_string("y", 9);
else watch_display_string("n", 9);
break;
case 2:
switch (settings->bit.to_interval) {
case 0:
watch_display_string("60 SeC", 4);
break;
case 1:
watch_display_string("2 n&in", 4);
break;
case 2:
watch_display_string("5 n&in", 4);
break;
case 3:
watch_display_string("30n&in", 4);
break;
}
break;
case 3:
switch (settings->bit.le_interval) {
case 0:
watch_display_string(" Never", 4);
break;
case 1:
watch_display_string("10n&in", 4);
break;
case 2:
watch_display_string("1 hour", 4);
break;
case 3:
watch_display_string("2 hour", 4);
break;
case 4:
watch_display_string("6 hour", 4);
break;
case 5:
watch_display_string("12 hr", 4);
break;
case 6:
watch_display_string(" 1 day", 4);
break;
case 7:
watch_display_string(" 7 day", 4);
break;
}
break;
case 4:
if (settings->bit.led_duration == 0) {
watch_display_string("instnt", 4);
} else if (settings->bit.led_duration == 0b111) {
watch_display_string("no LEd", 4);
} else {
sprintf(buf, " %1d SeC", settings->bit.led_duration * 2 - 1);
watch_display_string(buf, 4);
}
break;
case 5:
sprintf(buf, "%2d", settings->bit.led_green_color);
watch_display_string(buf, 8);
break;
case 6:
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) {
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).
return false;
}
watch_set_led_off();
return true;
}
void preferences_face_resign(movement_settings_t *settings, void *context) {
(void) settings;
(void) context;
watch_set_led_off();
watch_store_backup_data(settings->reg, 0);
}

View File

@ -29,6 +29,7 @@
const watch_face_t watch_faces[] = {
simple_clock_face,
preferences_face,
set_time_face,
};
@ -40,7 +41,7 @@ const watch_face_t watch_faces[] = {
* Some folks also like to use this to hide the preferences and time set faces from the normal rotation.
* If you don't want any faces to be excluded, set this to 0 and a long Mode press will have no effect.
*/
#define MOVEMENT_SECONDARY_FACE_INDEX (MOVEMENT_NUM_FACES - 2) // or (0)
#define MOVEMENT_SECONDARY_FACE_INDEX (0) // (MOVEMENT_NUM_FACES - 2)
/* Custom hourly chime tune. Check movement_custom_signal_tunes.h for options. */
#define SIGNAL_TUNE_DEFAULT
@ -48,8 +49,9 @@ const watch_face_t watch_faces[] = {
/* Determines the intensity of the led colors
* Set a hex value 0-15 with 0x0 being off and 0xF being max intensity
*/
#define MOVEMENT_DEFAULT_GREEN_COLOR 0xF
#define MOVEMENT_DEFAULT_RED_COLOR 0x0
#define MOVEMENT_DEFAULT_GREEN_COLOR 0xF
#define MOVEMENT_DEFAULT_BLUE_COLOR 0x0
/* Set to true for 24h mode or false for 12h mode */
#define MOVEMENT_DEFAULT_24H_MODE false

View File

@ -26,4 +26,5 @@
#include "simple_clock_face.h"
#include "set_time_face.h"
#include "preferences_face.h"
// New includes go above this line.

View File

@ -1,3 +1,4 @@
SRCS += \
./watch-faces/clock/simple_clock_face.c \
./watch-faces/settings/set_time_face.c \
./watch-faces/settings/preferences_face.c \

View File

@ -0,0 +1,245 @@
/*
* MIT License
*
* Copyright (c) 2022-2024 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.
*/
#include <stdlib.h>
#include "preferences_face.h"
#include "watch.h"
const char preferences_face_titles[PREFERENCES_PAGE_NUM_PREFERENCES][11] = {
"CL ", // Clock: 12 or 24 hour
"BT beep ", // Mode button: how loud should it beep?
"TO ", // Timeout: how long before we snap back to the clock face?
"LE ", // Low Energy mode: how long before it engages?
"LT ", // Light: duration
"LT red ", // Light: red component
"LT green", // Light: green component
"LT blue ", // Light: blue component (for watches with blue LED)
};
void preferences_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(preferences_state_t));
preferences_state_t *state = (preferences_state_t *)*context_ptr;
for (int i = 0; i < PREFERENCES_PAGE_NUM_PREFERENCES; i++) {
state->setting_enabled[i] = true;
}
#ifdef CLOCK_FACE_24H_ONLY
state->setting_enabled[PREFERENCES_PAGE_CLOCK_MODE] = false;
#endif
#ifndef WATCH_RED_TCC_CHANNEL
state->setting_enabled[PREFERENCES_PAGE_LED_RED] = false;
#endif
#ifndef WATCH_GREEN_TCC_CHANNEL
state->setting_enabled[PREFERENCES_PAGE_LED_GREEN] = false;
#endif
#ifndef WATCH_BLUE_TCC_CHANNEL
state->setting_enabled[PREFERENCES_PAGE_LED_BLUE] = false;
#endif
}
}
void preferences_face_activate(movement_settings_t *settings, void *context) {
(void) settings;
preferences_state_t *state = (preferences_state_t *)context;
state->current_page = 0;
movement_request_tick_frequency(4); // we need to manually blink some pixels
}
bool preferences_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
preferences_state_t *state = (preferences_state_t *)context;
switch (event.event_type) {
case EVENT_TICK:
case EVENT_ACTIVATE:
// Do nothing; handled below.
break;
case EVENT_MODE_BUTTON_UP:
watch_set_led_off();
movement_move_to_next_face();
return false;
case EVENT_LIGHT_BUTTON_DOWN:
state->current_page = (state->current_page + 1) % PREFERENCES_PAGE_NUM_PREFERENCES;
while (!state->setting_enabled[state->current_page]) {
state->current_page = (state->current_page + 1) % PREFERENCES_PAGE_NUM_PREFERENCES;
}
break;
case EVENT_ALARM_BUTTON_UP:
switch (state->current_page) {
case PREFERENCES_PAGE_CLOCK_MODE:
settings->bit.clock_mode_24h = !settings->bit.clock_mode_24h;
break;
case PREFERENCES_PAGE_BUTTON_SOUND:
settings->bit.button_should_sound = !settings->bit.button_should_sound;
break;
case PREFERENCES_PAGE_TIMEOUT:
settings->bit.to_interval = settings->bit.to_interval + 1;
break;
case PREFERENCES_PAGE_LOW_ENERGY:
settings->bit.le_interval = settings->bit.le_interval + 1;
break;
case PREFERENCES_PAGE_LED_DURATION:
settings->bit.led_duration = settings->bit.led_duration + 1;
if (settings->bit.led_duration > 3) {
// set all bits to disable the LED
settings->bit.led_duration = 0b111;
}
break;
case PREFERENCES_PAGE_LED_RED:
settings->bit.led_red_color = settings->bit.led_red_color + 1;
break;
case PREFERENCES_PAGE_LED_GREEN:
settings->bit.led_green_color = settings->bit.led_green_color + 1;
break;
case PREFERENCES_PAGE_LED_BLUE:
settings->bit.led_blue_color = settings->bit.led_blue_color + 1;
break;
case PREFERENCES_PAGE_NUM_PREFERENCES:
// nothing to do here, just silencing the warning
break;
}
break;
case EVENT_TIMEOUT:
movement_move_to_face(0);
break;
default:
return movement_default_loop_handler(event, settings);
}
watch_display_text(WATCH_POSITION_FULL, (char *)preferences_face_titles[state->current_page]);
watch_clear_all_indicators();
watch_clear_colon();
// blink active setting on even-numbered quarter-seconds
if (event.subsecond % 2) {
char buf[8];
switch (state->current_page) {
case PREFERENCES_PAGE_CLOCK_MODE:
if (settings->bit.clock_mode_24h) watch_display_text(WATCH_POSITION_BOTTOM, "24h");
else watch_display_text(WATCH_POSITION_BOTTOM, "12h");
break;
case PREFERENCES_PAGE_BUTTON_SOUND:
if (settings->bit.button_should_sound) {
watch_display_text(WATCH_POSITION_TOP_RIGHT, " Y");
} else {
watch_display_text(WATCH_POSITION_TOP_RIGHT, " N");
}
break;
case PREFERENCES_PAGE_TIMEOUT:
switch (settings->bit.to_interval) {
case 0:
watch_display_text(WATCH_POSITION_BOTTOM, "60 SeC");
break;
case 1:
watch_display_text(WATCH_POSITION_BOTTOM, "2 n&in");
break;
case 2:
watch_display_text(WATCH_POSITION_BOTTOM, "5 n&in");
break;
case 3:
watch_display_text(WATCH_POSITION_BOTTOM, "30n&in");
break;
}
break;
case PREFERENCES_PAGE_LOW_ENERGY:
switch (settings->bit.le_interval) {
case 0:
watch_display_text(WATCH_POSITION_BOTTOM, " Never");
break;
case 1:
watch_display_text(WATCH_POSITION_BOTTOM, "10n&in");
break;
case 2:
watch_display_text(WATCH_POSITION_BOTTOM, "1 hour");
break;
case 3:
watch_display_text(WATCH_POSITION_BOTTOM, "2 hour");
break;
case 4:
watch_display_text(WATCH_POSITION_BOTTOM, "6 hour");
break;
case 5:
watch_display_text(WATCH_POSITION_BOTTOM, "12 hr");
break;
case 6:
watch_display_text(WATCH_POSITION_BOTTOM, " 1 day");
break;
case 7:
watch_display_text(WATCH_POSITION_BOTTOM, " 7 day");
break;
}
break;
case PREFERENCES_PAGE_LED_DURATION:
if (settings->bit.led_duration == 0) {
watch_display_text(WATCH_POSITION_BOTTOM, "instnt");
} else if (settings->bit.led_duration == 0b111) {
watch_display_text(WATCH_POSITION_BOTTOM, "no LEd");
} else {
sprintf(buf, " %1d SeC", settings->bit.led_duration * 2 - 1);
watch_display_text(WATCH_POSITION_BOTTOM, buf);
}
break;
case PREFERENCES_PAGE_LED_RED:
sprintf(buf, "%2d", settings->bit.led_red_color);
watch_display_text(WATCH_POSITION_TOP_RIGHT, buf);
break;
break;
case PREFERENCES_PAGE_LED_GREEN:
sprintf(buf, "%2d", settings->bit.led_green_color);
watch_display_text(WATCH_POSITION_TOP_RIGHT, buf);
break;
break;
case PREFERENCES_PAGE_LED_BLUE:
sprintf(buf, "%2d", settings->bit.led_blue_color);
watch_display_text(WATCH_POSITION_TOP_RIGHT, buf);
break;
case PREFERENCES_PAGE_NUM_PREFERENCES:
// nothing to do here, just silencing the warning
break;
}
}
// on LED color select screns, preview the color.
if (state->current_page == PREFERENCES_PAGE_LED_RED ||
state->current_page == PREFERENCES_PAGE_LED_GREEN ||
state->current_page == PREFERENCES_PAGE_LED_BLUE) {
watch_set_led_color_rgb(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,
settings->bit.led_blue_color ? (0xF | settings->bit.led_blue_color << 4) : 0);
// return false so the watch stays awake (needed for the PWM driver to function).
return false;
}
watch_set_led_off();
return true;
}
void preferences_face_resign(movement_settings_t *settings, void *context) {
(void) settings;
(void) context;
watch_set_led_off();
watch_store_backup_data(settings->reg, 0);
}

View File

@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022 Joey Castillo
* Copyright (c) 2022-2024 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
@ -22,8 +22,7 @@
* SOFTWARE.
*/
#ifndef PREFERENCES_FACE_H_
#define PREFERENCES_FACE_H_
#pragma once
/*
* PREFERENCES face
@ -40,11 +39,15 @@
* for example, both Simple Clock, World Clock and Sunrise/Sunset will
* display the time in 24 hour format if the 24 hour clock is selected here.
*
* BT - Button tone.
* This setting is only relevant if you installed the buzzer connector,
* and it toggles the beep when changing modes. If Y, the buzzer will
* sound a tone when Mode is pressed. Change to N to make the Mode
* button silent.
* MO - Mode button.
* This setting allows you to choose whether the Mode button should emit
* a beep when pressed, and if so, how loud it should be. Options are
* "-" (no beep), "L" (low volume) and "H" (high volume).
*
* MO - Mode button.
* This setting allows you to choose whether the Mode button should emit
* a beep when pressed, and if so, how loud it should be. Options are
* "-" (no beep), "L" (low volume) and "H" (high volume).
*
* TO - Timeout.
* Sets the time until screens that time out (like Settings and Time Set)
@ -78,6 +81,24 @@
#include "movement.h"
typedef enum {
PREFERENCES_PAGE_CLOCK_MODE = 0,
PREFERENCES_PAGE_BUTTON_SOUND,
PREFERENCES_PAGE_TIMEOUT,
PREFERENCES_PAGE_LOW_ENERGY,
PREFERENCES_PAGE_LED_DURATION,
PREFERENCES_PAGE_LED_RED,
PREFERENCES_PAGE_LED_GREEN,
PREFERENCES_PAGE_LED_BLUE,
PREFERENCES_PAGE_NUM_PREFERENCES,
} preferences_page_t;
typedef struct {
bool setting_enabled[PREFERENCES_PAGE_NUM_PREFERENCES];
preferences_page_t current_page;
} preferences_state_t;
void preferences_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
void preferences_face_activate(movement_settings_t *settings, void *context);
bool preferences_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
@ -90,5 +111,3 @@ void preferences_face_resign(movement_settings_t *settings, void *context);
preferences_face_resign, \
NULL, \
})
#endif // PREFERENCES_FACE_H_