Prepare for settings
This commit is contained in:
parent
9dea22c5a3
commit
c755eb7f6a
|
@ -25,7 +25,7 @@
|
|||
"chalk"
|
||||
],
|
||||
"uuid": "e7872ba0-6697-41f3-9e18-43effc3b6dfe",
|
||||
"versionLabel": "1.0",
|
||||
"versionLabel": "1.2",
|
||||
"watchapp": {
|
||||
"watchface": true
|
||||
}
|
||||
|
|
70
src/main.c
70
src/main.c
|
@ -3,7 +3,7 @@
|
|||
|
||||
#define MINLEN 58
|
||||
#define HRCIRCLER 30
|
||||
#define NRINGS 12
|
||||
#define NRINGS 17
|
||||
#define MINCIRCLER 20
|
||||
|
||||
#define fatness 14
|
||||
|
@ -18,6 +18,9 @@ GPoint center, mincenter;
|
|||
int32_t min_angle, sec_angle;
|
||||
char hrstr[3], minstr[3];
|
||||
bool min_even;
|
||||
bool show_seconds = false;
|
||||
bool bt_vibe = true;
|
||||
bool shape = 0;
|
||||
|
||||
bool bt_connected;
|
||||
|
||||
|
@ -30,14 +33,59 @@ GColor *rings[nringcolors] = {
|
|||
&GColorWhite,
|
||||
};
|
||||
|
||||
const GPoint SUN_POINTS[] = {
|
||||
{0, 119},{78, 162},{93, 74},{175, 40},{116, -26},{140, -112},{52, -108},{0, -180},{-52, -108},{-140, -112},{-116, -26},{-175, 40},{-93, 74},{-78, 162},{0}
|
||||
};
|
||||
|
||||
// r = 180; tau = math.pi*2
|
||||
// print ','.join(["{%s, %s}"%(int(r/(i%2+1)*sin(tau*(i/10.0))), int(r/(i%2+1)*cos(tau*(i/10.0)))) for i in range(10)])
|
||||
const GPoint STAR_POINTS[] = {
|
||||
{0, 180},{52, 72},{171, 55},{85, -27},{105, -145},{0, -90},{-105, -145},{-85, -27},{-171, 55},{-52, 72},{0}
|
||||
};
|
||||
|
||||
const GPoint SQUARE_POINTS[] = {
|
||||
{0, 180},{180, 0},{0, -180},{-180, 0},{0}
|
||||
};
|
||||
|
||||
// print ','.join(["{%s, %s}"%(int(r*sin(tau*(i/3.0))), int(r*cos(tau*(i/3.0)))) for i in range(3)])
|
||||
const GPoint TRIANGLE_POINTS[] = {
|
||||
{0, 180},{155, -90},{-155, -90},{0}
|
||||
};
|
||||
|
||||
GPath shape_path = {
|
||||
0,
|
||||
(GPoint [15]){{0}},
|
||||
0,
|
||||
{0}
|
||||
};
|
||||
|
||||
static void min_update_proc(Layer *layer, GContext *ctx) {
|
||||
graphics_context_set_fill_color(ctx, *rings[0]);
|
||||
graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
|
||||
|
||||
gpath_move_to(&shape_path, mincenter);
|
||||
gpath_rotate_to(&shape_path, min_angle + DEG_TO_TRIGANGLE(180));
|
||||
|
||||
for (int i = 0; i < NRINGS; i += 1) {
|
||||
graphics_context_set_fill_color(ctx, *rings[(NRINGS - i) % nringcolors]);
|
||||
if (shape) {
|
||||
for (unsigned int j = 0; ; j += 1) {
|
||||
GPoint p;
|
||||
|
||||
p = SUN_POINTS[j];
|
||||
|
||||
if ((p.x == 0) && (p.y == 0)) {
|
||||
shape_path.num_points = j;
|
||||
break;
|
||||
}
|
||||
shape_path.points[j].x = p.x * (NRINGS - i) / 10;
|
||||
shape_path.points[j].y = p.y * (NRINGS - i) / 10;
|
||||
}
|
||||
gpath_draw_filled(ctx, &shape_path);
|
||||
} else {
|
||||
graphics_fill_circle(ctx, mincenter, MINCIRCLER + (NRINGS - i) * fatness);
|
||||
}
|
||||
}
|
||||
|
||||
// center dot
|
||||
if (bt_connected) {
|
||||
|
@ -93,6 +141,10 @@ static void hr_update_proc(Layer *layer, GContext *ctx) {
|
|||
}
|
||||
|
||||
static void sec_update_proc(Layer *layer, GContext *ctx) {
|
||||
if (! show_seconds) {
|
||||
return;
|
||||
}
|
||||
|
||||
GRect secbox = {
|
||||
.origin = {
|
||||
.x = mincenter.x - (40+2)/2,
|
||||
|
@ -114,7 +166,7 @@ static void sec_update_proc(Layer *layer, GContext *ctx) {
|
|||
|
||||
|
||||
static void handle_tick(struct tm *tick_time, TimeUnits units_changed) {
|
||||
if (units_changed && HOUR_UNIT) {
|
||||
if (units_changed & HOUR_UNIT) {
|
||||
if (clock_is_24h_style()) {
|
||||
strftime(hrstr, sizeof(hrstr), "%H", tick_time);
|
||||
} else {
|
||||
|
@ -123,17 +175,17 @@ static void handle_tick(struct tm *tick_time, TimeUnits units_changed) {
|
|||
layer_mark_dirty(s_hr_layer);
|
||||
}
|
||||
|
||||
if (units_changed && MINUTE_UNIT) {
|
||||
if (units_changed & MINUTE_UNIT) {
|
||||
strftime(minstr, sizeof(minstr), "%M", tick_time);
|
||||
min_angle = DEG_TO_TRIGANGLE(tick_time->tm_min * 6);
|
||||
mincenter.x = (int16_t)(sin_lookup(min_angle) * MINLEN / TRIG_MAX_RATIO) + center.x;
|
||||
mincenter.y = (int16_t)(-cos_lookup(min_angle) * MINLEN / TRIG_MAX_RATIO) + center.y;
|
||||
min_even = (tick_time->tm_min % 2 == 0);
|
||||
|
||||
layer_mark_dirty(s_min_layer);
|
||||
min_even = (tick_time->tm_min % 2 == 0);
|
||||
}
|
||||
|
||||
if (units_changed && SECOND_UNIT) {
|
||||
if (units_changed & SECOND_UNIT) {
|
||||
sec_angle = DEG_TO_TRIGANGLE(tick_time->tm_sec * 6);
|
||||
layer_mark_dirty(s_sec_layer);
|
||||
}
|
||||
|
@ -163,7 +215,11 @@ static void window_load(Window *window) {
|
|||
|
||||
time_t now = time(NULL);
|
||||
struct tm *tick_time = localtime(&now);
|
||||
if (show_seconds) {
|
||||
handle_tick(tick_time, HOUR_UNIT | MINUTE_UNIT | SECOND_UNIT);
|
||||
} else {
|
||||
handle_tick(tick_time, HOUR_UNIT | MINUTE_UNIT);
|
||||
}
|
||||
}
|
||||
|
||||
static void window_unload(Window *window) {
|
||||
|
@ -174,7 +230,7 @@ static void window_unload(Window *window) {
|
|||
|
||||
static void bt_handler(bool connected) {
|
||||
bt_connected = connected;
|
||||
if (! connected) {
|
||||
if (bt_vibe && (! connected)) {
|
||||
vibes_double_pulse();
|
||||
}
|
||||
layer_mark_dirty(s_min_layer);
|
||||
|
@ -188,8 +244,6 @@ static void init() {
|
|||
});
|
||||
window_stack_push(window, true);
|
||||
|
||||
tick_timer_service_subscribe(HOUR_UNIT | MINUTE_UNIT | SECOND_UNIT, handle_tick);
|
||||
|
||||
bluetooth_connection_service_subscribe(bt_handler);
|
||||
bt_connected = bluetooth_connection_service_peek();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue