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

21
sdk/defaults/app/index.js Normal file
View file

@ -0,0 +1,21 @@
/**
* 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.
*/
Pebble.addEventListener("ready",
function(e) {
console.log("Hello world! - Sent from your javascript application.");
}
);

76
sdk/defaults/app/main.c Normal file
View file

@ -0,0 +1,76 @@
/*
* 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;
static void prv_select_click_handler(ClickRecognizerRef recognizer, void *context) {
text_layer_set_text(s_text_layer, "Select");
}
static void prv_up_click_handler(ClickRecognizerRef recognizer, void *context) {
text_layer_set_text(s_text_layer, "Up");
}
static void prv_down_click_handler(ClickRecognizerRef recognizer, void *context) {
text_layer_set_text(s_text_layer, "Down");
}
static void prv_click_config_provider(void *context) {
window_single_click_subscribe(BUTTON_ID_SELECT, prv_select_click_handler);
window_single_click_subscribe(BUTTON_ID_UP, prv_up_click_handler);
window_single_click_subscribe(BUTTON_ID_DOWN, prv_down_click_handler);
}
static void prv_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(0, 72, 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 prv_window_unload(Window *window) {
text_layer_destroy(s_text_layer);
}
static void prv_init(void) {
s_window = window_create();
window_set_click_config_provider(s_window, prv_click_config_provider);
window_set_window_handlers(s_window, (WindowHandlers) {
.load = prv_window_load,
.unload = prv_window_unload,
});
const bool animated = true;
window_stack_push(s_window, animated);
}
static void prv_deinit(void) {
window_destroy(s_window);
}
int main(void) {
prv_init();
APP_LOG(APP_LOG_LEVEL_DEBUG, "Done initializing, pushed window: %p", s_window);
app_event_loop();
prv_deinit();
}

View file

@ -0,0 +1,29 @@
{
"name": "${project_name}",
"author": "MakeAwesomeHappen",
"version": "1.0.0",
"keywords": ["pebble-app"],
"private": true,
"dependencies": {},
"pebble": {
"displayName": "${display_name}",
"uuid": "${uuid}",
"sdkVersion": "${sdk_version}",
"enableMultiJS": true,
"targetPlatforms": [
"aplite",
"basalt",
"chalk",
"diorite"
],
"watchapp": {
"watchface": false
},
"messageKeys": [
"dummy"
],
"resources": {
"media": []
}
}
}

21
sdk/defaults/app/simple.c Normal file
View file

@ -0,0 +1,21 @@
/*
* 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>
int main(void) {
app_event_loop();
}

21
sdk/defaults/app/worker.c Normal file
View file

@ -0,0 +1,21 @@
/*
* 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_worker.h>
int main(void) {
worker_event_loop();
}

54
sdk/defaults/app/wscript Normal file
View file

@ -0,0 +1,54 @@
#
# This file is the default set of rules to compile a Pebble application.
#
# 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 = []
cached_env = ctx.env
for platform in ctx.env.TARGET_PLATFORMS:
ctx.env = ctx.all_envs[platform]
ctx.set_group(ctx.env.PLATFORM_NAME)
app_elf = '{}/pebble-app.elf'.format(ctx.env.BUILD_DIR)
ctx.pbl_build(source=ctx.path.ant_glob('src/c/**/*.c'), target=app_elf, bin_type='app')
if build_worker:
worker_elf = '{}/pebble-worker.elf'.format(ctx.env.BUILD_DIR)
binaries.append({'platform': platform, 'app_elf': app_elf, 'worker_elf': worker_elf})
ctx.pbl_build(source=ctx.path.ant_glob('worker_src/c/**/*.c'),
target=worker_elf,
bin_type='worker')
else:
binaries.append({'platform': platform, 'app_elf': app_elf})
ctx.env = cached_env
ctx.set_group('bundle')
ctx.pbl_bundle(binaries=binaries,
js=ctx.path.ant_glob(['src/pkjs/**/*.js',
'src/pkjs/**/*.json',
'src/common/**/*.js']),
js_entry_file='src/pkjs/index.js')

View file

@ -0,0 +1,10 @@
# Ignore build generated files
build/
dist/
dist.zip
# Ignore waf lock file
.lock-waf*
# Ignore installed node modules
node_modules/

22
sdk/defaults/lib/lib.c Normal file
View file

@ -0,0 +1,22 @@
/*
* 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>
#include "${project_name}.h"
bool ${project_name_c}_find_truth(void) {
return true;
}

19
sdk/defaults/lib/lib.h Normal file
View file

@ -0,0 +1,19 @@
/*
* 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.
*/
#pragma once
bool ${project_name_c}_find_truth(void);

21
sdk/defaults/lib/lib.js Normal file
View file

@ -0,0 +1,21 @@
/**
* 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.
*/
var run_me = function(e) {
console.log("Look at me, I'm running!");
};
module.exports = run_me;

View file

@ -0,0 +1,21 @@
{
"name": "${project_name}",
"author": "MakeAwesomeHappen",
"version": "1.0.0",
"files": ["dist.zip"],
"keywords": ["pebble-package"],
"dependencies": {},
"pebble": {
"projectType": "package",
"sdkVersion": "${sdk_version}",
"targetPlatforms": [
"aplite",
"basalt",
"chalk",
"diorite"
],
"resources": {
"media": []
}
}
}

48
sdk/defaults/lib/wscript Normal file
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
import shutil
import waflib
top = '.'
out = 'build'
def distclean(ctx):
if os.path.exists('dist.zip'):
os.remove('dist.zip')
if os.path.exists('dist'):
shutil.rmtree('dist')
waflib.Scripting.distclean(ctx)
def options(ctx):
ctx.load('pebble_sdk_lib')
def configure(ctx):
ctx.load('pebble_sdk_lib')
def build(ctx):
ctx.load('pebble_sdk_lib')
cached_env = ctx.env
for platform in ctx.env.TARGET_PLATFORMS:
ctx.env = ctx.all_envs[platform]
ctx.set_group(ctx.env.PLATFORM_NAME)
lib_name = '{}/{}'.format(ctx.env.BUILD_DIR, ctx.env.PROJECT_INFO['name'])
ctx.pbl_build(source=ctx.path.ant_glob('src/c/**/*.c'), target=lib_name, bin_type='lib')
ctx.env = cached_env
ctx.set_group('bundle')
ctx.pbl_bundle(includes=ctx.path.ant_glob('include/**/*.h'),
js=ctx.path.ant_glob(['src/js/**/*.js', 'src/js/**/*.json']),
bin_type='lib')
if ctx.cmd == 'clean':
for n in ctx.path.ant_glob(['dist/**/*', 'dist.zip'], quiet=True):
n.delete()

20
sdk/defaults/rocky/app.js Normal file
View file

@ -0,0 +1,20 @@
/**
* 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.
*/
// https://developer.pebble.com/docs/pebblekit-js/Pebble/#on
Pebble.on('message', function(event) {
console.log('Message received from watch:', event.data);
});

View file

@ -0,0 +1,84 @@
/**
* 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.
*/
var rocky = require('rocky');
// An object to cache our date & time values,
// to minimize computations in the draw handler.
var clockData = {
time: '',
date: ''
};
// Every minute
// https://developer.pebble.com/docs/rockyjs/rocky/#on
rocky.on('minutechange', function(event) {
// Current date/time
// https://developer.pebble.com/docs/rockyjs/Date/
var d = event.date;
// Get current time, based on 12h or 24h format (01:00 or 1:00 AM)
clockData.time = d.toLocaleTimeString().replace(/:\d+($$| )/, '$$1');
// Day of month
var day = d.toLocaleDateString(undefined, ({day: 'numeric'}));
// Month name
var month = d.toLocaleDateString(undefined, ({month: 'long'}));
// Date
clockData.date = (day + ' ' + month);
// Force screen redraw
rocky.requestDraw();
});
// Redraw the screen
rocky.on('draw', function(event) {
// Drawing canvas
var ctx = event.context;
// Clear the canvas
// https://developer.pebble.com/docs/rockyjs/CanvasRenderingContext2D/#Canvas
ctx.clearRect(0, 0, ctx.canvas.clientWidth, ctx.canvas.clientHeight);
// UnobstructedArea
// https://developer.pebble.com/docs/rockyjs/CanvasRenderingContext2D/#Canvas
var offsetY = (ctx.canvas.clientHeight - ctx.canvas.unobstructedHeight) / 2;
var centerX = ctx.canvas.unobstructedWidth / 2;
// Text formatting
ctx.fillStyle = 'white';
ctx.textAlign = 'center';
// Time font
// https://developer.pebble.com/docs/rockyjs/CanvasRenderingContext2D/#font
ctx.font = '26px bold Leco-numbers-am-pm';
// Time
ctx.fillText(clockData.time, centerX, (66 - offsetY));
// Date font
ctx.font = '18px bold Gothic';
// Date
ctx.fillText(clockData.date, centerX, (94 - offsetY));
});
// Send a single message to the Phone
// https://developer.pebble.com/docs/rockyjs/rocky/#postMessage
rocky.postMessage("This arrives on the phone via bluetooth!");

View file

@ -0,0 +1,25 @@
{
"name": "${project_name}",
"author": "MakeAwesomeHappen",
"version": "1.0.0",
"keywords": ["pebble-app"],
"private": true,
"dependencies": {},
"pebble": {
"main": {
"rockyjs": "src/rocky/index.js",
"pkjs": "src/pkjs/index.js"
},
"displayName": "${display_name}",
"uuid": "${uuid}",
"projectType": "rocky",
"sdkVersion": "${sdk_version}",
"enableMultiJS": true,
"watchapp": {
"watchface": true
},
"resources": {
"media": []
}
}
}

View file

@ -0,0 +1,30 @@
#
# This file is the default set of rules to compile a Pebble application.
#
# Feel free to customize this to your needs.
#
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')
ctx.pbl_bundle(js=ctx.path.ant_glob(['src/pkjs/**/*.js',
'src/pkjs/**/*.json',
'src/common/**/*.js']),
js_entry_file='src/pkjs/index.js',
bin_type='rocky')

View file

@ -0,0 +1,42 @@
{
"default": {
".gitignore": "gitignore"
},
"rocky": {
"default": {
"src/pkjs/index.js": "rocky/app.js",
"src/rocky/index.js": "rocky/index.js",
"wscript": "rocky/wscript",
"package.json": "rocky/package.json"
}
},
"app": {
"default": {
"src/c/${project_name}.c": "app/main.c",
"wscript": "app/wscript",
"package.json": "app/package.json",
"resources": null
},
"worker": {
"worker_src/c/${project_name}_worker.c": "app/worker.c"
},
"simple": {
"src/c/${project_name}.c": "app/simple.c"
},
"javascript": {
"src/pkjs/index.js": "app/index.js"
}
},
"lib": {
"default": {
"src/c/${project_name}.c": "lib/lib.c",
"include/${project_name}.h": "lib/lib.h",
"wscript": "lib/wscript",
"package.json": "lib/package.json",
"src/resources": null
},
"javascript": {
"src/js/index.js": "lib/lib.js"
}
}
}