-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.c
119 lines (94 loc) · 3.17 KB
/
main.c
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
108
109
110
111
112
113
114
115
116
117
118
119
/*!******************************************************************
* \file main.c
* \brief Sens'it SDK template
* \author Sens'it Team
* \copyright Copyright (c) 2018 Sigfox, All Rights Reserved.
*
* This file is an empty main template.
* You can use it as a basis to develop your own firmware.
*******************************************************************/
/******* INCLUDES **************************************************/
#include "sensit_types.h"
#include "sensit_api.h"
#include "error.h"
#include "button.h"
#include "battery.h"
#include "radio_api.h"
#include "hts221.h"
#include "ltr329.h"
#include "fxos8700.h"
/******* GLOBAL VARIABLES ******************************************/
u8 firmware_version[] = "TEMPLATE";
/*******************************************************************/
int main()
{
error_t err;
button_e btn;
u16 battery_level;
/* Start of initialization */
/* Configure button */
SENSIT_API_configure_button(INTERRUPT_BOTH_EGDE);
/* Initialize Sens'it radio */
err = RADIO_API_init();
ERROR_parser(err);
/* Initialize temperature & humidity sensor */
err = HTS221_init();
ERROR_parser(err);
/* Initialize light sensor */
err = LTR329_init();
ERROR_parser(err);
/* Initialize accelerometer */
err = FXOS8700_init();
ERROR_parser(err);
/* Clear pending interrupt */
pending_interrupt = 0;
/* End of initialization */
while (TRUE)
{
/* Execution loop */
/* Check of battery level */
BATTERY_handler(&battery_level);
/* RTC alarm interrupt handler */
if ((pending_interrupt & INTERRUPT_MASK_RTC) == INTERRUPT_MASK_RTC)
{
/* Clear interrupt */
pending_interrupt &= ~INTERRUPT_MASK_RTC;
}
/* Button interrupt handler */
if ((pending_interrupt & INTERRUPT_MASK_BUTTON) == INTERRUPT_MASK_BUTTON)
{
/* RGB Led ON during count of button presses */
SENSIT_API_set_rgb_led(RGB_WHITE);
/* Count number of presses */
btn = BUTTON_handler();
/* RGB Led OFF */
SENSIT_API_set_rgb_led(RGB_OFF);
if (btn == BUTTON_FOUR_PRESSES)
{
/* Reset the device */
SENSIT_API_reset();
}
/* Clear interrupt */
pending_interrupt &= ~INTERRUPT_MASK_BUTTON;
}
/* Reed switch interrupt handler */
if ((pending_interrupt & INTERRUPT_MASK_REED_SWITCH) == INTERRUPT_MASK_REED_SWITCH)
{
/* Clear interrupt */
pending_interrupt &= ~INTERRUPT_MASK_REED_SWITCH;
}
/* Accelerometer interrupt handler */
if ((pending_interrupt & INTERRUPT_MASK_FXOS8700) == INTERRUPT_MASK_FXOS8700)
{
/* Clear interrupt */
pending_interrupt &= ~INTERRUPT_MASK_FXOS8700;
}
/* Check if all interrupt have been clear */
if (pending_interrupt == 0)
{
/* Wait for Interrupt */
SENSIT_API_sleep(FALSE);
}
} /* End of while */
}
/*******************************************************************/