Hands + BT

This commit is contained in:
Neale Pickett 2016-05-15 21:20:12 -06:00
parent 8f10692071
commit f5057ff296
5 changed files with 80 additions and 82 deletions

View File

@ -9,6 +9,13 @@
"projectType": "native",
"resources": {
"media": [
{
"characterRegex": "[\uf10b]",
"file": "fonts/fontawesome-webfont.ttf",
"name": "SYMBOLS_50",
"targetPlatforms": null,
"type": "font"
},
{
"file": "images/io.png",
"name": "IMAGE_IO",
@ -44,7 +51,7 @@
"chalk"
],
"uuid": "564f9b82-5a03-494c-8bf1-65e4eb9a5306",
"versionLabel": "1.1",
"versionLabel": "1.4",
"watchapp": {
"watchface": true
}

Binary file not shown.

View File

@ -1,2 +0,0 @@
void show_htn(void);
void hide_htn(void);

View File

@ -1,64 +1,72 @@
#include <pebble.h>
#define MINLEN 58
#define HRCIRCLER 30
#define NRINGS 17
#define MINCIRCLER 20
#define HAND_OUT 50
#define HAND_IN 27
#define MINUTE_WIDTH 8
#define HOUR_WIDTH 12
#define BORDER_WIDTH PBL_IF_ROUND_ELSE(16, 12)
#define HBW (BORDER_WIDTH / 2)
#define fatness 14
#define fat(x) (fatness * x)
static Window *window;
static Layer *s_hr_layer, *s_min_layer;
static Layer *s_hr_layer, *s_min_layer, *s_sec_layer;
static GBitmap *oi_bitmap, *io_bitmap, *tck_bitmap;
static BitmapLayer *oi_layer, *tck_layer;
static TextLayer *s_bt_label;
GRect display_bounds;
GPoint center, mincenter;
int32_t min_angle;
char hrstr[3], minstr[3], datestr[15];
bool bt_vibe = true;
bool shape = 0;
int hour, min;
bool bt_connected;
#define nringcolors 5
GColor *rings[nringcolors] = {
&GColorVividCerulean,
&GColorChromeYellow,
&GColorCobaltBlue,
&GColorDarkGray,
&GColorWhite,
static GPoint point_of_polar(int32_t theta, int r) {
GPoint ret = {
.x = (int16_t)(sin_lookup(theta) * r / TRIG_MAX_RATIO) + mincenter.x,
.y = (int16_t)(-cos_lookup(theta) * r / TRIG_MAX_RATIO) + mincenter.y,
};
return ret;
}
static void min_update_proc(Layer *layer, GContext *ctx) {
//
graphics_context_set_stroke_width(ctx, MINUTE_WIDTH);
graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorLightGray, GColorWhite));
graphics_draw_line(ctx,
point_of_polar(0, 0),
point_of_polar(TRIG_MAX_ANGLE * min / 60, HAND_OUT));
}
static void hr_update_proc(Layer *layer, GContext *ctx) {
//
graphics_context_set_stroke_width(ctx, HOUR_WIDTH);
graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorLightGray, GColorWhite));
graphics_draw_line(ctx,
point_of_polar(TRIG_MAX_ANGLE * (hour % 12) / 12, HAND_IN),
point_of_polar(TRIG_MAX_ANGLE * (hour % 12) / 12, HAND_OUT));
}
static void handle_tick(struct tm *tick_time, TimeUnits units_changed) {
hour = tick_time->tm_hour;
min = tick_time->tm_min;
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 & MINUTE_UNIT) {
layer_mark_dirty(s_min_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);
}
}
@ -68,15 +76,14 @@ static void window_load(Window *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);
// Seconds
s_sec_layer = layer_create(display_bounds);
// 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 = {
GRect oi_bounds = {
.origin = {
.x = (display_bounds.size.w - bm_bounds.size.w) / 2,
.y = 40,
@ -86,9 +93,9 @@ static void window_load(Window *window) {
.h = bm_bounds.size.h,
}
};
oi_layer = bitmap_layer_create(min_bounds);
oi_layer = bitmap_layer_create(oi_bounds);
bitmap_layer_set_compositing_mode(oi_layer, GCompOpSet);
layer_add_child(s_min_layer, bitmap_layer_get_layer(oi_layer));
layer_add_child(s_sec_layer, bitmap_layer_get_layer(oi_layer));
// t_ck
tck_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_TCK);
@ -98,19 +105,42 @@ static void window_load(Window *window) {
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));
layer_add_child(s_sec_layer, bitmap_layer_get_layer(tck_layer));
// Minutes
s_min_layer = layer_create(oi_bounds);
layer_set_update_proc(s_min_layer, min_update_proc);
{
GRect b = layer_get_bounds(s_min_layer);
mincenter = grect_center_point(&b);
}
// Hours
s_hr_layer = layer_create(display_bounds);
s_hr_layer = layer_create(oi_bounds);
layer_set_update_proc(s_hr_layer, hr_update_proc);
// Missing phone
#ifdef PBL_ROUND
s_bt_label = text_layer_create(GRect(26, 5, 52, 64));
#else
s_bt_label = text_layer_create(GRect(0, -5, 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, COLOR_FALLBACK(GColorRajah, GColorBlack));
text_layer_set_font(s_bt_label, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SYMBOLS_50)));
layer_add_child(window_layer, s_min_layer);
layer_add_child(window_layer, s_hr_layer);
layer_add_child(window_layer, s_sec_layer);
layer_add_child(window_layer, text_layer_get_layer(s_bt_label));
}
static void window_unload(Window *window) {
layer_destroy(s_hr_layer);
layer_destroy(s_min_layer);
layer_destroy(s_sec_layer);
bitmap_layer_destroy(oi_layer);
}
@ -119,7 +149,12 @@ static void bt_handler(bool connected) {
if (bt_vibe && (! connected)) {
vibes_double_pulse();
}
layer_mark_dirty(s_min_layer);
if (bt_connected) {
text_layer_set_text(s_bt_label, "");
} else {
text_layer_set_text(s_bt_label, "");
}
}
static void init() {
@ -138,7 +173,7 @@ static void init() {
}
bluetooth_connection_service_subscribe(bt_handler);
bt_connected = bluetooth_connection_service_peek();
bt_handler(bluetooth_connection_service_peek());
}
static void deinit() {

View File

@ -1,42 +0,0 @@
#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}
}
};