} chirpy_demo_mode_t;
typedef enum {
- CDP_SCALE = 0,
+ CDP_CLEAR = 0,
CDP_INFO_SHORT,
CDP_INFO_LONG,
CDP_INFO_NANOSEC,
memset(context, 0, sizeof(chirpy_demo_state_t));
state->mode = CDM_CHOOSE;
- state->program = CDP_SCALE;
+ state->program = CDP_INFO_NANOSEC;
// Do we have activity data? Load it.
int32_t sz = filesystem_get_file_size(ACTIVITY_DATA_FILE_NAME);
activity_buffer_size = sz + 2;
activity_buffer = malloc(activity_buffer_size);
// First two bytes of prefix, so Chirpy RX can recognize this data type
- activity_buffer[0] = 0xc0;
+ activity_buffer[0] = 0x41;
activity_buffer[1] = 0x00;
// Read file
filesystem_read_file(ACTIVITY_DATA_FILE_NAME, (char*)&activity_buffer[2], sz);
static void _cdf_update_lcd(chirpy_demo_state_t *state) {
watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "CH", "Chirp");
- if (state->program == CDP_SCALE)
- watch_display_text(WATCH_POSITION_BOTTOM, " SCALE");
- else if (state->program == CDP_INFO_SHORT)
+ if (state->program == CDP_CLEAR) {
+ movement_force_led_on(255, 0, 0);
+ watch_display_text(WATCH_POSITION_BOTTOM, "CLEAR?");
+ } else if (state->program == CDP_INFO_SHORT) {
watch_display_text(WATCH_POSITION_BOTTOM, "SHORT ");
- else if (state->program == CDP_INFO_LONG)
+ } else if (state->program == CDP_INFO_LONG) {
watch_display_text(WATCH_POSITION_BOTTOM, " LOng ");
- else if (state->program == CDP_INFO_NANOSEC)
+ } else if (state->program == CDP_INFO_NANOSEC) {
watch_display_text(WATCH_POSITION_BOTTOM, " ACtIV");
- else
+ } else {
watch_display_text(WATCH_POSITION_BOTTOM, "---- ");
+ }
}
static void _cdf_quit_chirping(chirpy_demo_state_t *state) {
tick_state->tick_count = -1;
tick_state->seq_pos = 0;
// We'll be chirping out a scale
- if (state->program == CDP_SCALE) {
+ if (false) { // state->program == CDP_CLEAR) {
tick_state->tick_fun = _cdf_scale_tick;
}
// We'll be chirping out data
case EVENT_ALARM_BUTTON_UP:
// If in choose mode: select next program
if (state->mode == CDM_CHOOSE) {
- if (state->program == CDP_SCALE)
+ if (state->program == CDP_CLEAR)
state->program = CDP_INFO_SHORT;
else if (state->program == CDP_INFO_SHORT)
state->program = CDP_INFO_LONG;
if (activity_buffer_size > 0)
state->program = CDP_INFO_NANOSEC;
else
- state->program = CDP_SCALE;
+ state->program = CDP_CLEAR;
} else if (state->program == CDP_INFO_NANOSEC)
- state->program = CDP_SCALE;
+ state->program = CDP_CLEAR;
_cdf_update_lcd(state);
}
// If chirping: stoppit
case EVENT_ALARM_LONG_PRESS:
// If in choose mode: start chirping
if (state->mode == CDM_CHOOSE) {
- _cdm_setup_chirp(state);
+ if (state->program == CDP_CLEAR) {
+ filesystem_write_file("activity.dat", "", 0);
+ movement_force_led_off();
+ movement_move_to_next_face();
+ } else {
+ _cdm_setup_chirp(state);
+ }
}
break;
case EVENT_TICK:
#include <stdlib.h>
#include <string.h>
#include "activity_logging_face.h"
+#include "filesystem.h"
#include "watch.h"
#ifdef HAS_ACCELEROMETER
static void _activity_logging_face_log_data(activity_logging_state_t *state) {
watch_date_time_t date_time = movement_get_local_date_time();
size_t pos = state->data_points % ACTIVITY_LOGGING_NUM_DATA_POINTS;
+ activity_logging_data_point_t data_point = {0};
+
+ data_point.bit.day = date_time.unit.day;
+ 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.orientation_changes = orientation_changes;
+ // print size of thing
+ printf("Size of data point: %d\n", sizeof(activity_logging_data_point_t));
+ if (filesystem_append_file("activity.dat", (char *)&data_point, sizeof(activity_logging_data_point_t))) {
+ printf("Data point written\n", state->data_points);
+ } else {
+ printf("Failed to write data point\n");
+ }
+
+ state->data[pos].reg = data_point.reg;
+ state->data_points++;
- state->data[pos].timestamp.reg = date_time.reg;
- state->data[pos].active_minutes = active_minutes;
- state->data[pos].orientation_changes = orientation_changes;
active_minutes = 0;
orientation_changes = 0;
-
- state->data_points++;
}
static void _activity_logging_face_update_display(activity_logging_state_t *state, bool clock_mode_24h) {
watch_display_text(WATCH_POSITION_TOP_RIGHT, buf);
} else if (state->ts_ticks) {
// we are displaying the timestamp in response to a button press
- watch_date_time_t date_time = state->data[pos].timestamp;
watch_set_colon();
if (clock_mode_24h) {
watch_set_indicator(WATCH_INDICATOR_24H);
} else {
- if (date_time.unit.hour > 11) watch_set_indicator(WATCH_INDICATOR_PM);
- date_time.unit.hour %= 12;
- if (date_time.unit.hour == 0) date_time.unit.hour = 12;
+ if (state->data[pos].bit.hour > 11) watch_set_indicator(WATCH_INDICATOR_PM);
+ state->data[pos].bit.hour %= 12;
+ if (state->data[pos].bit.hour == 0) state->data[pos].bit.hour = 12;
}
watch_display_text(WATCH_POSITION_TOP_LEFT, "AT");
- sprintf(buf, "%2d", date_time.unit.day);
+ sprintf(buf, "%2d", state->data[pos].bit.day);
watch_display_text(WATCH_POSITION_TOP_RIGHT, buf);
- sprintf(buf, "%2d%02d%02d", date_time.unit.hour, date_time.unit.minute, date_time.unit.second);
+ sprintf(buf, "%2d%02d%02d", state->data[pos].bit.hour, state->data[pos].bit.minute, 0);
watch_display_text(WATCH_POSITION_BOTTOM, buf);
} else {
// we are displaying the number of accelerometer wakeups and orientation changes
watch_display_text(WATCH_POSITION_TOP, "AC");
sprintf(buf, "%2d", state->display_index);
watch_display_text(WATCH_POSITION_TOP_RIGHT, buf);
- sprintf(buf, "%-3lu/%2d", state->data[pos].orientation_changes > 999 ? 999 : state->data[pos].orientation_changes, state->data[pos].active_minutes);
+ sprintf(buf, "%-3lu/%2d", state->data[pos].bit.orientation_changes > 999 ? 999 : state->data[pos].bit.orientation_changes, state->data[pos].bit.active_minutes);
watch_display_text(WATCH_POSITION_BOTTOM, buf);
}
}
if (*context_ptr == NULL) {
*context_ptr = malloc(sizeof(activity_logging_state_t));
memset(*context_ptr, 0, sizeof(activity_logging_state_t));
+ // create file if it doesn't exist
+ if (!filesystem_file_exists("activity.dat")) filesystem_write_file("activity.dat", "", 0);
}
}
(void) context;
movement_watch_face_advisory_t retval = { 0 };
- // this will get called at the top of each minute, so all we check is if we're at the top of the hour as well.
- // if we are, we ask for a background task.
- retval.wants_background_task = watch_rtc_get_date_time().unit.minute == 0;
+ // log data every 5 minutes
+ retval.wants_background_task = (movement_get_local_date_time().unit.minute % 5) == 0;
return retval;
}