mirror of
https://github.com/google/pebble.git
synced 2025-06-22 09:06:17 +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
3
src/apps/dictation_demo/.gitignore
vendored
Normal file
3
src/apps/dictation_demo/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
# Ignore build generated files
|
||||
build
|
19
src/apps/dictation_demo/appinfo.json
Normal file
19
src/apps/dictation_demo/appinfo.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"uuid": "6e637ec2-f78e-4a76-b797-307cbdfd66dc",
|
||||
"shortName": "Dictation demo",
|
||||
"longName": "Dictation demo",
|
||||
"companyName": "MakeAwesomeHappen",
|
||||
"versionCode": 1,
|
||||
"versionLabel": "1.0",
|
||||
"sdkVersion": "3",
|
||||
"targetPlatforms": ["aplite", "basalt"],
|
||||
"watchapp": {
|
||||
"watchface": false
|
||||
},
|
||||
"appKeys": {
|
||||
"dummy": 0
|
||||
},
|
||||
"resources": {
|
||||
"media": []
|
||||
}
|
||||
}
|
130
src/apps/dictation_demo/src/dictation_demo.c
Normal file
130
src/apps/dictation_demo/src/dictation_demo.c
Normal file
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* 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>
|
||||
|
||||
typedef struct AppData {
|
||||
Window *window;
|
||||
TextLayer *result_text;
|
||||
char *result;
|
||||
DictationSession *session;
|
||||
bool confirm;
|
||||
} AppData;
|
||||
|
||||
static void prv_result_handler(DictationSession *session, DictationSessionStatus result,
|
||||
char *transcription, void *context) {
|
||||
AppData *app_data = context;
|
||||
free(app_data->result);
|
||||
if (result == DictationSessionStatusSuccess) {
|
||||
size_t size = strlen(transcription) + 11;
|
||||
app_data->result = malloc(size);
|
||||
if (!app_data->result) {
|
||||
APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to allocated memory for transcription");
|
||||
result = 99;
|
||||
} else {
|
||||
snprintf(app_data->result, size, "You said:\n%s", transcription);
|
||||
text_layer_set_text(app_data->result_text, app_data->result);
|
||||
return;
|
||||
}
|
||||
}
|
||||
app_data->result = malloc(100);
|
||||
snprintf(app_data->result, 100, "Welp, that didn't work (Error: %u).\n Try again.", result);
|
||||
text_layer_set_text(app_data->result_text, app_data->result);
|
||||
}
|
||||
|
||||
static void prv_select_click_handler(ClickRecognizerRef recognizer, void *context) {
|
||||
AppData *app_data = context;
|
||||
dictation_session_start(app_data->session);
|
||||
}
|
||||
|
||||
static void prv_down_click_handler(ClickRecognizerRef recognizer, void *context) {
|
||||
AppData *app_data = context;
|
||||
dictation_session_destroy(app_data->session);
|
||||
app_data->session = NULL;
|
||||
}
|
||||
|
||||
static void prv_up_click_handler(ClickRecognizerRef recognizer, void *context) {
|
||||
AppData *app_data = context;
|
||||
app_data->confirm = !app_data->confirm;
|
||||
dictation_session_enable_confirmation(app_data->session, app_data->confirm);
|
||||
}
|
||||
|
||||
static void prv_click_config_provider(void *context) {
|
||||
window_set_click_context(BUTTON_ID_SELECT, context);
|
||||
window_single_click_subscribe(BUTTON_ID_SELECT, prv_select_click_handler);
|
||||
window_set_click_context(BUTTON_ID_DOWN, context);
|
||||
window_single_click_subscribe(BUTTON_ID_DOWN, prv_down_click_handler);
|
||||
window_set_click_context(BUTTON_ID_UP, context);
|
||||
window_single_click_subscribe(BUTTON_ID_UP, prv_up_click_handler);
|
||||
}
|
||||
|
||||
static void prv_window_load(Window *window) {
|
||||
AppData *app_data = window_get_user_data(window);
|
||||
Layer *window_layer = window_get_root_layer(app_data->window);
|
||||
GRect bounds = layer_get_bounds(window_layer);
|
||||
|
||||
app_data->result_text = text_layer_create((GRect) {
|
||||
.origin = { .x = 10, .y = 10},
|
||||
.size = { .w = bounds.size.w - 20, .h = bounds.size.h - 20 }
|
||||
});
|
||||
|
||||
text_layer_set_text(app_data->result_text, "Press SELECT to start");
|
||||
text_layer_set_overflow_mode(app_data->result_text, GTextOverflowModeWordWrap);
|
||||
text_layer_set_text_alignment(app_data->result_text, GTextAlignmentCenter);
|
||||
layer_add_child(window_layer, text_layer_get_layer(app_data->result_text));
|
||||
}
|
||||
|
||||
static void prv_window_unload(Window *window) {
|
||||
AppData *app_data = window_get_user_data(window);
|
||||
text_layer_destroy(app_data->result_text);
|
||||
}
|
||||
|
||||
static void init(AppData *app_data) {
|
||||
app_data->session = dictation_session_create(1024, prv_result_handler, app_data);
|
||||
if (!app_data->session) {
|
||||
APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to create dictation session");
|
||||
}
|
||||
|
||||
app_data->confirm = true;
|
||||
|
||||
app_data->window = window_create();
|
||||
window_set_click_config_provider_with_context(app_data->window, prv_click_config_provider,
|
||||
app_data);
|
||||
window_set_window_handlers(app_data->window, (WindowHandlers) {
|
||||
.load = prv_window_load,
|
||||
.unload = prv_window_unload,
|
||||
});
|
||||
window_set_user_data(app_data->window, app_data);
|
||||
|
||||
const bool animated = true;
|
||||
window_stack_push(app_data->window, animated);
|
||||
|
||||
APP_LOG(APP_LOG_LEVEL_DEBUG, "Done initializing, pushed window: %p", app_data->window);
|
||||
}
|
||||
|
||||
static void deinit(AppData *app_data) {
|
||||
dictation_session_destroy(app_data->session);
|
||||
window_destroy(app_data->window);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
AppData *app_data = calloc(1, sizeof(AppData));
|
||||
init(app_data);
|
||||
|
||||
app_event_loop();
|
||||
|
||||
deinit(app_data);
|
||||
}
|
41
src/apps/dictation_demo/wscript
Normal file
41
src/apps/dictation_demo/wscript
Normal file
|
@ -0,0 +1,41 @@
|
|||
|
||||
#
|
||||
# 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):
|
||||
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'))
|
Loading…
Add table
Add a link
Reference in a new issue