Skip to content

Commit

Permalink
first build of Second Movement with two watch faces
Browse files Browse the repository at this point in the history
  • Loading branch information
joeycastillo committed Sep 18, 2024
1 parent 24598ec commit dccad01
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 148 deletions.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 changes: 0 additions & 102 deletions app.c

This file was deleted.

67 changes: 28 additions & 39 deletions movement/movement.c → movement.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// 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"
#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

#include "movement_custom_signal_tunes.h"

// Default to no secondary face behaviour.
#ifndef MOVEMENT_SECONDARY_FACE_INDEX
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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();
Expand All @@ -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.
Expand Down Expand Up @@ -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();
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions movement/movement.h → movement.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* SOFTWARE.
*/

#ifndef MOVEMENT_H_
#define MOVEMENT_H_
#pragma once

#include <stdio.h>
#include <stdbool.h>
#include "watch.h"
Expand Down Expand Up @@ -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 changes: 91 additions & 0 deletions movement_config.h
Original file line number Diff line number Diff line change
@@ -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_
Loading

0 comments on commit dccad01

Please sign in to comment.