Works, I guess

This commit is contained in:
Neale Pickett 2016-05-13 14:11:47 -06:00
parent 6c9e90514e
commit 075df8a001
8 changed files with 308 additions and 0 deletions

51
appinfo.json Normal file
View File

@ -0,0 +1,51 @@
{
"appKeys": {},
"capabilities": [
""
],
"companyName": "dartcatcher@gmail.com",
"enableMultiJS": false,
"longName": "toioioioioioioioik",
"projectType": "native",
"resources": {
"media": [
{
"file": "images/io.png",
"name": "IMAGE_IO",
"targetPlatforms": null,
"type": "bitmap"
},
{
"file": "images/tck.png",
"name": "IMAGE_TCK",
"targetPlatforms": null,
"type": "bitmap"
},
{
"file": "images/oi.png",
"name": "IMAGE_OI",
"targetPlatforms": null,
"type": "bitmap"
},
{
"file": "images/menu.png",
"menuIcon": true,
"name": "MENU_IMAGE",
"targetPlatforms": null,
"type": "png"
}
]
},
"sdkVersion": "3",
"shortName": "toik",
"targetPlatforms": [
"aplite",
"basalt",
"chalk"
],
"uuid": "564f9b82-5a03-494c-8bf1-65e4eb9a5306",
"versionLabel": "1.0",
"watchapp": {
"watchface": true
}
}

BIN
resources/images/io.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

BIN
resources/images/menu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

BIN
resources/images/oi.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

BIN
resources/images/tck.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

153
src/main.c Normal file
View File

@ -0,0 +1,153 @@
#include <pebble.h>
#define MINLEN 58
#define HRCIRCLER 30
#define NRINGS 17
#define MINCIRCLER 20
#define fatness 14
#define fat(x) (fatness * x)
static Window *window;
static Layer *s_hr_layer, *s_min_layer;
static GBitmap *oi_bitmap, *io_bitmap, *tck_bitmap;
static BitmapLayer *oi_layer, *tck_layer;
GRect display_bounds;
GPoint center, mincenter;
int32_t min_angle;
char hrstr[3], minstr[3], datestr[15];
bool bt_vibe = true;
bool shape = 0;
bool bt_connected;
#define nringcolors 5
GColor *rings[nringcolors] = {
&GColorVividCerulean,
&GColorChromeYellow,
&GColorCobaltBlue,
&GColorDarkGray,
&GColorWhite,
};
static void min_update_proc(Layer *layer, GContext *ctx) {
//
}
static void hr_update_proc(Layer *layer, GContext *ctx) {
//
}
static void handle_tick(struct tm *tick_time, TimeUnits units_changed) {
if (units_changed & HOUR_UNIT) {
if (clock_is_24h_style()) {
strftime(hrstr, sizeof(hrstr), "%H", tick_time);
} else {
strftime(hrstr, sizeof(hrstr), "%I", tick_time);
}
layer_mark_dirty(s_hr_layer);
}
if (units_changed & SECOND_UNIT) {
strftime(minstr, sizeof(minstr), "%M", tick_time);
if (tick_time->tm_sec % 2 == 0) {
bitmap_layer_set_bitmap(oi_layer, oi_bitmap);
} else {
bitmap_layer_set_bitmap(oi_layer, io_bitmap);
}
layer_mark_dirty(s_min_layer);
}
}
static void window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window);
display_bounds = layer_get_bounds(window_layer);
center = grect_center_point(&display_bounds);
// Minutes
s_min_layer = layer_create(display_bounds);
layer_set_update_proc(s_min_layer, min_update_proc);
// oioioioi
oi_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_OI);
io_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_IO);
GRect bm_bounds = gbitmap_get_bounds(oi_bitmap);
GRect min_bounds = {
.origin = {
.x = (display_bounds.size.w - bm_bounds.size.w) / 2,
.y = 40,
},
.size = {
.w = bm_bounds.size.w,
.h = bm_bounds.size.h,
}
};
oi_layer = bitmap_layer_create(min_bounds);
bitmap_layer_set_compositing_mode(oi_layer, GCompOpSet);
layer_add_child(s_min_layer, bitmap_layer_get_layer(oi_layer));
// t_ck
tck_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_TCK);
GRect tck_bounds = gbitmap_get_bounds(tck_bitmap);
tck_bounds.origin.x = center.x - (tck_bounds.size.w / 2);
tck_bounds.origin.y = 5;
tck_layer = bitmap_layer_create(tck_bounds);
bitmap_layer_set_compositing_mode(tck_layer, GCompOpSet);
bitmap_layer_set_bitmap(tck_layer, tck_bitmap);
layer_add_child(s_min_layer, bitmap_layer_get_layer(tck_layer));
// Hours
s_hr_layer = layer_create(display_bounds);
layer_set_update_proc(s_hr_layer, hr_update_proc);
layer_add_child(window_layer, s_min_layer);
layer_add_child(window_layer, s_hr_layer);
}
static void window_unload(Window *window) {
layer_destroy(s_hr_layer);
layer_destroy(s_min_layer);
bitmap_layer_destroy(oi_layer);
}
static void bt_handler(bool connected) {
bt_connected = connected;
if (bt_vibe && (! connected)) {
vibes_double_pulse();
}
layer_mark_dirty(s_min_layer);
}
static void init() {
window = window_create();
window_set_window_handlers(window, (WindowHandlers) {
.load = window_load,
.unload = window_unload,
});
window_stack_push(window, true);
tick_timer_service_subscribe(HOUR_UNIT | MINUTE_UNIT | SECOND_UNIT, handle_tick);
{
time_t now = time(NULL);
struct tm *tick_time = localtime(&now);
handle_tick(tick_time, HOUR_UNIT | MINUTE_UNIT | SECOND_UNIT);
}
bluetooth_connection_service_subscribe(bt_handler);
bt_connected = bluetooth_connection_service_peek();
}
static void deinit() {
tick_timer_service_unsubscribe();
window_destroy(window);
}
int main() {
init();
app_event_loop();
deinit();
}

42
src/twatch.h Normal file
View File

@ -0,0 +1,42 @@
#include <pebble.h>
#pragma once
#define SECOND_LEN PBL_IF_ROUND_ELSE(77, 72)
#define SECOND_RADIUS 7
static const GPathInfo SECOND_HAND_POINTS = {
4,
(GPoint []) {
{2, -70},
{2, PBL_IF_ROUND_ELSE(-90, -85)},
{-2, PBL_IF_ROUND_ELSE(-90, -85)},
{-2, -70}
}
};
#define MINUTE_LEN PBL_IF_ROUND_ELSE(-81, -78)
static const GPathInfo MINUTE_HAND_POINTS = {
7,
(GPoint []) {
{4, 0},
{4, MINUTE_LEN},
{3, MINUTE_LEN - 2},
{0, MINUTE_LEN - 3},
{-3, MINUTE_LEN - 2},
{-4, MINUTE_LEN},
{-4, 0}
}
};
#define HOUR_LEN PBL_IF_ROUND_ELSE(-55, -53)
static const GPathInfo HOUR_HAND_POINTS = {
7,
(GPoint []) {
{5, 0},
{5, HOUR_LEN},
{4, HOUR_LEN -2},
{0, HOUR_LEN - 3},
{-4, HOUR_LEN - 2},
{-5, HOUR_LEN},
{-5, 0}
}
};

62
wscript Normal file
View File

@ -0,0 +1,62 @@
#
# 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 [])