Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
719 changes: 713 additions & 6 deletions .clang-format

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/*.template.c
**/*.template.h
sdk/defaults/lib/lib.c
sdk/defaults/lib/lib.h
tools/clar/*
tests/**
11 changes: 11 additions & 0 deletions .github/workflows/compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,14 @@ jobs:
echo " /* SPDX-License-Identifier: Apache-2.0 */"
exit 1
fi

clang-format:
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Run clang-format
uses: jidicula/clang-format-action@v4.18.0
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
Window *window;
TextLayer *text_layer;

AppTimer* s_timer;
AppTimer *s_timer;
static AccelData s_last_accel_data;

static uint32_t prv_compute_delta_pos(AccelData *cur_pos, AccelData *last_pos) {
return (abs(last_pos->x - cur_pos->x) + abs(last_pos->y - cur_pos->y) +
abs(last_pos->z - cur_pos->z));
abs(last_pos->z - cur_pos->z));
}

static void prv_timer_cb(void *data) {
Expand All @@ -33,11 +33,11 @@ static void prv_timer_cb(void *data) {
int32_t delta = prv_compute_delta_pos(&accel_data, &s_last_accel_data);
s_last_accel_data = accel_data;

snprintf(accel_text, sizeof(accel_text), "Accel delta: %"PRIu32, delta);
snprintf(accel_text, sizeof(accel_text), "Accel delta: %" PRIu32, delta);
APP_LOG(APP_LOG_LEVEL_INFO, accel_text);
#else
snprintf(accel_text, sizeof(accel_text), "x:%"PRId16 ", y:%"PRId16 ", z:%"PRId16,
accel_data.x, accel_data.y, accel_data.z);
snprintf(accel_text, sizeof(accel_text), "x:%" PRId16 ", y:%" PRId16 ", z:%" PRId16, accel_data.x,
accel_data.y, accel_data.z);
APP_LOG(APP_LOG_LEVEL_INFO, accel_text);
#endif
text_layer_set_text(text_layer, accel_text);
Expand All @@ -50,8 +50,8 @@ void handle_init(void) {
GRect bounds = layer_get_bounds(window_layer);
uint32_t text_width = bounds.size.w;
uint32_t text_height = 28;
text_layer = text_layer_create(GRect(0, bounds.size.h/2 - text_height/2,
text_width, text_height));
text_layer =
text_layer_create(GRect(0, bounds.size.h / 2 - text_height / 2, text_width, text_height));

// Set the text, font, and text alignment
text_layer_set_text(text_layer, "No Accelerometer");
Expand Down
2 changes: 1 addition & 1 deletion apps/samples/app_heap_demo/src/app_heap_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <pebble.h>

#define ALLOC_SIZE 2048
#define ALLOC_SIZE 2048

static Window *window;
static TextLayer *text_heap_info;
Expand Down
15 changes: 7 additions & 8 deletions apps/samples/app_messages_test/src/app_message_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
static Window *s_window;
static TextLayer *s_text_layer;


enum {
DICT_KEY_TEST_0 = 0x0,
};
Expand All @@ -31,7 +30,7 @@ static int send_app_msg(void) {
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
int result;
APP_LOG(APP_LOG_LEVEL_DEBUG, "Sending messages");
for (int i=0; i<10; i++) {
for (int i = 0; i < 10; i++) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "app sending outbox");
do {
result = send_app_msg();
Expand All @@ -42,7 +41,7 @@ static void select_click_handler(ClickRecognizerRef recognizer, void *context) {

static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
text_layer_set_text(s_text_layer, "Up");
for (int i=0; i<10; i++) {
for (int i = 0; i < 10; i++) {
APP_LOG(APP_LOG_LEVEL_INFO, "sending BT log message");
}
}
Expand Down Expand Up @@ -82,7 +81,7 @@ static void window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window);
GRect bounds = layer_get_bounds(window_layer);

s_text_layer = text_layer_create((GRect) { .origin = { 0, 72 }, .size = { bounds.size.w, 20 } });
s_text_layer = text_layer_create((GRect){.origin = {0, 72}, .size = {bounds.size.w, 20}});
text_layer_set_text(s_text_layer, "Press a button");
text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter);
layer_add_child(window_layer, text_layer_get_layer(s_text_layer));
Expand All @@ -95,10 +94,10 @@ static void init(void) {
s_window = window_create();
app_message_init();
window_set_click_config_provider(s_window, click_config_provider);
window_set_window_handlers(s_window, (WindowHandlers) {
.load = window_load,
.unload = window_unload,
});
window_set_window_handlers(s_window, (WindowHandlers){
.load = window_load,
.unload = window_unload,
});
const bool animated = true;
window_stack_push(s_window, animated);
}
Expand Down
49 changes: 24 additions & 25 deletions apps/samples/bg_task_test/src/fg.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "pebble.h"
#include <inttypes.h>


Window *window;
TextLayer *text_layer;
Layer *line_layer;
Expand All @@ -18,21 +17,22 @@ static uint64_t prv_ms(void) {
return ((uint64_t)cur_sec * 1000) + cur_ms;
}


static void steps_event_handler(uint16_t type, AppWorkerMessage *data) {
//APP_LOG(APP_LOG_LEVEL_DEBUG, "Received new worker event. type: %d, data: %d, %d, %d", (int)type, (int)data->data0,
// (int)data->data1, (int)data->data2);
// APP_LOG(APP_LOG_LEVEL_DEBUG, "Received new worker event. type: %d, data: %d, %d, %d",
// (int)type, (int)data->data0,
// (int)data->data1, (int)data->data2);

if (type == 0) {
snprintf(g_text, sizeof(g_text), "%5d %5d %5d", (int)data->data0, (int)data->data1, (int)data->data2);
snprintf(g_text, sizeof(g_text), "%5d %5d %5d", (int)data->data0, (int)data->data1,
(int)data->data2);
text_layer_set_text(text_layer, g_text);
} else if (type == 1) {
snprintf(g_text, sizeof(g_text), "BAT: %d, %d, %d", (int)data->data0, (int)data->data1, (int)data->data2);
snprintf(g_text, sizeof(g_text), "BAT: %d, %d, %d", (int)data->data0, (int)data->data1,
(int)data->data2);
text_layer_set_text(text_layer, g_text);
}
}


static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
AppWorkerResult result = app_worker_launch();
APP_LOG(APP_LOG_LEVEL_INFO, "launch result: %d", result);
Expand All @@ -57,11 +57,10 @@ static void click_config_provider(void *context) {

static uint32_t s_seconds_count;
void handle_second_tick(struct tm *tick_time, TimeUnits units_changed) {

bool running = app_worker_is_running();

if (false) {
const char* status = "not";
const char *status = "not";
if (running) {
status = "is";
}
Expand All @@ -77,12 +76,11 @@ void handle_second_tick(struct tm *tick_time, TimeUnits units_changed) {
}

static void health_event_handler(HealthEventType event, void *context) {
APP_LOG(APP_LOG_LEVEL_INFO, "app: Got health event update. event_id: %"PRIu32"",
(uint32_t) event);
APP_LOG(APP_LOG_LEVEL_INFO, "app: Got health event update. event_id: %" PRIu32 "",
(uint32_t)event);
if (event == HealthEventMovementUpdate) {
HealthValue steps = health_service_sum_today(HealthMetricStepCount);
APP_LOG(APP_LOG_LEVEL_INFO, "app: movement event, steps: %"PRIu32"",
(uint32_t)steps);
APP_LOG(APP_LOG_LEVEL_INFO, "app: movement event, steps: %" PRIu32 "", (uint32_t)steps);

// Test getting historical steps
time_t day_start = time_start_of_today();
Expand All @@ -102,7 +100,6 @@ static void health_event_handler(HealthEventType event, void *context) {
steps = health_service_sum(HealthMetricStepCount, day_start - (SECONDS_PER_DAY / 2), day_start);
APP_LOG(APP_LOG_LEVEL_INFO, "steps 2nd half of yesterday: %d", (int)steps);


// Test the get_minute_history call

const int minute_data_len = 10;
Expand All @@ -116,20 +113,23 @@ static void health_event_handler(HealthEventType event, void *context) {
uint64_t elapsed_ms = prv_ms() - start_ms;

int num_records_returned = (utc_end - utc_start) / SECONDS_PER_MINUTE;
APP_LOG(APP_LOG_LEVEL_INFO, "app: Retrieved %d minute records in %"PRIu32" ms:",
num_records_returned, (uint32_t)elapsed_ms);
APP_LOG(APP_LOG_LEVEL_INFO,
"app: Retrieved %d minute records in %" PRIu32 " ms:", num_records_returned,
(uint32_t)elapsed_ms);
for (int i = 0; i < num_records_returned; i++) {
APP_LOG(APP_LOG_LEVEL_INFO, " steps: %"PRIu8", orient: 0x%"PRIx8", vmc: %"PRIu16", "
"light: %d, valid: %d", minute_data[i].steps, minute_data[i].orientation,
minute_data[i].vmc, (int)minute_data[i].light, (int)(!minute_data[i].is_invalid));
APP_LOG(APP_LOG_LEVEL_INFO,
" steps: %" PRIu8 ", orient: 0x%" PRIx8 ", vmc: %" PRIu16
", "
"light: %d, valid: %d",
minute_data[i].steps, minute_data[i].orientation, minute_data[i].vmc,
(int)minute_data[i].light, (int)(!minute_data[i].is_invalid));
}


} else if (event == HealthEventSleepUpdate) {
HealthValue total_sleep = health_service_sum_today(HealthMetricSleepSeconds);
HealthValue restful_sleep = health_service_sum_today(HealthMetricSleepRestfulSeconds);
APP_LOG(APP_LOG_LEVEL_INFO, "app: New sleep event: total: %"PRIu32", restful: %"PRIu32" ",
total_sleep / SECONDS_PER_MINUTE, restful_sleep / SECONDS_PER_MINUTE);
APP_LOG(APP_LOG_LEVEL_INFO, "app: New sleep event: total: %" PRIu32 ", restful: %" PRIu32 " ",
total_sleep / SECONDS_PER_MINUTE, restful_sleep / SECONDS_PER_MINUTE);
}
}

Expand All @@ -147,7 +147,7 @@ void handle_init(void) {

Layer *window_layer = window_get_root_layer(window);

text_layer = text_layer_create(GRect(7, 40, 144-7, 168-40));
text_layer = text_layer_create(GRect(7, 40, 144 - 7, 168 - 40));
text_layer_set_text_color(text_layer, GColorWhite);
text_layer_set_background_color(text_layer, GColorClear);
text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
Expand All @@ -170,11 +170,10 @@ void handle_init(void) {
health_service_events_subscribe(health_event_handler, NULL);
}


int main(void) {
handle_init();

app_event_loop();

handle_deinit();
}
48 changes: 20 additions & 28 deletions apps/samples/bg_task_test/worker_src/bg.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

#define BREAKPOINT __asm("bkpt")

#define ACCEL_BATCH_SIZE 10
#define ACCEL_BATCH_SIZE 10
#define PERSIST_WRITE_PERIOD_MS 1000

// -------------------------------------------------------------------------------------------------
static void prv_assert(bool condition, const char* msg) {
static void prv_assert(bool condition, const char *msg) {
if (!condition) {
APP_LOG(APP_LOG_LEVEL_ERROR, msg);

Expand All @@ -23,80 +23,75 @@ static void prv_assert(bool condition, const char* msg) {

// -----------------------------------------------------------------------------------------------
void handle_accel(AccelRawData *accel_data, uint32_t num_samples, uint64_t timestamp) {

// Display data
//for (uint32_t i=0; i<num_samples; i++) {
// APP_LOG(APP_LOG_LEVEL_INFO, "Got accel data: %d, %d, %d", accel_data[i].x, accel_data[i].y, accel_data[i].z);
// for (uint32_t i=0; i<num_samples; i++) {
// APP_LOG(APP_LOG_LEVEL_INFO, "Got accel data: %d, %d, %d", accel_data[i].x, accel_data[i].y,
// accel_data[i].z);
//}

// Publish new steps count
AppWorkerMessage steps_data = {
.data0 = accel_data[0].x,
.data1 = accel_data[0].y,
.data2 = accel_data[0].z,
.data0 = accel_data[0].x,
.data1 = accel_data[0].y,
.data2 = accel_data[0].z,
};
app_worker_send_message(0 /*type*/, &steps_data);
}

// -----------------------------------------------------------------------------------------------
static void update_persist_callback(void* context) {
static void update_persist_callback(void *context) {
int value = persist_read_int(42);
// APP_LOG(APP_LOG_LEVEL_INFO, "Updating persist value from %d to %d", value, value + 1);
persist_write_int(42, value + 1);
app_timer_register(PERSIST_WRITE_PERIOD_MS /*ms*/, update_persist_callback, NULL);
}


// -----------------------------------------------------------------------------------------------
static void battery_state_handler(BatteryChargeState charge) {
APP_LOG(APP_LOG_LEVEL_INFO, "got battery state service update");
APP_LOG(APP_LOG_LEVEL_INFO, "percent: %d, is_charging: %d, is_plugged: %d", charge.charge_percent,
charge.is_charging, charge.is_plugged);
charge.is_charging, charge.is_plugged);

AppWorkerMessage battery_data = {
.data0 = charge.charge_percent,
.data1 = charge.is_charging,
.data2 = charge.is_plugged,
.data0 = charge.charge_percent,
.data1 = charge.is_charging,
.data2 = charge.is_plugged,
};
app_worker_send_message(1 /*type*/, &battery_data);
}


// -----------------------------------------------------------------------------------------------
static void connection_handler(bool connected) {
APP_LOG(APP_LOG_LEVEL_INFO, "got phone connection update");
APP_LOG(APP_LOG_LEVEL_INFO, "connected: %d", connected);
}


// -----------------------------------------------------------------------------------------------
static void tick_timer_handler(struct tm *tick_time, TimeUnits units_changed) {
APP_LOG(APP_LOG_LEVEL_INFO, "got tick timer update");
}


// -----------------------------------------------------------------------------------------------
static void worker_message_handler(uint16_t type, AppWorkerMessage *data) {
if (type == 'x') {
prv_assert(0, "crashing");
}
}


// -----------------------------------------------------------------------------------------------
static void health_event_handler(HealthEventType event, void *context) {
APP_LOG(APP_LOG_LEVEL_INFO, "worker: Got health event update. event_id: %"PRIu32"",
(uint32_t) event);
APP_LOG(APP_LOG_LEVEL_INFO, "worker: Got health event update. event_id: %" PRIu32 "",
(uint32_t)event);
if (event == HealthEventMovementUpdate) {
HealthValue steps = health_service_sum_today(HealthMetricStepCount);
APP_LOG(APP_LOG_LEVEL_INFO, "worker: movement event, steps: %"PRIu32"",
(uint32_t)steps);
APP_LOG(APP_LOG_LEVEL_INFO, "worker: movement event, steps: %" PRIu32 "", (uint32_t)steps);

} else if (event == HealthEventSleepUpdate) {
HealthValue total_sleep = health_service_sum_today(HealthMetricSleepSeconds);
HealthValue restful_sleep = health_service_sum_today(HealthMetricSleepRestfulSeconds);
APP_LOG(APP_LOG_LEVEL_INFO, "worker: New sleep event: total: %"PRIu32", restful: %"PRIu32" ",
total_sleep / SECONDS_PER_MINUTE, restful_sleep / SECONDS_PER_MINUTE);
APP_LOG(APP_LOG_LEVEL_INFO,
"worker: New sleep event: total: %" PRIu32 ", restful: %" PRIu32 " ",
total_sleep / SECONDS_PER_MINUTE, restful_sleep / SECONDS_PER_MINUTE);
}
}

Expand All @@ -111,9 +106,7 @@ int main(void) {

battery_state_service_subscribe(battery_state_handler);

ConnectionHandlers conn_handlers = {
.pebble_app_connection_handler = connection_handler
};
ConnectionHandlers conn_handlers = {.pebble_app_connection_handler = connection_handler};
connection_service_subscribe(conn_handlers);

tick_timer_service_subscribe(MINUTE_UNIT, tick_timer_handler);
Expand All @@ -128,4 +121,3 @@ int main(void) {
accel_data_service_unsubscribe();
health_service_events_unsubscribe();
}

Loading