Compare commits
No commits in common. "master" and "1.0" have entirely different histories.
|
@ -1,13 +1,11 @@
|
|||
{
|
||||
"appKeys": {
|
||||
"btvibe": 2,
|
||||
"colors": 0,
|
||||
"inverse": 1
|
||||
"colors": 0
|
||||
},
|
||||
"capabilities": [
|
||||
"configurable"
|
||||
],
|
||||
"companyName": "lastfuture",
|
||||
"companyName": "lastfuture@lastfuture.de",
|
||||
"longName": "Arcangle",
|
||||
"projectType": "native",
|
||||
"resources": {
|
||||
|
@ -19,7 +17,7 @@
|
|||
"chalk"
|
||||
],
|
||||
"uuid": "000fd62a-3f0a-4bdd-a118-b3caa48893a0",
|
||||
"versionLabel": "1.3",
|
||||
"versionLabel": "1.0",
|
||||
"watchapp": {
|
||||
"watchface": true
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ Pebble.addEventListener('ready', function() {
|
|||
});
|
||||
|
||||
Pebble.addEventListener('showConfiguration', function() {
|
||||
var url='http://pebble.lastfuture.de/config/arcangle13/';
|
||||
var url='http://pebble.lastfuture.de/config/arcangle10/';
|
||||
console.log('Showing configuration page: '+url);
|
||||
Pebble.openURL(url);
|
||||
});
|
||||
|
@ -13,9 +13,7 @@ Pebble.addEventListener('webviewclosed', function(e) {
|
|||
console.log('Configuration page returned: '+JSON.stringify(configData));
|
||||
if (configData.colors) {
|
||||
Pebble.sendAppMessage({
|
||||
colors: configData.colors,
|
||||
inverse: 0+(configData.inverse === true),
|
||||
btvibe: 0+(configData.btvibe === true)
|
||||
colors: configData.colors
|
||||
}, function() {
|
||||
console.log('Send successful!');
|
||||
}, function() {
|
||||
|
|
208
src/main.c
208
src/main.c
|
@ -1,17 +1,15 @@
|
|||
#include <pebble.h>
|
||||
|
||||
#define KEY_COLORS 0
|
||||
#define KEY_INVERSE 1
|
||||
#define KEY_BT_VIBE 2
|
||||
|
||||
#define ANTIALIASING true
|
||||
#define INVERSE true
|
||||
|
||||
#define FINAL_RADIUS 90
|
||||
#define FINAL_RADIUS 88
|
||||
#define HAND_WIDTH 6
|
||||
#define HAND_MARGIN_OUTER 15
|
||||
#define HAND_MARGIN_MIDDLE 32
|
||||
#define HAND_MARGIN_INNER 40
|
||||
#define TICK_RADIUS 3
|
||||
#define HAND_MARGIN_OUTER 16
|
||||
#define HAND_MARGIN_INNER 50
|
||||
#define SHADOW_OFFSET 2
|
||||
#define GRID_SPACING 18
|
||||
|
||||
#define ANIMATION_DURATION 400
|
||||
|
@ -23,12 +21,13 @@ typedef struct {
|
|||
} Time;
|
||||
|
||||
static Window *s_main_window;
|
||||
static Layer *bg_canvas_layer, *s_canvas_layer;
|
||||
static Layer *s_canvas_layer;
|
||||
|
||||
static GPoint s_center;
|
||||
static Time s_last_time;
|
||||
static int colors = 1;
|
||||
static bool s_animating = false, debug = false, inverse = false, btvibe = false;
|
||||
static int s_radius = 0, colors = 1;
|
||||
static bool s_animating = false, debug = false;
|
||||
static float anim_offset;
|
||||
|
||||
static GColor gcolorbg, gcolorh, gcolort;
|
||||
|
||||
|
@ -57,69 +56,19 @@ static void handle_colorchange() {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
if (inverse) {
|
||||
GColor tempcolor = gcolorh;
|
||||
gcolorh = gcolort;
|
||||
gcolort = tempcolor;
|
||||
switch (colors) {
|
||||
case 1: // greens
|
||||
gcolorh = GColorDarkGreen;
|
||||
gcolort = GColorMediumAquamarine;
|
||||
break;
|
||||
|
||||
case 3: // blues
|
||||
gcolort = GColorPictonBlue;
|
||||
break;
|
||||
|
||||
case 2: // reds
|
||||
gcolort = GColorMelon;
|
||||
break;
|
||||
|
||||
case 4: // greys
|
||||
gcolort = GColorLightGray;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (inverse) {
|
||||
gcolorbg = GColorWhite;
|
||||
} else {
|
||||
gcolorbg = GColorBlack;
|
||||
}
|
||||
}
|
||||
|
||||
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
||||
Tuple *colors_t = dict_find(iter, KEY_COLORS);
|
||||
Tuple *inverse_t = dict_find(iter, KEY_INVERSE);
|
||||
Tuple *btvibe_t = dict_find(iter, KEY_BT_VIBE);
|
||||
|
||||
if(colors_t) {
|
||||
colors = colors_t->value->uint8;
|
||||
persist_write_int(KEY_COLORS, colors);
|
||||
}
|
||||
if(inverse_t && inverse_t->value->int8 > 0) {
|
||||
persist_write_bool(KEY_INVERSE, true);
|
||||
inverse = true;
|
||||
} else {
|
||||
persist_write_bool(KEY_INVERSE, false);
|
||||
inverse = false;
|
||||
}
|
||||
if(btvibe_t && btvibe_t->value->int8 > 0) {
|
||||
persist_write_bool(KEY_BT_VIBE, true);
|
||||
btvibe = true;
|
||||
} else {
|
||||
persist_write_bool(KEY_BT_VIBE, false);
|
||||
btvibe = false;
|
||||
}
|
||||
handle_colorchange();
|
||||
if(bg_canvas_layer) {
|
||||
layer_mark_dirty(bg_canvas_layer);
|
||||
}
|
||||
if(s_canvas_layer) {
|
||||
layer_mark_dirty(s_canvas_layer);
|
||||
}
|
||||
vibes_short_pulse();
|
||||
}
|
||||
|
||||
/*************************** AnimationImplementation **************************/
|
||||
|
@ -153,7 +102,7 @@ static void tick_handler(struct tm *tick_time, TimeUnits changed) {
|
|||
// Store time
|
||||
// dummy time in emulator
|
||||
if (debug) {
|
||||
s_last_time.hours = 11;
|
||||
s_last_time.hours = 8;
|
||||
s_last_time.minutes = tick_time->tm_sec;
|
||||
} else {
|
||||
s_last_time.hours = tick_time->tm_hour;
|
||||
|
@ -167,17 +116,6 @@ static void tick_handler(struct tm *tick_time, TimeUnits changed) {
|
|||
}
|
||||
}
|
||||
|
||||
static void handle_bluetooth(bool connected) {
|
||||
if (btvibe && !connected) {
|
||||
static uint32_t const segments[] = { 200, 200, 50, 150, 200 };
|
||||
VibePattern pat = {
|
||||
.durations = segments,
|
||||
.num_segments = ARRAY_LENGTH(segments),
|
||||
};
|
||||
vibes_enqueue_custom_pattern(pat);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t get_angle_for_minute(int minute) {
|
||||
// Progress through 60 minutes, out of 360 degrees
|
||||
return (minute * 360) / 60;
|
||||
|
@ -188,11 +126,43 @@ static int32_t get_angle_for_hour(int hour, int minute) {
|
|||
return ((hour * 360) / 12)+(get_angle_for_minute(minute)/12);
|
||||
}
|
||||
|
||||
static void bg_update_proc(Layer *layer, GContext *ctx) {
|
||||
static void update_proc(Layer *layer, GContext *ctx) {
|
||||
GRect bounds = layer_get_bounds(layer);
|
||||
graphics_context_set_fill_color(ctx, gcolorbg);
|
||||
graphics_fill_rect(ctx, bounds, 0, GCornerNone);
|
||||
graphics_context_set_antialiased(ctx, ANTIALIASING);
|
||||
|
||||
// Use current time while animating
|
||||
Time mode_time = s_last_time;
|
||||
|
||||
// Adjust for minutes through the hour
|
||||
float hour_angle = TRIG_MAX_ANGLE * mode_time.hours / 12;
|
||||
float minute_angle = TRIG_MAX_ANGLE * mode_time.minutes / 60;
|
||||
float hour_deg = get_angle_for_hour(mode_time.hours, mode_time.minutes);
|
||||
float minute_deg = get_angle_for_minute(mode_time.minutes);
|
||||
hour_angle += (minute_angle / TRIG_MAX_ANGLE) * (TRIG_MAX_ANGLE / 12);
|
||||
if (s_animating) {
|
||||
hour_angle += anim_offset;
|
||||
minute_angle -= anim_offset;
|
||||
}
|
||||
|
||||
GPoint minute_hand_outer = (GPoint) {
|
||||
.x = (int16_t)(sin_lookup(TRIG_MAX_ANGLE * mode_time.minutes / 60) * (int32_t)(s_radius - HAND_MARGIN_OUTER) / TRIG_MAX_RATIO) + s_center.x,
|
||||
.y = (int16_t)(-cos_lookup(TRIG_MAX_ANGLE * mode_time.minutes / 60) * (int32_t)(s_radius - HAND_MARGIN_OUTER) / TRIG_MAX_RATIO) + s_center.y,
|
||||
};
|
||||
GPoint minute_hand_inner = (GPoint) {
|
||||
.x = (int16_t)(sin_lookup(TRIG_MAX_ANGLE * mode_time.minutes / 60) * ((int32_t)HAND_MARGIN_INNER+1) / TRIG_MAX_RATIO) + s_center.x,
|
||||
.y = (int16_t)(-cos_lookup(TRIG_MAX_ANGLE * mode_time.minutes / 60) * ((int32_t)HAND_MARGIN_INNER+1) / TRIG_MAX_RATIO) + s_center.y,
|
||||
};
|
||||
GPoint hour_hand_outer = (GPoint) {
|
||||
.x = (int16_t)(sin_lookup(hour_angle) * (int32_t)(s_radius - HAND_MARGIN_OUTER - (0.35 * s_radius)) / TRIG_MAX_RATIO) + s_center.x,
|
||||
.y = (int16_t)(-cos_lookup(hour_angle) * (int32_t)(s_radius - HAND_MARGIN_OUTER - (0.35 * s_radius)) / TRIG_MAX_RATIO) + s_center.y,
|
||||
};
|
||||
GPoint hour_hand_inner = (GPoint) {
|
||||
.x = (int16_t)(sin_lookup(hour_angle) * (int32_t)HAND_MARGIN_INNER / TRIG_MAX_RATIO) + s_center.x,
|
||||
.y = (int16_t)(-cos_lookup(hour_angle) * (int32_t)HAND_MARGIN_INNER / TRIG_MAX_RATIO) + s_center.y,
|
||||
};
|
||||
|
||||
graphics_context_set_stroke_color(ctx, gcolort);
|
||||
graphics_context_set_stroke_width(ctx, 1);
|
||||
for (int gx=0; gx<bounds.size.h; gx += GRID_SPACING) {
|
||||
|
@ -200,51 +170,41 @@ static void bg_update_proc(Layer *layer, GContext *ctx) {
|
|||
GPoint gxbot = (GPoint) { .x = gx, .y = bounds.size.h };
|
||||
graphics_draw_line(ctx, gxtop, gxbot);
|
||||
}
|
||||
|
||||
for (int gy=0; gy<bounds.size.w; gy += GRID_SPACING) {
|
||||
GPoint gxtop = (GPoint) { .y = gy, .x = 0 };
|
||||
GPoint gxbot = (GPoint) { .y = gy, .x = bounds.size.w };
|
||||
graphics_draw_line(ctx, gxtop, gxbot);
|
||||
}
|
||||
}
|
||||
|
||||
static void update_proc(Layer *layer, GContext *ctx) {
|
||||
GRect bounds = layer_get_bounds(layer);
|
||||
GRect bounds_mo = grect_inset(bounds, GEdgeInsets(HAND_MARGIN_OUTER));
|
||||
GRect bounds_mi = grect_inset(bounds, GEdgeInsets(HAND_MARGIN_MIDDLE-1));
|
||||
GRect bounds_m = grect_inset(bounds, GEdgeInsets(HAND_MARGIN_MIDDLE));
|
||||
GRect bounds_ho = grect_inset(bounds, GEdgeInsets(HAND_MARGIN_MIDDLE+1));
|
||||
GRect bounds_hi = grect_inset(bounds, GEdgeInsets(HAND_MARGIN_INNER));
|
||||
|
||||
// Use current time while animating
|
||||
Time mode_time = s_last_time;
|
||||
|
||||
// Adjust for minutes through the hour
|
||||
float hour_deg = get_angle_for_hour(mode_time.hours, mode_time.minutes);
|
||||
float minute_deg = get_angle_for_minute(mode_time.minutes);
|
||||
|
||||
GPoint minute_hand_outer = gpoint_from_polar(bounds_mo, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(minute_deg));
|
||||
GPoint minute_hand_inner = gpoint_from_polar(bounds_mi, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(minute_deg));
|
||||
GPoint hour_hand_outer = gpoint_from_polar(bounds_ho, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(hour_deg));
|
||||
GPoint hour_hand_inner = gpoint_from_polar(bounds_hi, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(hour_deg));
|
||||
|
||||
if((s_radius - HAND_MARGIN_OUTER) > HAND_MARGIN_INNER) {
|
||||
if(s_radius > 2 * HAND_MARGIN_OUTER) {
|
||||
graphics_context_set_stroke_color(ctx, gcolorh);
|
||||
graphics_context_set_stroke_width(ctx, HAND_WIDTH);
|
||||
graphics_draw_line(ctx, hour_hand_inner, hour_hand_outer);
|
||||
}
|
||||
if(s_radius > HAND_MARGIN_OUTER) {
|
||||
graphics_context_set_stroke_color(ctx, gcolorh);
|
||||
graphics_context_set_stroke_width(ctx, HAND_WIDTH);
|
||||
graphics_draw_line(ctx, minute_hand_inner, minute_hand_outer);
|
||||
}
|
||||
GRect frame = grect_inset(bounds, GEdgeInsets(37));
|
||||
graphics_context_set_fill_color(ctx, gcolorh);
|
||||
if (minute_deg > hour_deg && minute_deg-hour_deg > 180) {
|
||||
hour_deg += 360;
|
||||
} else if (minute_deg < hour_deg && hour_deg-minute_deg > 180) {
|
||||
minute_deg += 360;
|
||||
}
|
||||
graphics_context_set_stroke_width(ctx, HAND_WIDTH+1);
|
||||
if (minute_deg < hour_deg) {
|
||||
graphics_draw_arc(ctx, bounds_m, GOvalScaleModeFitCircle,
|
||||
DEG_TO_TRIGANGLE(minute_deg),
|
||||
DEG_TO_TRIGANGLE(hour_deg));
|
||||
graphics_fill_radial(ctx, frame, GOvalScaleModeFitCircle, HAND_WIDTH,
|
||||
DEG_TO_TRIGANGLE(minute_deg-1),
|
||||
DEG_TO_TRIGANGLE(hour_deg+1));
|
||||
} else {
|
||||
graphics_draw_arc(ctx, bounds_m, GOvalScaleModeFitCircle,
|
||||
DEG_TO_TRIGANGLE(hour_deg),
|
||||
DEG_TO_TRIGANGLE(minute_deg));
|
||||
graphics_fill_radial(ctx, frame, GOvalScaleModeFitCircle, HAND_WIDTH,
|
||||
DEG_TO_TRIGANGLE(hour_deg-1),
|
||||
DEG_TO_TRIGANGLE(minute_deg+1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -253,40 +213,35 @@ static void window_load(Window *window) {
|
|||
GRect window_bounds = layer_get_bounds(window_layer);
|
||||
|
||||
s_center = grect_center_point(&window_bounds);
|
||||
s_center.x -= 1;
|
||||
s_center.y -= 1;
|
||||
|
||||
if (persist_exists(KEY_COLORS)) {
|
||||
colors = persist_read_int(KEY_COLORS);
|
||||
} else {
|
||||
colors = 1;
|
||||
}
|
||||
if (persist_exists(KEY_INVERSE)) {
|
||||
inverse = persist_read_bool(KEY_INVERSE);
|
||||
} else {
|
||||
inverse = false;
|
||||
}
|
||||
if (persist_exists(KEY_BT_VIBE)) {
|
||||
btvibe = persist_read_bool(KEY_BT_VIBE);
|
||||
} else {
|
||||
btvibe = false;
|
||||
}
|
||||
|
||||
bg_canvas_layer = layer_create(window_bounds);
|
||||
|
||||
|
||||
s_canvas_layer = layer_create(window_bounds);
|
||||
layer_set_update_proc(bg_canvas_layer, bg_update_proc);
|
||||
layer_set_update_proc(s_canvas_layer, update_proc);
|
||||
layer_add_child(window_layer, bg_canvas_layer);
|
||||
layer_add_child(bg_canvas_layer, s_canvas_layer);
|
||||
layer_add_child(window_layer, s_canvas_layer);
|
||||
}
|
||||
|
||||
static void window_unload(Window *window) {
|
||||
layer_destroy(bg_canvas_layer);
|
||||
layer_destroy(s_canvas_layer);
|
||||
}
|
||||
|
||||
/*********************************** App **************************************/
|
||||
|
||||
static int anim_percentage(AnimationProgress dist_normalized, int max) {
|
||||
return (int)(float)(((float)dist_normalized / (float)ANIMATION_NORMALIZED_MAX) * (float)max);
|
||||
}
|
||||
|
||||
static void radius_update(Animation *anim, AnimationProgress dist_normalized) {
|
||||
s_radius = anim_percentage(dist_normalized, FINAL_RADIUS);
|
||||
layer_mark_dirty(s_canvas_layer);
|
||||
}
|
||||
|
||||
static void init() {
|
||||
srand(time(NULL));
|
||||
|
||||
|
@ -309,12 +264,7 @@ static void init() {
|
|||
});
|
||||
window_stack_push(s_main_window, true);
|
||||
|
||||
if (inverse) {
|
||||
gcolorbg = GColorWhite;
|
||||
} else {
|
||||
gcolorbg = GColorBlack;
|
||||
}
|
||||
|
||||
gcolorh = GColorMediumSpringGreen;
|
||||
gcolort = GColorMidnightGreen;
|
||||
|
||||
|
@ -330,14 +280,16 @@ static void init() {
|
|||
light_enable(true);
|
||||
}
|
||||
|
||||
handle_bluetooth(connection_service_peek_pebble_app_connection());
|
||||
|
||||
connection_service_subscribe((ConnectionHandlers) {
|
||||
.pebble_app_connection_handler = handle_bluetooth
|
||||
});
|
||||
|
||||
app_message_register_inbox_received(inbox_received_handler);
|
||||
app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
|
||||
|
||||
|
||||
|
||||
// Prepare animations
|
||||
AnimationImplementation radius_impl = {
|
||||
.update = radius_update
|
||||
};
|
||||
animate(ANIMATION_DURATION, ANIMATION_DELAY, &radius_impl, false);
|
||||
}
|
||||
|
||||
static void deinit() {
|
||||
|
|
Loading…
Reference in New Issue