Skip to content

Commit

Permalink
bring in Chirpy face
Browse files Browse the repository at this point in the history
  • Loading branch information
joeycastillo committed Oct 22, 2024
1 parent e8b4d4d commit c0514ad
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 25 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ INCLUDES += \
-I./filesystem \
-I./shell \
-I./movement/lib/sunriset \
-I./movement/lib/chirpy_tx \
-I./watch-library/shared/watch \
-I./watch-library/shared/driver \
-I./watch-faces/clock \
-I./watch-faces/complication \
-I./watch-faces/demo \
-I./watch-faces/sensor \
-I./watch-faces/settings \
-I./watch-faces/io \

# Add your source files here.
SRCS += \
Expand All @@ -62,6 +64,7 @@ SRCS += \
./shell/shell.c \
./shell/shell_cmd_list.c \
./movement/lib/sunriset/sunriset.c \
./movement/lib/chirpy_tx/chirpy_tx.c \
./watch-library/shared/driver/thermistor_driver.c \
./watch-library/shared/watch/watch_common_buzzer.c \
./watch-library/shared/watch/watch_common_display.c \
Expand Down
1 change: 1 addition & 0 deletions movement_faces.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@
#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.
1 change: 1 addition & 0 deletions watch-faces.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ SRCS += \
./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.
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ static uint8_t short_data[] = {
0x00,
};

#define NANOSEC_INI_FILE_NAME "nanosec.ini"
#define ACTIVITY_DATA_FILE_NAME "activity.dat"

static uint8_t *nanosec_buffer = 0;
static uint16_t nanosec_buffer_size = 0;
static uint8_t *activity_buffer = 0;
static uint16_t activity_buffer_size = 0;

void chirpy_demo_face_setup(uint8_t watch_face_index, void **context_ptr) {
(void)watch_face_index;
Expand All @@ -113,39 +113,39 @@ void chirpy_demo_face_activate(void *context) {
state->mode = CDM_CHOOSE;
state->program = CDP_SCALE;

// Do we have nanosec data? Load it.
int32_t sz = filesystem_get_file_size(NANOSEC_INI_FILE_NAME);
// Do we have activity data? Load it.
int32_t sz = filesystem_get_file_size(ACTIVITY_DATA_FILE_NAME);
if (sz > 0) {
// We will free this in resign.
// I don't like any kind of dynamic allocation in long-running embedded software...
// But there's no way around it here; I don't want to hard-wire (and squat) any fixed size structure
// Nanosec data may change in the future too
nanosec_buffer_size = sz + 2;
nanosec_buffer = malloc(nanosec_buffer_size);
activity_buffer_size = sz + 2;
activity_buffer = malloc(activity_buffer_size);
// First two bytes of prefix, so Chirpy RX can recognize this data type
nanosec_buffer[0] = 0xc0;
nanosec_buffer[1] = 0x00;
activity_buffer[0] = 0xc0;
activity_buffer[1] = 0x00;
// Read file
filesystem_read_file(NANOSEC_INI_FILE_NAME, (char*)&nanosec_buffer[2], sz);
filesystem_read_file(ACTIVITY_DATA_FILE_NAME, (char*)&activity_buffer[2], sz);
}
}

// To create / check test file in emulator:
// echo TestData > nanosec.ini
// cat nanosec.ini
// echo TestData > activity.ini
// cat activity.ini

static void _cdf_update_lcd(chirpy_demo_state_t *state) {
watch_display_string("CH", 0);
watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "CH", "Chirp");
if (state->program == CDP_SCALE)
watch_display_string(" SCALE", 4);
watch_display_text(WATCH_POSITION_BOTTOM, " SCALE");
else if (state->program == CDP_INFO_SHORT)
watch_display_string("SHORT ", 4);
watch_display_text(WATCH_POSITION_BOTTOM, "SHORT ");
else if (state->program == CDP_INFO_LONG)
watch_display_string(" LOng ", 4);
watch_display_text(WATCH_POSITION_BOTTOM, " LOng ");
else if (state->program == CDP_INFO_NANOSEC)
watch_display_string("nAnO ", 4);
watch_display_text(WATCH_POSITION_BOTTOM, " ACtIV");
else
watch_display_string("---- ", 4);
watch_display_text(WATCH_POSITION_BOTTOM, "---- ");
}

static void _cdf_quit_chirping(chirpy_demo_state_t *state) {
Expand Down Expand Up @@ -224,8 +224,8 @@ static void _cdf_countdown_tick(void *context) {
curr_data_ptr = long_data_str;
curr_data_len = strlen((const char *)long_data_str);
} else if (state->program == CDP_INFO_NANOSEC) {
curr_data_ptr = nanosec_buffer;
curr_data_len = nanosec_buffer_size;
curr_data_ptr = activity_buffer;
curr_data_len = activity_buffer_size;
}
}
return;
Expand Down Expand Up @@ -276,7 +276,7 @@ bool chirpy_demo_face_loop(movement_event_t event, void *context) {
else if (state->program == CDP_INFO_SHORT)
state->program = CDP_INFO_LONG;
else if (state->program == CDP_INFO_LONG) {
if (nanosec_buffer_size > 0)
if (activity_buffer_size > 0)
state->program = CDP_INFO_NANOSEC;
else
state->program = CDP_SCALE;
Expand Down Expand Up @@ -323,9 +323,9 @@ bool chirpy_demo_face_loop(movement_event_t event, void *context) {
void chirpy_demo_face_resign(void *context) {
(void)context;

if (nanosec_buffer != 0) {
free(nanosec_buffer);
nanosec_buffer = 0;
nanosec_buffer_size = 0;
if (activity_buffer != 0) {
free(activity_buffer);
activity_buffer = 0;
activity_buffer_size = 0;
}
}
File renamed without changes.

0 comments on commit c0514ad

Please sign in to comment.