Works on chalk and basalt

This commit is contained in:
Neale Pickett 2015-12-25 18:10:48 -07:00
parent 033982351e
commit 30e8045f19
8 changed files with 358 additions and 0 deletions

50
appinfo.json Normal file
View File

@ -0,0 +1,50 @@
{
"appKeys": {},
"capabilities": [
""
],
"companyName": "dartcatcher@gmail.com",
"longName": "Twatch Rings",
"projectType": "native",
"resources": {
"media": [
{
"file": "images/icon",
"name": "IMAGE_ICON",
"targetPlatforms": null,
"type": "bitmap"
},
{
"characterRegex": "[0-9]",
"file": "fonts/Helvetica-Bold.ttf",
"name": "FONT_24",
"targetPlatforms": null,
"type": "font"
},
{
"file": "images/menu.png",
"menuIcon": true,
"name": "MENU_IMAGE",
"type": "png"
},
{
"characterRegex": "[\uf10b]",
"file": "fonts/fontawesome-webfont.ttf",
"name": "SYMBOLS_64",
"targetPlatforms": null,
"type": "font"
}
]
},
"sdkVersion": "3",
"shortName": "Twatch Rings",
"targetPlatforms": [
"basalt",
"chalk"
],
"uuid": "029c47c0-f364-4d8f-bf66-abd35a9008f8",
"versionLabel": "1.0",
"watchapp": {
"watchface": true
}
}

Binary file not shown.

Binary file not shown.

BIN
resources/images/icon Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 B

BIN
resources/images/menu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

204
src/main.c Normal file
View File

@ -0,0 +1,204 @@
#include <pebble.h>
#include "twatch.h"
#define seconds true
#define fatness PBL_IF_ROUND_ELSE(14, 13)
#define fat(x) (fatness * PBL_IF_ROUND_ELSE(x, x-1))
static Window *window;
static Layer *s_bg_layer, *s_fg_layer, *s_hands_layer;
static TextLayer *s_day_label, *s_bt_label;
static GPath *s_second_arrow, *s_minute_arrow, *s_hour_arrow;
static char s_day_buffer[6];
GRect display_bounds;
GPoint center;
bool bt_connected;
static void bg_update_proc(Layer *layer, GContext *ctx) {
// Draw Background Rings
GRect frame;
graphics_context_set_fill_color(ctx, GColorPictonBlue);
graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
// center dot
graphics_context_set_fill_color(ctx, GColorWhite);
graphics_fill_circle(ctx, center, 20);
frame = grect_inset(display_bounds, GEdgeInsets(fat(2) - 1));
graphics_context_set_fill_color(ctx, GColorRed);
graphics_fill_radial(ctx, frame, GOvalScaleModeFitCircle, fatness + 2, DEG_TO_TRIGANGLE(0), DEG_TO_TRIGANGLE(360));
frame = grect_inset(display_bounds, GEdgeInsets(fat(4) - 1));
graphics_context_set_fill_color(ctx, GColorIslamicGreen);
graphics_fill_radial(ctx, frame, GOvalScaleModeFitCircle, fatness + 2, DEG_TO_TRIGANGLE(0), DEG_TO_TRIGANGLE(360));
}
static void fg_update_proc(Layer *layer, GContext *ctx) {
GRect frame;
frame = grect_inset(display_bounds, GEdgeInsets(fat(1)));
graphics_context_set_fill_color(ctx, GColorBulgarianRose);
graphics_fill_radial(ctx, frame, GOvalScaleModeFitCircle, fatness, DEG_TO_TRIGANGLE(0), DEG_TO_TRIGANGLE(360));
frame = grect_inset(display_bounds, GEdgeInsets(fat(3)));
graphics_context_set_fill_color(ctx, GColorYellow);
graphics_fill_radial(ctx, frame, GOvalScaleModeFitCircle, fatness, DEG_TO_TRIGANGLE(0), DEG_TO_TRIGANGLE(360));
}
static void hands_update_proc(Layer *layer, GContext *ctx) {
time_t now = time(NULL);
struct tm *t = localtime(&now);
char *b = s_day_buffer;
// minute hand
graphics_context_set_fill_color(ctx, GColorWhite);
gpath_rotate_to(s_minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60);
gpath_draw_filled(ctx, s_minute_arrow);
// hour hand
gpath_rotate_to(s_hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6));
gpath_draw_filled(ctx, s_hour_arrow);
// second hand
int32_t second_angle = TRIG_MAX_ANGLE * t->tm_sec / 60;
GPoint second_point = {
.x = (int16_t)(sin_lookup(second_angle) * SECOND_LEN / TRIG_MAX_RATIO) + center.x,
.y = (int16_t)(-cos_lookup(second_angle) * SECOND_LEN / TRIG_MAX_RATIO) + center.y,
};
graphics_context_set_fill_color(ctx, GColorBlack);
graphics_fill_circle(ctx, second_point, SECOND_RADIUS);
if (false && bt_connected) {
text_layer_set_text(s_bt_label, "");
} else {
text_layer_set_text(s_bt_label, "");
}
strftime(s_day_buffer, sizeof(s_day_buffer), "%d", t);
if (b[0] == '0') {
b += 1;
}
text_layer_set_text(s_day_label, b);
}
static void handle_second_tick(struct tm *tick_time, TimeUnits units_changed) {
layer_mark_dirty(s_hands_layer);
}
static void window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window);
GRect bounds = layer_get_bounds(window_layer);
// Background
s_bg_layer = layer_create(bounds);
layer_set_update_proc(s_bg_layer, bg_update_proc);
layer_add_child(window_layer, s_bg_layer);
// Hands
s_hands_layer = layer_create(bounds);
layer_set_update_proc(s_hands_layer, hands_update_proc);
layer_add_child(window_layer, s_hands_layer);
// Foreground
s_fg_layer = layer_create(bounds);
layer_set_update_proc(s_fg_layer, fg_update_proc);
layer_add_child(window_layer, s_fg_layer);
// Day
#ifdef PBL_RECT
s_day_label = text_layer_create(GRect(57, 69, 30, 24));
#else
s_day_label = text_layer_create(GRect(75, 75, 30, 24));
#endif
text_layer_set_font(s_day_label, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_24)));
text_layer_set_text_alignment(s_day_label, GTextAlignmentCenter);
text_layer_set_text(s_day_label, s_day_buffer);
text_layer_set_background_color(s_day_label, GColorClear);
text_layer_set_text_color(s_day_label, GColorBlack);
layer_add_child(s_fg_layer, text_layer_get_layer(s_day_label));
// Missing phone
#ifdef PBL_RECT
s_bt_label = text_layer_create(GRect(10, 42, 52, 64));
#else
s_bt_label = text_layer_create(GRect(26, 50, 52, 64));
#endif
text_layer_set_text_alignment(s_bt_label, GTextAlignmentCenter);
text_layer_set_text(s_bt_label, "");
text_layer_set_background_color(s_bt_label, GColorClear);
text_layer_set_text_color(s_bt_label, GColorOxfordBlue);
text_layer_set_font(s_bt_label, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SYMBOLS_64)));
layer_add_child(s_fg_layer, text_layer_get_layer(s_bt_label));
}
static void window_unload(Window *window) {
layer_destroy(s_bg_layer);
layer_destroy(s_fg_layer);
layer_destroy(s_hands_layer);
text_layer_destroy(s_day_label);
}
static void bt_handler(bool connected) {
bt_connected = connected;
if (! connected) {
vibes_long_pulse();
}
layer_mark_dirty(s_fg_layer);
}
static void tick_subscribe() {
if (seconds) {
tick_timer_service_subscribe(SECOND_UNIT, handle_second_tick);
} else {
tick_timer_service_subscribe(MINUTE_UNIT, handle_second_tick);
}
}
static void init() {
window = window_create();
window_set_window_handlers(window, (WindowHandlers) {
.load = window_load,
.unload = window_unload,
});
window_stack_push(window, true);
s_day_buffer[0] = '\0';
// init paths
s_second_arrow = gpath_create(&SECOND_HAND_POINTS);
s_minute_arrow = gpath_create(&MINUTE_HAND_POINTS);
s_hour_arrow = gpath_create(&HOUR_HAND_POINTS);
Layer *window_layer = window_get_root_layer(window);
display_bounds = layer_get_bounds(window_layer);
center = grect_center_point(&display_bounds);
gpath_move_to(s_second_arrow, center);
gpath_move_to(s_minute_arrow, center);
gpath_move_to(s_hour_arrow, center);
tick_subscribe();
bluetooth_connection_service_subscribe(bt_handler);
bt_connected = bluetooth_connection_service_peek();
}
static void deinit() {
gpath_destroy(s_second_arrow);
gpath_destroy(s_minute_arrow);
gpath_destroy(s_hour_arrow);
// XXX: text destroy?
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 [])