summaryrefslogtreecommitdiffstats
path: root/Smol Watch Project/My Project/main.c
blob: 053840a28601f55505bf08469188eea4f95e1f85 (plain)
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
#include <atmel_start.h>
#include <hpl_sleep.h>
#include "watch-library/watch.h"
#include "mars_clock.h"

Watch watch;
bool local = true;

void calendar_callback(struct calendar_descriptor *const calendar) {
}

static void mode_callback() {
	local = !local;
}

static void light_callback() {
	struct calendar_date_time date_time;
	calendar_get_date_time(&CALENDAR_0, &date_time);
	date_time.time.min = (date_time.time.min + 1) % 60;
	watch_set_date_time(date_time);
}

static void alarm_callback() {
	struct calendar_date_time date_time;
	calendar_get_date_time(&CALENDAR_0, &date_time);
	date_time.time.sec = 0;
	watch_set_date_time(date_time);
}

static void tick_callback() {
}

int main(void)
{
	atmel_start_init();

	watch_init(&watch);

	watch_enable_date_time(&watch);
	struct calendar_date_time date_time;
	date_time.date.year = 2021;
	date_time.date.month = 5;
	date_time.date.day = 8;
	date_time.time.hour = 19;
	date_time.time.min = 40;
	date_time.time.sec = 0;
	watch_set_date_time(date_time);
	update_display(&watch, date_time, local);
	watch_enable_tick(tick_callback);

	gpio_set_pin_level(RED, false);
	gpio_set_pin_direction(RED, GPIO_DIRECTION_OUT);
	gpio_set_pin_function(RED, GPIO_PIN_FUNCTION_OFF);
	gpio_set_pin_level(GREEN, false);
	gpio_set_pin_direction(GREEN, GPIO_DIRECTION_OUT);
	gpio_set_pin_function(GREEN, GPIO_PIN_FUNCTION_OFF);

	watch_enable_buttons(&watch);
	watch_register_button_callback(&watch, BTN_MODE, &mode_callback);
	watch_register_button_callback(&watch, BTN_ALARM, &alarm_callback);
	watch_register_button_callback(&watch, BTN_LIGHT, &light_callback);

	watch_enable_display(&watch);
	watch_display_pixel(&watch, 1, 16);

	while (1) {
		sleep(4);
		struct calendar_date_time date_time;
		calendar_get_date_time(&CALENDAR_0, &date_time);
		update_display(&watch, date_time, local);
	}
	
	return 0;
}