first build of Second Movement with two watch faces
This commit is contained in:
parent
24598ec280
commit
dccad01e8f
10
Makefile
10
Makefile
@ -27,14 +27,18 @@ endif
|
||||
|
||||
# Add your include directories here.
|
||||
INCLUDES += \
|
||||
-I./ \
|
||||
-I./tinyusb/src \
|
||||
-I./watch-library/shared/watch \
|
||||
-I./watch-library/hardware/watch \
|
||||
-I./watch-faces/clock \
|
||||
-I./watch-faces/settings \
|
||||
|
||||
# Add your source files here.
|
||||
SRCS += \
|
||||
./watch-library/shared/watch/watch_common_buzzer.c \
|
||||
./watch-library/shared/watch/watch_common_display.c \
|
||||
./watch-library/shared/watch/watch_utility.c \
|
||||
./watch-library/hardware/watch/watch.c \
|
||||
./watch-library/hardware/watch/watch_adc.c \
|
||||
./watch-library/hardware/watch/watch_deepsleep.c \
|
||||
@ -47,7 +51,11 @@ SRCS += \
|
||||
./watch-library/hardware/watch/watch_tcc.c \
|
||||
./watch-library/hardware/watch/watch_usb_descriptors.c \
|
||||
./watch-library/hardware/watch/watch_usb_cdc.c \
|
||||
./app.c \
|
||||
|
||||
include watch-faces.mk
|
||||
|
||||
SRCS += \
|
||||
./movement.c \
|
||||
|
||||
# Finally, leave this line at the bottom of the file.
|
||||
include $(GOSSAMER_PATH)/rules.mk
|
||||
|
||||
102
app.c
102
app.c
@ -1,102 +0,0 @@
|
||||
#include "app.h"
|
||||
#include "watch.h"
|
||||
#include "watch_private.h"
|
||||
#include "delay.h"
|
||||
#include "usb.h"
|
||||
#include "tusb.h"
|
||||
#include "watch_usb_cdc.h"
|
||||
#include "tcc.h"
|
||||
|
||||
uint8_t ticks = 0;
|
||||
bool beep = false;
|
||||
|
||||
void cb_tick(void);
|
||||
void cb_mode_btn_interrupt(void);
|
||||
void cb_light_btn_interrupt(void);
|
||||
void cb_alarm_btn_extwake(void);
|
||||
|
||||
void yield(void) {
|
||||
tud_task();
|
||||
cdc_task();
|
||||
}
|
||||
|
||||
void app_init(void) {
|
||||
// initialize the watch hardware.
|
||||
_watch_init();
|
||||
|
||||
// check if we are plugged into USB power.
|
||||
HAL_GPIO_VBUS_DET_in();
|
||||
HAL_GPIO_VBUS_DET_pulldown();
|
||||
if (HAL_GPIO_VBUS_DET_read()){
|
||||
/// if so, enable USB functionality.
|
||||
_watch_enable_usb();
|
||||
}
|
||||
HAL_GPIO_VBUS_DET_off();
|
||||
}
|
||||
|
||||
void app_setup(void) {
|
||||
watch_enable_leds();
|
||||
watch_enable_external_interrupts();
|
||||
|
||||
HAL_GPIO_BTN_LIGHT_in();
|
||||
HAL_GPIO_BTN_LIGHT_pulldown();
|
||||
HAL_GPIO_BTN_LIGHT_pmuxen(HAL_GPIO_PMUX_EIC);
|
||||
HAL_GPIO_BTN_MODE_in();
|
||||
HAL_GPIO_BTN_MODE_pulldown();
|
||||
HAL_GPIO_BTN_MODE_pmuxen(HAL_GPIO_PMUX_EIC);
|
||||
|
||||
// Simple test sketch exercises RTC and EIC, plus LEDs, screen and buzzer.
|
||||
// Periodic callback increments the tick counter.
|
||||
watch_rtc_register_periodic_callback(cb_tick, 1);
|
||||
// Light button turns on the LED.
|
||||
watch_register_interrupt_callback(HAL_GPIO_BTN_LIGHT_pin(), cb_light_btn_interrupt, INTERRUPT_TRIGGER_RISING);
|
||||
// Mode button beeps the piezo.
|
||||
watch_register_interrupt_callback(HAL_GPIO_BTN_MODE_pin(), cb_mode_btn_interrupt, INTERRUPT_TRIGGER_RISING);
|
||||
// Alarm buttton resets the tick counter.
|
||||
watch_register_extwake_callback(HAL_GPIO_BTN_ALARM_pin(), cb_alarm_btn_extwake, true);
|
||||
|
||||
watch_enable_display();
|
||||
watch_display_top_left("WA");
|
||||
watch_display_top_right(" 0");
|
||||
watch_display_main_line(" test ");
|
||||
}
|
||||
|
||||
bool app_loop(void) {
|
||||
if (usb_is_enabled()) {
|
||||
yield();
|
||||
}
|
||||
|
||||
if (beep) {
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C8, 100);
|
||||
beep = false;
|
||||
}
|
||||
|
||||
char buf[4];
|
||||
sprintf(buf, "%2d", ticks);
|
||||
printf("ticks: %d\n", ticks);
|
||||
watch_display_top_right(buf);
|
||||
|
||||
if (ticks >= 30) {
|
||||
watch_enter_sleep_mode();
|
||||
}
|
||||
|
||||
return !usb_is_enabled();
|
||||
}
|
||||
|
||||
void cb_tick(void) {
|
||||
ticks = ticks + 1;
|
||||
watch_set_led_off();
|
||||
}
|
||||
|
||||
void cb_light_btn_interrupt(void) {
|
||||
watch_set_led_green();
|
||||
}
|
||||
|
||||
void cb_mode_btn_interrupt(void) {
|
||||
beep = true;
|
||||
}
|
||||
|
||||
void cb_alarm_btn_extwake(void) {
|
||||
watch_set_led_red();
|
||||
ticks = 0;
|
||||
}
|
||||
@ -30,32 +30,25 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "app.h"
|
||||
#include "watch.h"
|
||||
#include "filesystem.h"
|
||||
#include "usb.h"
|
||||
#include "movement.h"
|
||||
#include "shell.h"
|
||||
|
||||
#ifndef MOVEMENT_FIRMWARE
|
||||
#include "movement_config.h"
|
||||
#elif MOVEMENT_FIRMWARE == MOVEMENT_FIRMWARE_STANDARD
|
||||
#include "movement_config.h"
|
||||
#elif MOVEMENT_FIRMWARE == MOVEMENT_FIRMWARE_BACKER
|
||||
#include "alt_fw/backer.h"
|
||||
#elif MOVEMENT_FIRMWARE == MOVEMENT_FIRMWARE_ALT_TIME
|
||||
#include "alt_fw/alt_time.h"
|
||||
#elif MOVEMENT_FIRMWARE == MOVEMENT_FIRMWARE_FOCUS
|
||||
#include "alt_fw/focus.h"
|
||||
#elif MOVEMENT_FIRMWARE == MOVEMENT_FIRMWARE_THE_BACKPACKER
|
||||
#include "alt_fw/the_backpacker.h"
|
||||
#elif MOVEMENT_FIRMWARE == MOVEMENT_FIRMWARE_THE_ATHLETE
|
||||
#include "alt_fw/the_athlete.h"
|
||||
#elif MOVEMENT_FIRMWARE == MOVEMENT_FIRMWARE_THE_STARGAZER
|
||||
#include "alt_fw/the_stargazer.h"
|
||||
#elif MOVEMENT_FIRMWARE == MOVEMENT_FIRMWARE_DEEP_SPACE_NOW
|
||||
#include "alt_fw/deep_space_now.h"
|
||||
#endif
|
||||
/// FIXMME: #SecondMovement needs to bring back the following includes (and remove the default signal_tune)
|
||||
// #include "filesystem.h"
|
||||
// #include "shell.h"
|
||||
// #include "movement_custom_signal_tunes.h"
|
||||
int8_t signal_tune[] = {
|
||||
BUZZER_NOTE_C8, 5,
|
||||
BUZZER_NOTE_REST, 6,
|
||||
BUZZER_NOTE_C8, 5,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
#include "movement_config.h"
|
||||
|
||||
#include "movement_custom_signal_tunes.h"
|
||||
|
||||
// Default to no secondary face behaviour.
|
||||
#ifndef MOVEMENT_SECONDARY_FACE_INDEX
|
||||
@ -412,7 +405,8 @@ void app_init(void) {
|
||||
movement_state.next_available_backup_register = 4;
|
||||
_movement_reset_inactivity_countdown();
|
||||
|
||||
filesystem_init();
|
||||
/// FIXME: #SecondMovement needs filesystem support
|
||||
// filesystem_init();
|
||||
|
||||
#if __EMSCRIPTEN__
|
||||
int32_t time_zone_offset = EM_ASM_INT({
|
||||
@ -454,12 +448,12 @@ void app_setup(void) {
|
||||
watch_rtc_register_alarm_callback(cb_alarm_fired, alarm_time, ALARM_MATCH_SS);
|
||||
}
|
||||
if (movement_state.le_mode_ticks != -1) {
|
||||
watch_disable_extwake_interrupt(BTN_ALARM);
|
||||
watch_disable_extwake_interrupt(HAL_GPIO_BTN_ALARM_pin());
|
||||
|
||||
watch_enable_external_interrupts();
|
||||
watch_register_interrupt_callback(BTN_MODE, cb_mode_btn_interrupt, INTERRUPT_TRIGGER_BOTH);
|
||||
watch_register_interrupt_callback(BTN_LIGHT, cb_light_btn_interrupt, INTERRUPT_TRIGGER_BOTH);
|
||||
watch_register_interrupt_callback(BTN_ALARM, cb_alarm_btn_interrupt, INTERRUPT_TRIGGER_BOTH);
|
||||
watch_register_interrupt_callback(HAL_GPIO_BTN_MODE_pin(), cb_mode_btn_interrupt, INTERRUPT_TRIGGER_BOTH);
|
||||
watch_register_interrupt_callback(HAL_GPIO_BTN_LIGHT_pin(), cb_light_btn_interrupt, INTERRUPT_TRIGGER_BOTH);
|
||||
watch_register_interrupt_callback(HAL_GPIO_BTN_ALARM_pin(), cb_alarm_btn_interrupt, INTERRUPT_TRIGGER_BOTH);
|
||||
|
||||
watch_enable_buzzer();
|
||||
watch_enable_leds();
|
||||
@ -477,12 +471,6 @@ void app_setup(void) {
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
@ -523,7 +511,7 @@ bool app_loop(void) {
|
||||
// if the LED should be off, turn it off
|
||||
if (movement_state.light_ticks == 0) {
|
||||
// unless the user is holding down the LIGHT button, in which case, give them more time.
|
||||
if (watch_get_pin_level(BTN_LIGHT)) {
|
||||
if (HAL_GPIO_BTN_LIGHT_read()) {
|
||||
movement_state.light_ticks = 1;
|
||||
} else {
|
||||
_movement_led_off();
|
||||
@ -539,7 +527,7 @@ bool app_loop(void) {
|
||||
// if we have timed out of our low energy mode countdown, enter low energy mode.
|
||||
if (movement_state.le_mode_ticks == 0) {
|
||||
movement_state.le_mode_ticks = -1;
|
||||
watch_register_extwake_callback(BTN_ALARM, cb_alarm_btn_extwake, true);
|
||||
watch_register_extwake_callback(HAL_GPIO_BTN_ALARM_pin(), cb_alarm_btn_extwake, true);
|
||||
event.event_type = EVENT_NONE;
|
||||
event.subsecond = 0;
|
||||
|
||||
@ -623,8 +611,9 @@ bool app_loop(void) {
|
||||
}
|
||||
|
||||
// if we are plugged into USB, handle the serial shell
|
||||
if (watch_is_usb_enabled()) {
|
||||
shell_task();
|
||||
if (usb_is_enabled()) {
|
||||
/// FIXME: #SecondMovement needs to bring back the shell
|
||||
// shell_task();
|
||||
}
|
||||
|
||||
event.subsecond = 0;
|
||||
@ -667,19 +656,19 @@ static movement_event_type_t _figure_out_button_event(bool pin_level, movement_e
|
||||
}
|
||||
|
||||
void cb_light_btn_interrupt(void) {
|
||||
bool pin_level = watch_get_pin_level(BTN_LIGHT);
|
||||
bool pin_level = HAL_GPIO_BTN_LIGHT_read();
|
||||
_movement_reset_inactivity_countdown();
|
||||
event.event_type = _figure_out_button_event(pin_level, EVENT_LIGHT_BUTTON_DOWN, &movement_state.light_down_timestamp);
|
||||
}
|
||||
|
||||
void cb_mode_btn_interrupt(void) {
|
||||
bool pin_level = watch_get_pin_level(BTN_MODE);
|
||||
bool pin_level = HAL_GPIO_BTN_MODE_read();
|
||||
_movement_reset_inactivity_countdown();
|
||||
event.event_type = _figure_out_button_event(pin_level, EVENT_MODE_BUTTON_DOWN, &movement_state.mode_down_timestamp);
|
||||
}
|
||||
|
||||
void cb_alarm_btn_interrupt(void) {
|
||||
bool pin_level = watch_get_pin_level(BTN_ALARM);
|
||||
bool pin_level = HAL_GPIO_BTN_ALARM_read();
|
||||
_movement_reset_inactivity_countdown();
|
||||
event.event_type = _figure_out_button_event(pin_level, EVENT_ALARM_BUTTON_DOWN, &movement_state.alarm_down_timestamp);
|
||||
}
|
||||
@ -22,8 +22,8 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MOVEMENT_H_
|
||||
#define MOVEMENT_H_
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "watch.h"
|
||||
@ -312,5 +312,3 @@ void movement_play_alarm(void);
|
||||
void movement_play_alarm_beeps(uint8_t rounds, BuzzerNote alarm_note);
|
||||
|
||||
uint8_t movement_claim_backup_register(void);
|
||||
|
||||
#endif // MOVEMENT_H_
|
||||
91
movement_config.h
Normal file
91
movement_config.h
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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,
|
||||
set_time_face,
|
||||
};
|
||||
|
||||
#define MOVEMENT_NUM_FACES (sizeof(watch_faces) / sizeof(watch_face_t))
|
||||
|
||||
/* Determines what face to go to from the first face on long press of the Mode button.
|
||||
* Also excludes these faces from the normal rotation.
|
||||
* In the default firmware, this lets you access temperature and battery voltage with a long press of Mode.
|
||||
* 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)
|
||||
|
||||
/* Custom hourly chime tune. Check movement_custom_signal_tunes.h for options. */
|
||||
#define SIGNAL_TUNE_DEFAULT
|
||||
|
||||
/* 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
|
||||
|
||||
/* Set to true for 24h mode or false for 12h mode */
|
||||
#define MOVEMENT_DEFAULT_24H_MODE false
|
||||
|
||||
/* Enable or disable the sound on mode button press */
|
||||
#define MOVEMENT_DEFAULT_BUTTON_SOUND true
|
||||
|
||||
/* Set the timeout before switching back to the main watch face
|
||||
* Valid values are:
|
||||
* 0: 60 seconds
|
||||
* 1: 2 minutes
|
||||
* 2: 5 minutes
|
||||
* 3: 30 minutes
|
||||
*/
|
||||
#define MOVEMENT_DEFAULT_TIMEOUT_INTERVAL 0
|
||||
|
||||
/* Set the timeout before switching to low energy mode
|
||||
* Valid values are:
|
||||
* 0: Never
|
||||
* 1: 1 hour
|
||||
* 2: 2 hours
|
||||
* 3: 6 hours
|
||||
* 4: 12 hours
|
||||
* 5: 1 day
|
||||
* 6: 2 days
|
||||
* 7: 7 days
|
||||
*/
|
||||
#define MOVEMENT_DEFAULT_LOW_ENERGY_INTERVAL 1
|
||||
|
||||
/* Set the led duration
|
||||
* Valid values are:
|
||||
* 0: No LED
|
||||
* 1: 1 second
|
||||
* 2: 3 seconds
|
||||
* 3: 5 seconds
|
||||
*/
|
||||
#define MOVEMENT_DEFAULT_LED_DURATION 1
|
||||
|
||||
#endif // MOVEMENT_CONFIG_H_
|
||||
29
movement_faces.h
Normal file
29
movement_faces.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "simple_clock_face.h"
|
||||
#include "set_time_face.h"
|
||||
// New includes go above this line.
|
||||
3
watch-faces.mk
Normal file
3
watch-faces.mk
Normal file
@ -0,0 +1,3 @@
|
||||
SRCS += \
|
||||
./watch-faces/clock/simple_clock_face.c \
|
||||
./watch-faces/settings/set_time_face.c \
|
||||
@ -26,7 +26,7 @@
|
||||
#include "simple_clock_face.h"
|
||||
#include "watch.h"
|
||||
#include "watch_utility.h"
|
||||
#include "watch_private_display.h"
|
||||
#include "watch_common_display.h"
|
||||
|
||||
static void _update_alarm_indicator(bool settings_alarm_enabled, simple_clock_state_t *state) {
|
||||
state->alarm_enabled = settings_alarm_enabled;
|
||||
@ -92,7 +92,7 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
|
||||
switch (event.event_type) {
|
||||
case EVENT_TICK:
|
||||
if (_quick_ticks_running) {
|
||||
if (watch_get_pin_level(BTN_ALARM)) _handle_alarm_button(settings, date_time, current_page);
|
||||
if (HAL_GPIO_BTN_ALARM_read()) _handle_alarm_button(settings, date_time, current_page);
|
||||
else _abort_quick_ticks();
|
||||
}
|
||||
break;
|
||||
Loading…
x
Reference in New Issue
Block a user