aboutsummaryrefslogtreecommitdiff
path: root/control/application.c
blob: 06d6adaafaccde2818097a9e4652c76ccd21007d (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
75
#include <bcl.h>
#include <bc_eeprom.h>
#include <bc_spi.h>
#include <bc_dice.h>
#include "ledctl.h"
#include "sensors.h"
#include "gui.h"

bc_led_t led;
bc_led_t led_lcd_red;
bc_led_t led_lcd_blue;

void lcd_button_left_event_handler(bc_button_t *self, bc_button_event_t event, void *event_param) {
	if (event == BC_BUTTON_EVENT_CLICK) {
		click_left();
		update_gui();
		bc_led_pulse(&led_lcd_blue, 30);
	} else if (event == BC_BUTTON_EVENT_HOLD) {
		hold_left();
		update_gui();
		bc_led_pulse(&led_lcd_blue, 500);
	}
}

void lcd_button_right_event_handler(bc_button_t *self, bc_button_event_t event, void *event_param) {
	if (event == BC_BUTTON_EVENT_CLICK) {
		click_right();
		update_gui();
		bc_led_pulse(&led_lcd_red, 30);
	} else if (event == BC_BUTTON_EVENT_HOLD) {
		hold_right();
		update_gui();
		bc_led_pulse(&led_lcd_red, 500);
	}
}

void application_init(void) {
	bc_log_init(BC_LOG_LEVEL_DEBUG, BC_LOG_TIMESTAMP_ABS);

	// Initialize LED on core module
	bc_led_init(&led, BC_GPIO_LED, false, false);
	bc_led_set_mode(&led, BC_LED_MODE_OFF);

	// Initialize Radio
	bc_radio_init(BC_RADIO_MODE_NODE_SLEEPING);

	// Initialize battery
	init_battery();

	// Initialize thermometer sensor on core module
	init_temperature();

	// Initialize LCD
	bc_module_lcd_init();

	// Initialize LCD button left
	static bc_button_t lcd_left;
	bc_button_init_virtual(&lcd_left, BC_MODULE_LCD_BUTTON_LEFT, bc_module_lcd_get_button_driver(), false);
	bc_button_set_event_handler(&lcd_left, lcd_button_left_event_handler, NULL);

	// Initialize LCD button right
	static bc_button_t lcd_right;
	bc_button_init_virtual(&lcd_right, BC_MODULE_LCD_BUTTON_RIGHT, bc_module_lcd_get_button_driver(), false);
	bc_button_set_event_handler(&lcd_right, lcd_button_right_event_handler, NULL);

	// Initialize red and blue LED on LCD module
	bc_led_init_virtual(&led_lcd_red, BC_MODULE_LCD_LED_RED, bc_module_lcd_get_led_driver(), true);
	bc_led_init_virtual(&led_lcd_blue, BC_MODULE_LCD_LED_BLUE, bc_module_lcd_get_led_driver(), true);

	bc_radio_pairing_request("lcd-thermostat", VERSION);

	bc_led_pulse(&led, 2000);

	update_gui();
}