1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#include <pebble.h>
Window *window;
TextLayer *text_layer;
GFont *font;
AppTimer *timer;
char text[300];
int time_ticks = 0;
int state = 0;
int interval = 150;
char cursor = 0;
void draw_text();
void app_timer(void * data)
{
time_ticks++;
draw_text();
}
void draw_text()
{
time_t t = time(NULL);
struct tm * tick_time = localtime(&t);
snprintf(text, sizeof(text), "C:\\>time /t\n%02d:%02d\n\nC:\\>date /t\n%02d.%02d.%04d", tick_time->tm_hour, tick_time->tm_min, tick_time->tm_mday, tick_time->tm_mon+1, tick_time->tm_year+1900);
if (time_ticks >= 2)
{
state++;
time_ticks = 0;
}
cursor ^= 1;
if (state <= 6)
{
text[4+state] = cursor ? '_' : ' ';
text[5+state] = 0;
}
else if (state < 14)
{
text[16+state] = cursor ? '_' : ' ';
text[17+state] = 0;
} else timer = NULL;
if (state < 14)
{
timer = app_timer_register(interval, app_timer, NULL);
}
text_layer_set_text(text_layer, text);
}
void start_draw()
{
time_ticks = state = 0;
draw_text();
}
void tick(struct tm *tick_time, TimeUnits units_changed)
{
start_draw();
}
void handle_init(void) {
// Create a window and text layer
window = window_create();
window_set_background_color(window, GColorBlack);
text_layer = text_layer_create(GRect(2, -5, 144, 168));
font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TERMINAL_32));
// Set the text, font, and text alignment
text_layer_set_font(text_layer, font);
text_layer_set_text_alignment(text_layer, GTextAlignmentLeft);
text_layer_set_text_color(text_layer, GColorWhite);
text_layer_set_background_color(text_layer, GColorClear);
text_layer_set_text(text_layer, "C:\\>");
// Add the text layer to the window
layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer));
// Push the window
window_stack_push(window, true);
tick_timer_service_subscribe(MINUTE_UNIT, tick);
}
void handle_deinit(void) {
// Stop timers
tick_timer_service_unsubscribe();
if (timer) app_timer_cancel(timer);
// Destroy the text layer
text_layer_destroy(text_layer);
// Destroy the window
window_destroy(window);
// Unload font
fonts_unload_custom_font(font);
}
int main(void) {
handle_init();
app_event_loop();
handle_deinit();
}
|