Import of the watch repository from Pebble

This commit is contained in:
Matthieu Jeanson 2024-12-12 16:43:03 -08:00 committed by Katharine Berry
commit 3b92768480
10334 changed files with 2564465 additions and 0 deletions

View file

@ -0,0 +1,23 @@
{
"uuid": "2a3352d5-2d44-437f-9652-98464640aeab",
"shortName": "AppMsgTest",
"longName": "AppMsgTest",
"companyName": "Pebble",
"versionCode": 1,
"versionLabel": "1.0",
"watchapp": {
"watchface": false
},
"appKeys": {
"test0": 0
},
"resources": {
"media": []
},
"targetPlatforms": [
"aplite",
"basalt",
"chalk"
],
"sdkVersion": "3"
}

View file

@ -0,0 +1,131 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <pebble.h>
static Window *s_window;
static TextLayer *s_text_layer;
enum {
DICT_KEY_TEST_0 = 0x0,
};
static int send_app_msg(void) {
Tuplet value = TupletInteger(DICT_KEY_TEST_0, 1);
DictionaryIterator *iter;
app_message_outbox_begin(&iter);
if (iter == NULL) {
return -1;
}
dict_write_tuplet(iter, &value);
dict_write_end(iter);
int result = app_message_outbox_send();
return result;
}
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++) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "app sending outbox");
do {
result = send_app_msg();
} while (result == -1);
APP_LOG(APP_LOG_LEVEL_DEBUG, "outbox result code: %d", result);
}
}
static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
text_layer_set_text(s_text_layer, "Up");
for (int i=0; i<10; i++) {
APP_LOG(APP_LOG_LEVEL_INFO, "sending BT log message");
}
}
static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
text_layer_set_text(s_text_layer, "Down");
}
static void click_config_provider(void *context) {
window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler);
window_single_click_subscribe(BUTTON_ID_UP, up_click_handler);
window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler);
}
static void in_received_handler(DictionaryIterator *iter, void *context) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "Received message");
}
static void in_dropped_handler(AppMessageResult reason, void *context) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "App Message Dropped!");
}
static void out_failed_handler(DictionaryIterator *failed, AppMessageResult reason, void *context) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "App Message Failed to Send!");
}
static void app_message_init(void) {
// Register message handlers
app_message_register_inbox_received(in_received_handler);
app_message_register_inbox_dropped(in_dropped_handler);
app_message_register_outbox_failed(out_failed_handler);
// Init buffers
app_message_open(64, 64);
}
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 } });
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));
}
static void window_unload(Window *window) {
}
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,
});
const bool animated = true;
window_stack_push(s_window, animated);
}
static void deinit(void) {
window_destroy(s_window);
text_layer_destroy(s_text_layer);
}
int main(void) {
init();
APP_LOG(APP_LOG_LEVEL_DEBUG, "Done initializing, pushed window: %p", s_window);
app_event_loop();
deinit();
}

View file

@ -0,0 +1,30 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Set callback for the app ready event
Pebble.addEventListener("ready",
function(e) {
console.log("connected!" + e.ready);
console.log(e.type);
});
// Set callback for appmessage events
Pebble.addEventListener("appmessage",
function(e) {
console.log("sending reply");
Pebble.sendAppMessage({"test0": "42"});
});

View file

@ -0,0 +1,48 @@
#
# This file is the default set of rules to compile a Pebble project.
#
# Feel free to customize this to your needs.
#
import os.path
top = '.'
out = 'build'
def options(ctx):
ctx.load('pebble_sdk')
def configure(ctx):
"""
This method is used to configure your build.
ctx.load(`pebble_sdk`) automatically configures a build for each valid platform in `targetPlatforms`.
Platform-specific configuration: add your change after calling ctx.load('pebble_sdk') and make sure to set the
correct environment first.
Universal configuration: add your change prior to calling ctx.load('pebble_sdk').
"""
ctx.load('pebble_sdk')
def build(ctx):
ctx.load('pebble_sdk')
build_worker = os.path.exists('worker_src')
binaries = []
for p in ctx.env.TARGET_PLATFORMS:
ctx.set_env(ctx.all_envs[p])
ctx.set_group(ctx.env.PLATFORM_NAME)
app_elf = '{}/pebble-app.elf'.format(ctx.env.BUILD_DIR)
ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'), target=app_elf)
if build_worker:
worker_elf = '{}/pebble-worker.elf'.format(ctx.env.BUILD_DIR)
binaries.append({'platform': p, 'app_elf': app_elf, 'worker_elf': worker_elf})
ctx.pbl_worker(source=ctx.path.ant_glob('worker_src/**/*.c'), target=worker_elf)
else:
binaries.append({'platform': p, 'app_elf': app_elf})
ctx.set_group('bundle')
ctx.pbl_bundle(binaries=binaries, js=ctx.path.ant_glob(['src/js/**/*.js', 'src/js/**/*.json']), js_entry_file='src/js/app.js')