mirror of
https://github.com/google/pebble.git
synced 2025-06-06 10:13:12 +00:00
Import of the watch repository from Pebble
This commit is contained in:
commit
3b92768480
10334 changed files with 2564465 additions and 0 deletions
19
src/apps/accelerometer_peek_test/appinfo.json
Normal file
19
src/apps/accelerometer_peek_test/appinfo.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"appKeys": {},
|
||||
"capabilities": [
|
||||
""
|
||||
],
|
||||
"companyName": "Pebble Technology",
|
||||
"longName": "Accelerometer Peek Test",
|
||||
"projectType": "native",
|
||||
"resources": {
|
||||
"media": []
|
||||
},
|
||||
"sdkVersion": "3",
|
||||
"shortName": "Accelerometer",
|
||||
"uuid": "5fe852be-99cd-4bd0-953d-31c767630dde",
|
||||
"versionLabel": "1.0",
|
||||
"watchapp": {
|
||||
"watchface": false
|
||||
}
|
||||
}
|
103
src/apps/accelerometer_peek_test/src/accelerometer_peek_test.c
Normal file
103
src/apps/accelerometer_peek_test/src/accelerometer_peek_test.c
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* 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 <inttypes.h>
|
||||
|
||||
#define ACCEL_RAW_DATA 0
|
||||
#define TIMEOUT_MS 1000
|
||||
|
||||
Window *window;
|
||||
TextLayer *text_layer;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
static void prv_timer_cb(void *data) {
|
||||
s_timer = app_timer_register(TIMEOUT_MS, prv_timer_cb, NULL);
|
||||
|
||||
AccelData accel_data;
|
||||
int error;
|
||||
if ((error = accel_service_peek(&accel_data)) != 0) {
|
||||
APP_LOG(APP_LOG_LEVEL_ERROR, "Accelerometer error %i", error);
|
||||
return;
|
||||
}
|
||||
|
||||
static char accel_text[20];
|
||||
#if !ACCEL_RAW_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);
|
||||
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);
|
||||
APP_LOG(APP_LOG_LEVEL_INFO, accel_text);
|
||||
#endif
|
||||
text_layer_set_text(text_layer, accel_text);
|
||||
}
|
||||
|
||||
void handle_init(void) {
|
||||
// Create a window and text layer
|
||||
window = window_create();
|
||||
Layer *window_layer = window_get_root_layer(window);
|
||||
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));
|
||||
|
||||
// Set the text, font, and text alignment
|
||||
text_layer_set_text(text_layer, "No Accelerometer");
|
||||
text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
|
||||
|
||||
// Add the text layer to the window
|
||||
layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer));
|
||||
|
||||
// Push the window
|
||||
window_stack_push(window, true);
|
||||
|
||||
// App Logging!
|
||||
APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
|
||||
|
||||
// Subscribe Accelerometer and Register Timer
|
||||
accel_data_service_subscribe(0, NULL);
|
||||
s_timer = app_timer_register(TIMEOUT_MS, prv_timer_cb, NULL);
|
||||
}
|
||||
|
||||
void handle_deinit(void) {
|
||||
// Destroy Timer and Unsubscribe Accelerometer
|
||||
app_timer_cancel(s_timer);
|
||||
accel_data_service_unsubscribe();
|
||||
|
||||
// Destroy the text layer
|
||||
text_layer_destroy(text_layer);
|
||||
|
||||
// Destroy the window
|
||||
window_destroy(window);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
handle_init();
|
||||
app_event_loop();
|
||||
handle_deinit();
|
||||
}
|
61
src/apps/accelerometer_peek_test/wscript
Normal file
61
src/apps/accelerometer_peek_test/wscript
Normal file
|
@ -0,0 +1,61 @@
|
|||
|
||||
#
|
||||
# This file is the default set of rules to compile a Pebble project.
|
||||
#
|
||||
# Feel free to customize this to your needs.
|
||||
#
|
||||
|
||||
import os.path
|
||||
try:
|
||||
from sh import CommandNotFound, jshint, cat, ErrorReturnCode_2
|
||||
hint = jshint
|
||||
except (ImportError, CommandNotFound):
|
||||
hint = None
|
||||
|
||||
top = '.'
|
||||
out = 'build'
|
||||
|
||||
def options(ctx):
|
||||
ctx.load('pebble_sdk')
|
||||
|
||||
def configure(ctx):
|
||||
ctx.load('pebble_sdk')
|
||||
|
||||
def build(ctx):
|
||||
if False and hint is not None:
|
||||
try:
|
||||
hint([node.abspath() for node in ctx.path.ant_glob("src/**/*.js")], _tty_out=False) # no tty because there are none in the cloudpebble sandbox.
|
||||
except ErrorReturnCode_2 as e:
|
||||
ctx.fatal("\nJavaScript linting failed (you can disable this in Project Settings):\n" + e.stdout)
|
||||
|
||||
# Concatenate all our JS files (but not recursively), and only if any JS exists in the first place.
|
||||
ctx.path.make_node('src/js/').mkdir()
|
||||
js_paths = ctx.path.ant_glob(['src/*.js', 'src/**/*.js'])
|
||||
if js_paths:
|
||||
ctx(rule='cat ${SRC} > ${TGT}', source=js_paths, target='pebble-js-app.js')
|
||||
has_js = True
|
||||
else:
|
||||
has_js = False
|
||||
|
||||
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(p)
|
||||
ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'),
|
||||
target=app_elf)
|
||||
|
||||
if build_worker:
|
||||
worker_elf='{}/pebble-worker.elf'.format(p)
|
||||
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='pebble-js-app.js' if has_js else [])
|
Loading…
Add table
Add a link
Reference in a new issue