track stationary, not active minutes
This commit is contained in:
parent
b00faa2b03
commit
3e6079a24b
13
movement.c
13
movement.c
@ -79,7 +79,7 @@ void cb_tick(void);
|
||||
void cb_accelerometer_event(void);
|
||||
void cb_accelerometer_sleep_change(void);
|
||||
uint32_t orientation_changes = 0;
|
||||
uint8_t active_minutes = 0;
|
||||
uint8_t stationary_minutes = 0;
|
||||
#endif
|
||||
|
||||
#if __EMSCRIPTEN__
|
||||
@ -160,7 +160,7 @@ static void _movement_handle_top_of_minute(void) {
|
||||
|
||||
#ifdef HAS_ACCELEROMETER
|
||||
// every minute, we want to log whether the accelerometer is asleep or awake.
|
||||
if (!HAL_GPIO_A4_read()) active_minutes++;
|
||||
if (HAL_GPIO_A4_read()) stationary_minutes++;
|
||||
#endif
|
||||
|
||||
// update the DST offset cache every 30 minutes, since someplace in the world could change.
|
||||
@ -925,7 +925,7 @@ void cb_tick(void) {
|
||||
watch_date_time_t date_time = watch_rtc_get_date_time();
|
||||
if (date_time.unit.second != movement_state.last_second) {
|
||||
// TODO: can we consolidate these two ticks?
|
||||
if (movement_state.settings.bit.le_interval && movement_state.le_mode_ticks > 0) movement_state.le_mode_ticks--;
|
||||
if (movement_state.le_mode_ticks > 0) movement_state.le_mode_ticks--;
|
||||
if (movement_state.timeout_ticks > 0) movement_state.timeout_ticks--;
|
||||
|
||||
movement_state.last_second = date_time.unit.second;
|
||||
@ -956,12 +956,9 @@ void cb_accelerometer_sleep_change(void) {
|
||||
printf("Sleep on INT2\n");
|
||||
} else {
|
||||
event.event_type = EVENT_ACCELEROMETER_WAKE;
|
||||
// reset the stationary minutes counter; we're counting consecutive stationary minutes.
|
||||
stationary_minutes = 0;
|
||||
printf("Wake on INT2\n");
|
||||
// Not sure if it's useful to know what axis exceeded the threshold, but here's that:
|
||||
// uint8_t int_src = lis2dw_get_wakeup_source();
|
||||
// if (int_src & LIS2DW_WAKE_UP_SRC_VAL_X_WU) printf("Wake on X\n");
|
||||
// if (int_src & LIS2DW_WAKE_UP_SRC_VAL_Y_WU) printf("Wake on Y\n");
|
||||
// if (int_src & LIS2DW_WAKE_UP_SRC_VAL_Z_WU) printf("Wake on Z\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -42,7 +42,6 @@
|
||||
#include "set_time_face.h"
|
||||
#include "preferences_face.h"
|
||||
#include "light_sensor_face.h"
|
||||
#include "accelerometer_sleep_state_face.h"
|
||||
#include "irda_demo_face.h"
|
||||
#include "chirpy_demo_face.h"
|
||||
// New includes go above this line.
|
||||
|
||||
@ -17,7 +17,6 @@ SRCS += \
|
||||
./watch-faces/settings/set_time_face.c \
|
||||
./watch-faces/settings/preferences_face.c \
|
||||
./watch-faces/demo/light_sensor_face.c \
|
||||
./watch-faces/demo/accelerometer_sleep_state_face.c \
|
||||
./watch-faces/demo/irda_demo_face.c \
|
||||
./watch-faces/io/chirpy_demo_face.c \
|
||||
# New watch faces go above this line.
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
// hacky: we're just tapping into Movement's global state.
|
||||
// we should make better API for this.
|
||||
extern uint32_t orientation_changes;
|
||||
extern uint8_t active_minutes;
|
||||
extern uint8_t stationary_minutes;
|
||||
|
||||
static void _accel_interrupt_count_face_update_display(accel_interrupt_count_state_t *state) {
|
||||
(void) state;
|
||||
@ -48,7 +48,7 @@ static void _accel_interrupt_count_face_update_display(accel_interrupt_count_sta
|
||||
else watch_display_text(WATCH_POSITION_TOP_RIGHT, " A");
|
||||
|
||||
// Orientation changes / active minutes
|
||||
sprintf(buf, "%-3lu/%2d", orientation_changes > 999 ? 999 : orientation_changes, active_minutes);
|
||||
sprintf(buf, "%-3lu/%2d", orientation_changes > 999 ? 999 : orientation_changes, stationary_minutes);
|
||||
watch_display_text(WATCH_POSITION_BOTTOM, buf);
|
||||
}
|
||||
|
||||
|
||||
@ -1,102 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 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 <string.h>
|
||||
#include "accelerometer_sleep_state_face.h"
|
||||
|
||||
void accelerometer_sleep_state_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
||||
(void) watch_face_index;
|
||||
(void) context_ptr;
|
||||
}
|
||||
|
||||
void accelerometer_sleep_state_face_activate(void *context) {
|
||||
(void) context;
|
||||
movement_request_tick_frequency(8);
|
||||
}
|
||||
|
||||
bool accelerometer_sleep_state_face_loop(movement_event_t event, void *context) {
|
||||
(void) context;
|
||||
char buf[7];
|
||||
char state[4];
|
||||
|
||||
switch (event.event_type) {
|
||||
case EVENT_ACTIVATE:
|
||||
watch_display_text(WATCH_POSITION_TOP_LEFT, "A3");
|
||||
watch_set_colon();
|
||||
// fall through
|
||||
case EVENT_TICK:
|
||||
if (HAL_GPIO_A3_read()) {
|
||||
strcpy(state, "SLP");
|
||||
printf("1\n");
|
||||
} else {
|
||||
strcpy(state, "Act");
|
||||
printf("0\n");
|
||||
}
|
||||
sprintf(buf, "ac %s", state);
|
||||
// printf("%s\n", buf);
|
||||
watch_display_text(WATCH_POSITION_BOTTOM, buf);
|
||||
// If needed, update your display here.
|
||||
break;
|
||||
case EVENT_LIGHT_BUTTON_UP:
|
||||
// You can use the Light button for your own purposes. Note that by default, Movement will also
|
||||
// illuminate the LED in response to EVENT_LIGHT_BUTTON_DOWN; to suppress that behavior, add an
|
||||
// empty case for EVENT_LIGHT_BUTTON_DOWN.
|
||||
break;
|
||||
case EVENT_ALARM_BUTTON_UP:
|
||||
// Just in case you have need for another button.
|
||||
break;
|
||||
case EVENT_TIMEOUT:
|
||||
// Your watch face will receive this event after a period of inactivity. If it makes sense to resign,
|
||||
// you may uncomment this line to move back to the first watch face in the list:
|
||||
// movement_move_to_face(0);
|
||||
break;
|
||||
case EVENT_LOW_ENERGY_UPDATE:
|
||||
// If you did not resign in EVENT_TIMEOUT, you can use this event to update the display once a minute.
|
||||
// Avoid displaying fast-updating values like seconds, since the display won't update again for 60 seconds.
|
||||
// You should also consider starting the tick animation, to show the wearer that this is sleep mode:
|
||||
// watch_start_sleep_animation(500);
|
||||
break;
|
||||
default:
|
||||
// Movement's default loop handler will step in for any cases you don't handle above:
|
||||
// * EVENT_LIGHT_BUTTON_DOWN lights the LED
|
||||
// * EVENT_MODE_BUTTON_UP moves to the next watch face in the list
|
||||
// * EVENT_MODE_LONG_PRESS returns to the first watch face (or skips to the secondary watch face, if configured)
|
||||
// You can override any of these behaviors by adding a case for these events to this switch statement.
|
||||
return movement_default_loop_handler(event);
|
||||
}
|
||||
|
||||
// return true if the watch can enter standby mode. Generally speaking, you should always return true.
|
||||
// Exceptions:
|
||||
// * If you are displaying a color using the low-level watch_set_led_color function, you should return false.
|
||||
// * If you are sounding the buzzer using the low-level watch_set_buzzer_on function, you should return false.
|
||||
// Note that if you are driving the LED or buzzer using Movement functions like movement_illuminate_led or
|
||||
// movement_play_alarm, you can still return true. This guidance only applies to the low-level watch_ functions.
|
||||
return true;
|
||||
}
|
||||
|
||||
void accelerometer_sleep_state_face_resign(void *context) {
|
||||
(void) context;
|
||||
}
|
||||
|
||||
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "movement.h"
|
||||
|
||||
/*
|
||||
* A DESCRIPTION OF YOUR WATCH FACE
|
||||
*
|
||||
* and a description of how use it
|
||||
*
|
||||
*/
|
||||
|
||||
void accelerometer_sleep_state_face_setup(uint8_t watch_face_index, void ** context_ptr);
|
||||
void accelerometer_sleep_state_face_activate(void *context);
|
||||
bool accelerometer_sleep_state_face_loop(movement_event_t event, void *context);
|
||||
void accelerometer_sleep_state_face_resign(void *context);
|
||||
|
||||
#define accelerometer_sleep_state_face ((const watch_face_t){ \
|
||||
accelerometer_sleep_state_face_setup, \
|
||||
accelerometer_sleep_state_face_activate, \
|
||||
accelerometer_sleep_state_face_loop, \
|
||||
accelerometer_sleep_state_face_resign, \
|
||||
NULL, \
|
||||
})
|
||||
@ -33,7 +33,7 @@
|
||||
// hacky: we're just tapping into Movement's global state.
|
||||
// we should make better API for this.
|
||||
extern uint32_t orientation_changes;
|
||||
extern uint8_t active_minutes;
|
||||
extern uint8_t stationary_minutes;
|
||||
|
||||
static void _activity_logging_face_log_data(activity_logging_state_t *state) {
|
||||
watch_date_time_t date_time = movement_get_local_date_time();
|
||||
@ -44,7 +44,7 @@ static void _activity_logging_face_log_data(activity_logging_state_t *state) {
|
||||
data_point.bit.month = date_time.unit.month;
|
||||
data_point.bit.hour = date_time.unit.hour;
|
||||
data_point.bit.minute = date_time.unit.minute;
|
||||
data_point.bit.active_minutes = active_minutes;
|
||||
data_point.bit.stationary_minutes = stationary_minutes;
|
||||
data_point.bit.orientation_changes = orientation_changes;
|
||||
// print size of thing
|
||||
printf("Size of data point: %d\n", sizeof(activity_logging_data_point_t));
|
||||
@ -57,7 +57,7 @@ static void _activity_logging_face_log_data(activity_logging_state_t *state) {
|
||||
state->data[pos].reg = data_point.reg;
|
||||
state->data_points++;
|
||||
|
||||
active_minutes = 0;
|
||||
stationary_minutes = 0;
|
||||
orientation_changes = 0;
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ static void _activity_logging_face_update_display(activity_logging_state_t *stat
|
||||
watch_display_text(WATCH_POSITION_TOP, "AC");
|
||||
sprintf(buf, "%2d", state->display_index);
|
||||
watch_display_text(WATCH_POSITION_TOP_RIGHT, buf);
|
||||
sprintf(buf, "%-3u/%2d", state->data[pos].bit.orientation_changes > 999 ? 999 : state->data[pos].bit.orientation_changes, state->data[pos].bit.active_minutes);
|
||||
sprintf(buf, "%-3u/%2d", state->data[pos].bit.orientation_changes > 999 ? 999 : state->data[pos].bit.orientation_changes, state->data[pos].bit.stationary_minutes);
|
||||
watch_display_text(WATCH_POSITION_BOTTOM, buf);
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ typedef union {
|
||||
uint32_t month: 4;
|
||||
uint32_t hour: 5;
|
||||
uint32_t minute: 6;
|
||||
uint32_t active_minutes: 3;
|
||||
uint32_t stationary_minutes: 3;
|
||||
uint32_t orientation_changes: 9;
|
||||
} bit;
|
||||
uint32_t reg;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user