mirror of https://github.com/nealey/Twatch
cloudpebble commit
This commit is contained in:
parent
384a93f84d
commit
b5193b11ab
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"appKeys": {},
|
||||
"capabilities": [
|
||||
""
|
||||
],
|
||||
"companyName": "dartcatcher@gmail.com",
|
||||
"longName": "Twatch",
|
||||
"projectType": "native",
|
||||
"resources": {
|
||||
"media": []
|
||||
},
|
||||
"sdkVersion": "3",
|
||||
"shortName": "Twatch",
|
||||
"targetPlatforms": [
|
||||
"aplite",
|
||||
"basalt"
|
||||
],
|
||||
"uuid": "3b2a3db6-1699-4826-8a2d-dbbc843cc28c",
|
||||
"versionLabel": "1.0",
|
||||
"watchapp": {
|
||||
"watchface": true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
#include <pebble.h>
|
||||
#include "twatch.h"
|
||||
|
||||
#if 0
|
||||
#define BLACK
|
||||
#endif
|
||||
|
||||
#ifdef BLACK
|
||||
#define FG GColorWhite
|
||||
#define BG GColorBlack
|
||||
#else
|
||||
#define FG GColorBlack
|
||||
#define BG GColorWhite
|
||||
#endif
|
||||
|
||||
static Window *window;
|
||||
static Layer *s_simple_bg_layer, *s_date_layer, *s_hands_layer;
|
||||
static TextLayer *s_day_label, *s_mon_label;
|
||||
|
||||
static GPath *s_tick_paths[NUM_CLOCK_TICKS];
|
||||
static GPath *s_minute_arrow, *s_hour_arrow;
|
||||
static char s_mon_buffer[4], s_day_buffer[6];
|
||||
|
||||
static void bg_update_proc(Layer *layer, GContext *ctx) {
|
||||
graphics_context_set_fill_color(ctx, BG);
|
||||
graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
|
||||
graphics_context_set_fill_color(ctx, FG);
|
||||
for (int i = 0; i < NUM_CLOCK_TICKS; ++i) {
|
||||
gpath_draw_filled(ctx, s_tick_paths[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void hands_update_proc(Layer *layer, GContext *ctx) {
|
||||
GRect bounds = layer_get_bounds(layer);
|
||||
|
||||
time_t now = time(NULL);
|
||||
struct tm *t = localtime(&now);
|
||||
|
||||
#ifdef SECONDS
|
||||
GPoint center = grect_center_point(&bounds);
|
||||
int16_t second_hand_length = bounds.size.w / 2;
|
||||
|
||||
int32_t second_angle = TRIG_MAX_ANGLE * t->tm_sec / 60;
|
||||
GPoint second_hand = {
|
||||
.x = (int16_t)(sin_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.x,
|
||||
.y = (int16_t)(-cos_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.y,
|
||||
};
|
||||
|
||||
// second hand
|
||||
graphics_context_set_stroke_color(ctx, FG);
|
||||
graphics_draw_line(ctx, second_hand, center);
|
||||
#endif
|
||||
|
||||
// minute/hour hand
|
||||
graphics_context_set_fill_color(ctx, FG);
|
||||
graphics_context_set_stroke_color(ctx, BG);
|
||||
|
||||
gpath_rotate_to(s_minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60);
|
||||
gpath_draw_filled(ctx, s_minute_arrow);
|
||||
gpath_draw_outline(ctx, s_minute_arrow);
|
||||
|
||||
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);
|
||||
gpath_draw_outline(ctx, s_hour_arrow);
|
||||
|
||||
// dot in the middle
|
||||
//graphics_context_set_fill_color(ctx, BG);
|
||||
//graphics_fill_rect(ctx, GRect(bounds.size.w / 2 - 1, bounds.size.h / 2 - 1, 3, 3), 0, GCornerNone);
|
||||
}
|
||||
|
||||
static void date_update_proc(Layer *layer, GContext *ctx) {
|
||||
time_t now = time(NULL);
|
||||
struct tm *t = localtime(&now);
|
||||
char *b = s_day_buffer;
|
||||
|
||||
strftime(s_mon_buffer, sizeof(s_mon_buffer), "%b", t);
|
||||
text_layer_set_text(s_mon_label, s_mon_buffer);
|
||||
|
||||
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(window_get_root_layer(window));
|
||||
}
|
||||
|
||||
static void window_load(Window *window) {
|
||||
Layer *window_layer = window_get_root_layer(window);
|
||||
GRect bounds = layer_get_bounds(window_layer);
|
||||
|
||||
s_simple_bg_layer = layer_create(bounds);
|
||||
layer_set_update_proc(s_simple_bg_layer, bg_update_proc);
|
||||
layer_add_child(window_layer, s_simple_bg_layer);
|
||||
|
||||
s_date_layer = layer_create(bounds);
|
||||
layer_set_update_proc(s_date_layer, date_update_proc);
|
||||
layer_add_child(window_layer, s_date_layer);
|
||||
|
||||
s_mon_label = text_layer_create(GRect(117, 145, 27, 20));
|
||||
text_layer_set_text(s_mon_label, s_day_buffer);
|
||||
text_layer_set_background_color(s_mon_label, BG);
|
||||
text_layer_set_text_color(s_mon_label, FG);
|
||||
text_layer_set_font(s_mon_label, fonts_get_system_font(FONT_KEY_GOTHIC_18));
|
||||
|
||||
layer_add_child(s_date_layer, text_layer_get_layer(s_mon_label));
|
||||
|
||||
s_day_label = text_layer_create(GRect(123, 130, 18, 20));
|
||||
text_layer_set_text(s_day_label, s_day_buffer);
|
||||
text_layer_set_background_color(s_day_label, BG);
|
||||
text_layer_set_text_color(s_day_label, FG);
|
||||
text_layer_set_font(s_day_label, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
|
||||
|
||||
layer_add_child(s_date_layer, text_layer_get_layer(s_day_label));
|
||||
|
||||
s_hands_layer = layer_create(bounds);
|
||||
layer_set_update_proc(s_hands_layer, hands_update_proc);
|
||||
layer_add_child(window_layer, s_hands_layer);
|
||||
}
|
||||
|
||||
static void window_unload(Window *window) {
|
||||
layer_destroy(s_simple_bg_layer);
|
||||
layer_destroy(s_date_layer);
|
||||
|
||||
text_layer_destroy(s_day_label);
|
||||
text_layer_destroy(s_mon_label);
|
||||
|
||||
layer_destroy(s_hands_layer);
|
||||
}
|
||||
|
||||
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';
|
||||
s_mon_buffer[0] = '\0';
|
||||
|
||||
// init hand paths
|
||||
s_minute_arrow = gpath_create(&MINUTE_HAND_POINTS);
|
||||
s_hour_arrow = gpath_create(&HOUR_HAND_POINTS);
|
||||
|
||||
Layer *window_layer = window_get_root_layer(window);
|
||||
GRect bounds = layer_get_bounds(window_layer);
|
||||
GPoint center = grect_center_point(&bounds);
|
||||
gpath_move_to(s_minute_arrow, center);
|
||||
gpath_move_to(s_hour_arrow, center);
|
||||
|
||||
for (int i = 0; i < NUM_CLOCK_TICKS; ++i) {
|
||||
s_tick_paths[i] = gpath_create(&ANALOG_BG_POINTS[i]);
|
||||
}
|
||||
|
||||
#ifdef SECONDS
|
||||
tick_timer_service_subscribe(SECOND_UNIT, handle_second_tick);
|
||||
#else
|
||||
tick_timer_service_subscribe(MINUTE_UNIT, handle_second_tick);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void deinit() {
|
||||
gpath_destroy(s_minute_arrow);
|
||||
gpath_destroy(s_hour_arrow);
|
||||
|
||||
for (int i = 0; i < NUM_CLOCK_TICKS; ++i) {
|
||||
gpath_destroy(s_tick_paths[i]);
|
||||
}
|
||||
|
||||
tick_timer_service_unsubscribe();
|
||||
window_destroy(window);
|
||||
}
|
||||
|
||||
int main() {
|
||||
init();
|
||||
app_event_loop();
|
||||
deinit();
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
#include <pebble.h>
|
||||
#pragma once
|
||||
|
||||
#define NUM_CLOCK_TICKS 11
|
||||
|
||||
static const struct GPathInfo ANALOG_BG_POINTS[] = {
|
||||
{ 4,
|
||||
(GPoint []) {
|
||||
{68, 0},
|
||||
{71, 0},
|
||||
{71, 12},
|
||||
{68, 12}
|
||||
}
|
||||
},
|
||||
{ 4, (GPoint []){
|
||||
{72, 0},
|
||||
{75, 0},
|
||||
{75, 12},
|
||||
{72, 12}
|
||||
}
|
||||
},
|
||||
{ 4, (GPoint []){
|
||||
{112, 10},
|
||||
{114, 12},
|
||||
{108, 23},
|
||||
{106, 21}
|
||||
}
|
||||
},
|
||||
{ 4, (GPoint []){
|
||||
{132, 47},
|
||||
{144, 40},
|
||||
{144, 44},
|
||||
{135, 49}
|
||||
}
|
||||
},
|
||||
{ 4, (GPoint []){
|
||||
{135, 118},
|
||||
{144, 123},
|
||||
{144, 126},
|
||||
{132, 120}
|
||||
}
|
||||
},
|
||||
{ 4, (GPoint []){
|
||||
{108, 144},
|
||||
{114, 154},
|
||||
{112, 157},
|
||||
{106, 147}
|
||||
}
|
||||
},
|
||||
{ 4, (GPoint []){
|
||||
{70, 155},
|
||||
{73, 155},
|
||||
{73, 167},
|
||||
{70, 167}
|
||||
}
|
||||
},
|
||||
{ 4, (GPoint []){
|
||||
{32, 10},
|
||||
{30, 12},
|
||||
{36, 23},
|
||||
{38, 21}
|
||||
}
|
||||
},
|
||||
{ 4, (GPoint []){
|
||||
{12, 47},
|
||||
{-1, 40},
|
||||
{-1, 44},
|
||||
{9, 49}
|
||||
}
|
||||
},
|
||||
{ 4, (GPoint []){
|
||||
{9, 118},
|
||||
{-1, 123},
|
||||
{-1, 126},
|
||||
{12, 120}
|
||||
}
|
||||
},
|
||||
{ 4, (GPoint []){
|
||||
{36, 144},
|
||||
{30, 154},
|
||||
{32, 157},
|
||||
{38, 147}
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
static const GPathInfo MINUTE_HAND_POINTS = {
|
||||
4,
|
||||
(GPoint []) {
|
||||
{ 3, 5 },
|
||||
{ 3, -70 },
|
||||
{ -3, -70 },
|
||||
{ -3, 5 }
|
||||
}
|
||||
};
|
||||
|
||||
static const GPathInfo HOUR_HAND_POINTS = {
|
||||
4,
|
||||
(GPoint []) {
|
||||
{ 10, -20 },
|
||||
{ 0, -50 },
|
||||
{ -10, -20 },
|
||||
{ 0, -25 }
|
||||
}
|
||||
};
|
|
@ -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 [])
|
||||
|
Loading…
Reference in New Issue