blob: 9dc069969efc51b220c6ab451012ca29f37e359e (
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
76
77
78
79
|
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "watch.h"
#include "tsl2591.h"
#include "app.h"
ApplicationState application_state;
char buf[16] = {0};
void app_init() {
memset(&application_state, 0, sizeof(application_state));
}
void app_wake_from_deep_sleep() {
// This app does not support deep sleep mode.
}
void app_setup() {
watch_enable_external_interrupts();
watch_register_interrupt_callback(BTN_MODE, cb_mode_pressed, INTERRUPT_TRIGGER_RISING);
watch_register_interrupt_callback(BTN_LIGHT, cb_light_pressed, INTERRUPT_TRIGGER_RISING);
watch_register_extwake_callback(BTN_ALARM, cb_alarm_pressed, true);
watch_enable_buzzer();
watch_enable_leds();
// pin A0 powers the sensor on this board.
watch_enable_digital_output(A0);
watch_set_pin_level(A0, true);
delay_ms(10);
watch_enable_i2c();
watch_enable_display();
watch_register_tick_callback(cb_tick);
delay_ms(5000);
if (!tsl2591_init()) {
printf("Sensor init failed?\n");
}
}
void app_prepare_for_sleep() {
}
void app_wake_from_sleep() {
}
bool app_loop() {
return true;
}
void cb_mode_pressed() {
application_state.mode = (application_state.mode + 1) % NUM_MODES;
application_state.mode_changed = true;
application_state.mode_ticks = 300;
application_state.page = 0;
}
void cb_light_pressed() {
application_state.light_ticks = 3;
}
void cb_alarm_pressed() {
}
void cb_tick() {
uint16_t result = tsl2591_get_visible_light_reading();
printf("Visible Light : %d\n\n", result);
if (application_state.light_ticks > 0) {
application_state.light_ticks--;
}
if (application_state.mode_ticks > 0) {
application_state.mode_ticks--;
}
}
|