Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
blockarchitech committed Jan 12, 2025
0 parents commit 87ec662
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
build/
node_modules/
package-lock.json
8 changes: 8 additions & 0 deletions .lock-waf_linux2_build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
argv = ['/home/pebble/.pebble-sdk/SDKs/current/sdk-core/pebble/waf', 'configure']
environ = {'NO_GCE_CHECK': 'False', 'PEBBLE_TOOL_VERSION': 'pebble-sdk-4.6-rc2-linux64', 'NODE_VERSION': '10.16.2', 'PEBBLE_SDK_VERSION': '4.3', 'NVM_DIR': '/home/pebble/.nvm', 'PEBBLE_TOOLCHAIN_PATH': '/opt/pebble-sdk-4.6-rc2-linux64/arm-cs-tools/bin', 'PATH': '/opt/pebble-sdk-4.6-rc2-linux64/arm-cs-tools/bin:/opt/pebble-sdk-4.6-rc2-linux64/bin:/home/pebble/.nvm/versions/node/v10.16.2/bin:/opt/pebble-sdk-4.6-rc2-linux64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'DISPLAY': ':0', '_': '/opt/pebble-sdk-4.6-rc2-linux64/.env/bin/python', 'TERM': 'xterm', 'SHLVL': '1', 'PHONESIM_PATH': '/opt/pebble-sdk-4.6-rc2-linux64/.env//bin/pypkjs', 'HOSTNAME': 'tacoframework', 'PYTHONHOME': '/home/pebble/.pebble-sdk/SDKs/current/sdk-core/../.env', 'NODE_PATH': '/home/pebble/.pebble-sdk/SDKs/current/sdk-core/../node_modules', 'PWD': '/pebble', 'HOME': '/home/pebble', 'NOCLIMB': '1'}
files = ['/pebble/wscript']
hash = -1811062659542012155
options = {'files': '', 'jobs': 16, 'verbose': 0, 'nocache': False, 'progress_bar': 0, 'no_groups': False, 'distcheck_args': None, 'top': '', 'sandbox': False, 'destdir': '', 'keep': 0, 'zones': '', 'debug': False, 'prefix': '/usr/local/', 'timestamp': None, 'download': False, 'force': False, 'targets': '', 'out': ''}
out_dir = '/pebble/build'
run_dir = '/pebble'
top_dir = '/pebble'
41 changes: 41 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "test",
"author": "MakeAwesomeHappen",
"version": "1.0.0",
"keywords": [
"pebble-app"
],
"scripts": {
"webpack": "webpack",
"build": "python3 pebble.py build",
"clean": "python3 pebble.py clean"
},
"private": true,
"pebble": {
"displayName": "test",
"uuid": "f8404983-83df-42ab-b620-5e6beb802917",
"sdkVersion": "3",
"enableMultiJS": true,
"targetPlatforms": [
"aplite",
"basalt",
"chalk",
"diorite"
],
"watchapp": {
"watchface": false
},
"messageKeys": [
"dummy"
],
"resources": {
"media": []
}
},
"devDependencies": {
"ts-loader": "^9.5.2",
"typescript": "^5.7.3",
"webpack": "^5.97.1",
"webpack-cli": "^6.0.1"
}
}
34 changes: 34 additions & 0 deletions pebble-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Set up args for podman or docker depending on the container runtime installed
# CONTAINER_RUNTIME="podman"
# EXTRA_RUN_ARGS="--userns=keep-id"

CONTAINER_RUNTIME="docker"
EXTRA_RUN_ARGS=""

IMAGE='docker.io/kennedn/pebble-wrapper:latest'


# If clean-containers passed, set a flag that will run a `"${CONTAINER_RUNTIME}" rm` once image_ids is obtained
CLEAN=
[ "$1" == "clean-containers" ] && CLEAN=1

# Obtain list of running containers with the pebble base image
image_ids=$("${CONTAINER_RUNTIME}" ps --filter "ancestor=${IMAGE}" --format '{{.ID}}')

image_id=
# If list is not empty, check if any have the current directory mounted
if [ -n "${image_ids}" ]; then
image_id=$("${CONTAINER_RUNTIME}" inspect ${image_ids} | jq -r --arg pwd "$(pwd)" '[.[] | select (.Mounts[].Destination == "/pebble" and .Mounts[].Source == $pwd)][0].Id | select (. != null)')
[ -n "${CLEAN}" ] && "${CONTAINER_RUNTIME}" kill ${image_ids}
fi

[ -n "${CLEAN}" ] && exit 0

# If no running containers have the current directory mounted, create one
if [ -z "${image_id}" ]; then
image_id=$("${CONTAINER_RUNTIME}" run ${EXTRA_RUN_ARGS} -d -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.x11-unix -v ~/.Xauthority:/home/pebble/.Xauthority --net=host --entrypoint="sleep" -v .:/pebble ${IMAGE} infinity)
fi
# Pass all args to the pebble tool in the container that has the current directory mounted
"${CONTAINER_RUNTIME}" exec -it -w="/pebble" ${image_id} pebble $@
37 changes: 37 additions & 0 deletions pebble.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import sys

PEBBLE_TOOL_LOCATION = "./pebble-wrapper.sh"

if __name__ == '__main__':
if len(sys.argv) > 1 and sys.argv[1] == "build":
os.system(PEBBLE_TOOL_LOCATION + ' build')

binaries = [
{'platform': 'aplite'},
{'platform': 'basalt'},
{'platform': 'chalk'},
{'platform': 'diorite'},
]

os.system('npm run webpack')
os.system('cp dist/bundle.js build/pebble-js-app.js')
os.system('cp dist/bundle.js.map build/pebble-js-app.js.map')

zip_file = 'build/pebble-ts.pbw'
zip_args = [
'zip',
'-j',
zip_file,
'build/pebble-js-app.js',
'build/pebble-js-app.js.map',
'build/appinfo.json',
]
for binary in binaries:
zip_args.append(binary['platform'])
os.system(' '.join(zip_args))
elif len(sys.argv) > 1 and sys.argv[1] == "clean":
os.system(PEBBLE_TOOL_LOCATION + ' clean')
os.system("rm -rf dist")
else:
print("Usage: python build.py [build|clean]")
60 changes: 60 additions & 0 deletions src/c/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#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();
}
1 change: 1 addition & 0 deletions src/pkts/Pebble.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare var Pebble: any;
5 changes: 5 additions & 0 deletions src/pkts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Pebble.addEventListener("ready",
function(e) {
console.log("Hello world! - Sent from your javascript application.");
}
);
18 changes: 18 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "NodeNext",
"incremental": true,
"declaration": true,
"outDir": "./dist/",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"sourceMap": true,
"allowJs": false

},
"include": [
"src/pkts/**/*.ts"
], // pebblekit "ts"
}
23 changes: 23 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const path = require('path');

module.exports = {
entry: './src/pkts/index.ts',
devtool: 'source-map',
mode: 'development',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
};
53 changes: 53 additions & 0 deletions wscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# 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')




0 comments on commit 87ec662

Please sign in to comment.