mirror of
https://github.com/alinanorakari/Pebble-Time-Watchface-Super-Simple.git
synced 2025-12-14 15:45:22 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eebb13b2de | |||
| 626d922c57 | |||
| adfcf45283 | |||
| 18223442d0 | |||
| 9d7b3a945a |
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"appKeys": {
|
"appKeys": {
|
||||||
|
"btvibe": 8,
|
||||||
"colorbg": 0,
|
"colorbg": 0,
|
||||||
"colorh": 2,
|
"colorh": 2,
|
||||||
"colorm": 1,
|
"colorm": 1,
|
||||||
@@ -25,7 +26,7 @@
|
|||||||
"chalk"
|
"chalk"
|
||||||
],
|
],
|
||||||
"uuid": "ceeae81b-6b50-43b6-8bbb-6d6f6eb62b69",
|
"uuid": "ceeae81b-6b50-43b6-8bbb-6d6f6eb62b69",
|
||||||
"versionLabel": "1.5",
|
"versionLabel": "1.7",
|
||||||
"watchapp": {
|
"watchapp": {
|
||||||
"watchface": true
|
"watchface": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Pebble.addEventListener('showConfiguration', function() {
|
|||||||
if(Pebble.getActiveWatchInfo) {
|
if(Pebble.getActiveWatchInfo) {
|
||||||
watch = Pebble.getActiveWatchInfo();
|
watch = Pebble.getActiveWatchInfo();
|
||||||
}
|
}
|
||||||
var url='http://pebble.lastfuture.de/config/supersimple15/';
|
var url='http://pebble.lastfuture.de/config/supersimple17/';
|
||||||
if (watch.platform != "chalk") {
|
if (watch.platform != "chalk") {
|
||||||
url += "?rect=true";
|
url += "?rect=true";
|
||||||
}
|
}
|
||||||
@@ -24,10 +24,11 @@ Pebble.addEventListener('webviewclosed', function(e) {
|
|||||||
colorm: parseInt(configData.colorm, 16),
|
colorm: parseInt(configData.colorm, 16),
|
||||||
colorh: parseInt(configData.colorh, 16),
|
colorh: parseInt(configData.colorh, 16),
|
||||||
colorp: parseInt(configData.colorp, 16),
|
colorp: parseInt(configData.colorp, 16),
|
||||||
shadows: configData.shadows === 'true',
|
shadows: 0+(configData.shadows === 'true'),
|
||||||
ticks: configData.ticks,
|
ticks: configData.ticks,
|
||||||
colort: parseInt(configData.colort, 16),
|
colort: parseInt(configData.colort, 16),
|
||||||
rectticks: configData.rectticks === 'true'
|
rectticks: 0+(configData.rectticks === 'true'),
|
||||||
|
btvibe: 0+(configData.btvibe === 'true')
|
||||||
}, function() {
|
}, function() {
|
||||||
console.log('Send successful!');
|
console.log('Send successful!');
|
||||||
}, function() {
|
}, function() {
|
||||||
|
|||||||
151
src/main.c
151
src/main.c
@@ -8,6 +8,7 @@
|
|||||||
#define KEY_TICKS 5
|
#define KEY_TICKS 5
|
||||||
#define KEY_TICK_COLOR 6
|
#define KEY_TICK_COLOR 6
|
||||||
#define KEY_RECT_TICKS 7
|
#define KEY_RECT_TICKS 7
|
||||||
|
#define KEY_BT_VIBE 8
|
||||||
|
|
||||||
#define ANTIALIASING true
|
#define ANTIALIASING true
|
||||||
|
|
||||||
@@ -47,12 +48,12 @@ typedef struct {
|
|||||||
} Time;
|
} Time;
|
||||||
|
|
||||||
static Window *s_main_window;
|
static Window *s_main_window;
|
||||||
static Layer *s_canvas_layer;
|
static Layer *bg_canvas_layer, *s_canvas_layer;
|
||||||
|
|
||||||
static GPoint s_center;
|
static GPoint s_center;
|
||||||
static Time s_last_time;
|
static Time s_last_time;
|
||||||
static int animpercent = 0, ticks;
|
static int animpercent = 0, ticks;
|
||||||
static bool s_animating = false, shadows = true, debug = false, rectticks = true;
|
static bool s_animating = false, shadows = true, debug = false, rectticks = true, btvibe = false;
|
||||||
|
|
||||||
static GColor gcolorbg, gcolorm, gcolorh, gcolorp, gcolorshadow, gcolort;
|
static GColor gcolorbg, gcolorm, gcolorh, gcolorp, gcolorshadow, gcolort;
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
|||||||
Tuple *ticknum_t = dict_find(iter, KEY_TICKS);
|
Tuple *ticknum_t = dict_find(iter, KEY_TICKS);
|
||||||
Tuple *colort_t = dict_find(iter, KEY_TICK_COLOR);
|
Tuple *colort_t = dict_find(iter, KEY_TICK_COLOR);
|
||||||
Tuple *rectticks_t = dict_find(iter, KEY_RECT_TICKS);
|
Tuple *rectticks_t = dict_find(iter, KEY_RECT_TICKS);
|
||||||
|
Tuple *btvibe_t = dict_find(iter, KEY_BT_VIBE);
|
||||||
|
|
||||||
if(colorbg_t) {
|
if(colorbg_t) {
|
||||||
int colorbg = colorbg_t->value->int32;
|
int colorbg = colorbg_t->value->int32;
|
||||||
@@ -87,7 +89,7 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
|||||||
persist_write_int(KEY_PEG_COLOR, colorp);
|
persist_write_int(KEY_PEG_COLOR, colorp);
|
||||||
gcolorp = GColorFromHEX(colorp);
|
gcolorp = GColorFromHEX(colorp);
|
||||||
}
|
}
|
||||||
if(shadows_t && shadows_t->value->int32 > 0) {
|
if(shadows_t && shadows_t->value->int8 > 0) {
|
||||||
persist_write_bool(KEY_SHADOWS, true);
|
persist_write_bool(KEY_SHADOWS, true);
|
||||||
shadows = true;
|
shadows = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -103,16 +105,27 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
|||||||
persist_write_int(KEY_TICK_COLOR, colort);
|
persist_write_int(KEY_TICK_COLOR, colort);
|
||||||
gcolort = GColorFromHEX(colort);
|
gcolort = GColorFromHEX(colort);
|
||||||
}
|
}
|
||||||
if(rectticks_t && rectticks_t->value->int32 > 0) {
|
if(rectticks_t && rectticks_t->value->int8 > 0) {
|
||||||
persist_write_bool(KEY_RECT_TICKS, true);
|
persist_write_bool(KEY_RECT_TICKS, true);
|
||||||
rectticks = true;
|
rectticks = true;
|
||||||
} else {
|
} else {
|
||||||
persist_write_bool(KEY_RECT_TICKS, false);
|
persist_write_bool(KEY_RECT_TICKS, false);
|
||||||
rectticks = false;
|
rectticks = 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;
|
||||||
|
}
|
||||||
|
if(bg_canvas_layer) {
|
||||||
|
layer_mark_dirty(bg_canvas_layer);
|
||||||
|
}
|
||||||
if(s_canvas_layer) {
|
if(s_canvas_layer) {
|
||||||
layer_mark_dirty(s_canvas_layer);
|
layer_mark_dirty(s_canvas_layer);
|
||||||
}
|
}
|
||||||
|
vibes_short_pulse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************** AnimationImplementation **************************/
|
/*************************** AnimationImplementation **************************/
|
||||||
@@ -145,7 +158,7 @@ static void animate(int duration, int delay, AnimationImplementation *implementa
|
|||||||
static void tick_handler(struct tm *tick_time, TimeUnits changed) {
|
static void tick_handler(struct tm *tick_time, TimeUnits changed) {
|
||||||
// Store time
|
// Store time
|
||||||
// dummy time in emulator
|
// dummy time in emulator
|
||||||
if (watch_info_get_model()==WATCH_INFO_MODEL_UNKNOWN) {
|
if (debug) {
|
||||||
s_last_time.hours = 0;
|
s_last_time.hours = 0;
|
||||||
s_last_time.minutes = tick_time->tm_sec;
|
s_last_time.minutes = tick_time->tm_sec;
|
||||||
} else {
|
} else {
|
||||||
@@ -160,6 +173,17 @@ 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) {
|
static int32_t get_angle_for_minute(int minute) {
|
||||||
// Progress through 60 minutes, out of 360 degrees
|
// Progress through 60 minutes, out of 360 degrees
|
||||||
return ((minute * 360) / 60);
|
return ((minute * 360) / 60);
|
||||||
@@ -170,6 +194,58 @@ static int32_t get_angle_for_hour(int hour, int minute) {
|
|||||||
return (((hour * 360) / 12)+(get_angle_for_minute(minute)/12));
|
return (((hour * 360) / 12)+(get_angle_for_minute(minute)/12));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void bg_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);
|
||||||
|
if (ticks > 0) {
|
||||||
|
graphics_context_set_fill_color(ctx, gcolort);
|
||||||
|
#if defined(PBL_RECT)
|
||||||
|
if (rectticks) {
|
||||||
|
int dist_v = 39;
|
||||||
|
int dist_h = 46;
|
||||||
|
int halfwidth = (bounds.size.w/2)-1;
|
||||||
|
int halfheight = (bounds.size.h/2)-1;
|
||||||
|
switch (ticks) {
|
||||||
|
case 12:
|
||||||
|
graphics_fill_circle(ctx, GPoint(halfwidth+dist_h, 4), TICK_RADIUS/2); // 1
|
||||||
|
graphics_fill_circle(ctx, GPoint(halfwidth-dist_h, 4), TICK_RADIUS/2); // 11
|
||||||
|
graphics_fill_circle(ctx, GPoint(halfwidth+dist_h, (bounds.size.h-5)), TICK_RADIUS/2); // 5
|
||||||
|
graphics_fill_circle(ctx, GPoint(halfwidth-dist_h, (bounds.size.h-5)), TICK_RADIUS/2); // 7
|
||||||
|
graphics_fill_circle(ctx, GPoint((bounds.size.w-5), halfheight-dist_v), TICK_RADIUS/2); // 2
|
||||||
|
graphics_fill_circle(ctx, GPoint((bounds.size.w-5), halfheight+dist_v), TICK_RADIUS/2); // 4
|
||||||
|
graphics_fill_circle(ctx, GPoint(4, halfheight-dist_v), TICK_RADIUS/2); // 10
|
||||||
|
graphics_fill_circle(ctx, GPoint(4, halfheight+dist_v), TICK_RADIUS/2); // 8
|
||||||
|
case 4:
|
||||||
|
graphics_fill_circle(ctx, GPoint(halfwidth, (bounds.size.h-3)), TICK_RADIUS); // 6
|
||||||
|
graphics_fill_circle(ctx, GPoint((bounds.size.w-3), halfheight), TICK_RADIUS); // 3
|
||||||
|
graphics_fill_circle(ctx, GPoint(2, halfheight), TICK_RADIUS); // 9
|
||||||
|
case 1:
|
||||||
|
default:
|
||||||
|
graphics_fill_circle(ctx, GPoint(halfwidth, 2), TICK_RADIUS); // 12
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#endif
|
||||||
|
GRect insetbounds = grect_inset(bounds, GEdgeInsets(2));
|
||||||
|
GRect insetbounds12 = grect_inset(bounds, GEdgeInsets(4));
|
||||||
|
for(int i = 0; i < ticks; i++) {
|
||||||
|
int hour_angle = (i * 360) / ticks;
|
||||||
|
if (ticks == 12 && i%3!=0) {
|
||||||
|
GPoint pos = gpoint_from_polar(insetbounds12, GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(hour_angle));
|
||||||
|
graphics_fill_circle(ctx, pos, TICK_RADIUS/2);
|
||||||
|
} else {
|
||||||
|
GPoint pos = gpoint_from_polar(insetbounds, GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(hour_angle));
|
||||||
|
graphics_fill_circle(ctx, pos, TICK_RADIUS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if defined(PBL_RECT)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void update_proc(Layer *layer, GContext *ctx) {
|
static void update_proc(Layer *layer, GContext *ctx) {
|
||||||
GRect bounds = layer_get_bounds(layer);
|
GRect bounds = layer_get_bounds(layer);
|
||||||
GRect bounds_h = bounds;
|
GRect bounds_h = bounds;
|
||||||
@@ -201,8 +277,6 @@ static void update_proc(Layer *layer, GContext *ctx) {
|
|||||||
}
|
}
|
||||||
GRect bounds_mo = grect_inset(bounds_h, GEdgeInsets(outer_m));
|
GRect bounds_mo = grect_inset(bounds_h, GEdgeInsets(outer_m));
|
||||||
GRect bounds_ho = grect_inset(bounds_h, GEdgeInsets(outer_h));
|
GRect bounds_ho = grect_inset(bounds_h, GEdgeInsets(outer_h));
|
||||||
graphics_context_set_fill_color(ctx, gcolorbg);
|
|
||||||
graphics_fill_rect(ctx, bounds, 0, GCornerNone);
|
|
||||||
graphics_context_set_antialiased(ctx, ANTIALIASING);
|
graphics_context_set_antialiased(ctx, ANTIALIASING);
|
||||||
|
|
||||||
// Use current time while animating
|
// Use current time while animating
|
||||||
@@ -215,50 +289,6 @@ static void update_proc(Layer *layer, GContext *ctx) {
|
|||||||
GPoint minute_hand_outer = gpoint_from_polar(bounds_mo, GOvalScaleModeFillCircle, DEG_TO_TRIGANGLE(minute_deg));
|
GPoint minute_hand_outer = gpoint_from_polar(bounds_mo, GOvalScaleModeFillCircle, DEG_TO_TRIGANGLE(minute_deg));
|
||||||
GPoint hour_hand_outer = gpoint_from_polar(bounds_ho, GOvalScaleModeFillCircle, DEG_TO_TRIGANGLE(hour_deg));
|
GPoint hour_hand_outer = gpoint_from_polar(bounds_ho, GOvalScaleModeFillCircle, DEG_TO_TRIGANGLE(hour_deg));
|
||||||
|
|
||||||
if (ticks > 0) {
|
|
||||||
graphics_context_set_fill_color(ctx, gcolort);
|
|
||||||
#if defined(PBL_RECT)
|
|
||||||
if (rectticks) {
|
|
||||||
int dist_v = 41;
|
|
||||||
int dist_h = 44;
|
|
||||||
switch (ticks) {
|
|
||||||
case 12:
|
|
||||||
graphics_fill_circle(ctx, GPoint((bounds.size.w/2)+dist_h, 4), TICK_RADIUS/2); // 1
|
|
||||||
graphics_fill_circle(ctx, GPoint((bounds.size.w/2)-dist_h, 4), TICK_RADIUS/2); // 11
|
|
||||||
graphics_fill_circle(ctx, GPoint((bounds.size.w/2)+dist_h, (bounds.size.h-5)), TICK_RADIUS/2); // 5
|
|
||||||
graphics_fill_circle(ctx, GPoint((bounds.size.w/2)-dist_h, (bounds.size.h-5)), TICK_RADIUS/2); // 7
|
|
||||||
graphics_fill_circle(ctx, GPoint((bounds.size.w-5), (bounds.size.h/2)-dist_v), TICK_RADIUS/2); // 2
|
|
||||||
graphics_fill_circle(ctx, GPoint((bounds.size.w-5), (bounds.size.h/2)+dist_v), TICK_RADIUS/2); // 4
|
|
||||||
graphics_fill_circle(ctx, GPoint(4, (bounds.size.h/2)-dist_v), TICK_RADIUS/2); // 10
|
|
||||||
graphics_fill_circle(ctx, GPoint(4, (bounds.size.h/2)+dist_v), TICK_RADIUS/2); // 8
|
|
||||||
case 4:
|
|
||||||
graphics_fill_circle(ctx, GPoint((bounds.size.w/2), (bounds.size.h-3)), TICK_RADIUS); // 6
|
|
||||||
graphics_fill_circle(ctx, GPoint((bounds.size.w-3), (bounds.size.h/2)), TICK_RADIUS); // 3
|
|
||||||
graphics_fill_circle(ctx, GPoint(2, (bounds.size.h/2)), TICK_RADIUS); // 9
|
|
||||||
case 1:
|
|
||||||
default:
|
|
||||||
graphics_fill_circle(ctx, GPoint((bounds.size.w/2), 2), TICK_RADIUS); // 12
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
#endif
|
|
||||||
GRect insetbounds = grect_inset(bounds, GEdgeInsets(2));
|
|
||||||
GRect insetbounds12 = grect_inset(bounds, GEdgeInsets(4));
|
|
||||||
for(int i = 0; i < ticks; i++) {
|
|
||||||
int hour_angle = (i * 360) / ticks;
|
|
||||||
if (ticks == 12 && i%3!=0) {
|
|
||||||
GPoint pos = gpoint_from_polar(insetbounds12, GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(hour_angle));
|
|
||||||
graphics_fill_circle(ctx, pos, TICK_RADIUS/2);
|
|
||||||
} else {
|
|
||||||
GPoint pos = gpoint_from_polar(insetbounds, GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(hour_angle));
|
|
||||||
graphics_fill_circle(ctx, pos, TICK_RADIUS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#if defined(PBL_RECT)
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if(shadows) {
|
if(shadows) {
|
||||||
graphics_context_set_stroke_color(ctx, gcolorshadow);
|
graphics_context_set_stroke_color(ctx, gcolorshadow);
|
||||||
graphics_context_set_stroke_width(ctx, HAND_WIDTH);
|
graphics_context_set_stroke_width(ctx, HAND_WIDTH);
|
||||||
@@ -337,13 +367,22 @@ static void window_load(Window *window) {
|
|||||||
} else {
|
} else {
|
||||||
rectticks = false;
|
rectticks = 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);
|
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_set_update_proc(s_canvas_layer, update_proc);
|
||||||
layer_add_child(window_layer, s_canvas_layer);
|
layer_add_child(window_layer, bg_canvas_layer);
|
||||||
|
layer_add_child(bg_canvas_layer, s_canvas_layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_unload(Window *window) {
|
static void window_unload(Window *window) {
|
||||||
|
layer_destroy(bg_canvas_layer);
|
||||||
layer_destroy(s_canvas_layer);
|
layer_destroy(s_canvas_layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,7 +429,13 @@ static void init() {
|
|||||||
if (debug) {
|
if (debug) {
|
||||||
light_enable(true);
|
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_register_inbox_received(inbox_received_handler);
|
||||||
app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
|
app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user