-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.h
168 lines (155 loc) · 4.7 KB
/
app.h
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* @file app.h
* @author Bernd Giesecke ([email protected])
* @brief For application specific includes and definitions
* Will be included from main.h
* @version 0.1
* @date 2021-04-23
*
* @copyright Copyright (c) 2021
*
*/
#ifndef APP_H
#define APP_H
#include <Arduino.h>
/** Add you required includes after Arduino.h */
#include <Wire.h>
#include "TinyGPS++.h" //http://librarymanager/All#TinyGPSPlus
#include <Adafruit_Sensor.h>
#include <Adafruit_BME680.h> // Click to install library: http://librarymanager/All#Adafruit_BME680
// Debug output set to 0 to disable app debug output
#ifndef MY_DEBUG
#define MY_DEBUG 1
#endif
/** Examples for application events */
#define ACC_TRIGGER 0b1000000000000000
#define N_ACC_TRIGGER 0b0111111111111111
#ifdef NRF52_SERIES
#if MY_DEBUG > 0
#define MYLOG(tag, ...) \
do \
{ \
if (tag) \
PRINTF("[%s] ", tag); \
PRINTF(__VA_ARGS__); \
PRINTF("\n"); \
if (g_ble_uart_is_connected) \
{ \
g_ble_uart.printf(__VA_ARGS__); \
g_ble_uart.printf("\n"); \
} \
} while (0)
#else
#define MYLOG(...)
#endif
#endif
#ifdef ARDUINO_ARCH_RP2040
#if MY_DEBUG > 0
#define MYLOG(tag, ...) \
do \
{ \
if (tag) \
Serial.printf("[%s] ", tag); \
Serial.printf(__VA_ARGS__); \
Serial.printf("\n"); \
} while (0)
#else
#define MYLOG(...)
#endif
#endif
#if defined ESP32
#if MY_DEBUG > 0
#define MYLOG(tag, ...) \
if (tag) \
Serial.printf("[%s] ", tag); \
Serial.printf(__VA_ARGS__); \
Serial.printf("\n"); \
if (g_ble_uart_is_connected) \
{ \
char buff[255]; \
int len = sprintf(buff, __VA_ARGS__); \
uart_tx_characteristic->setValue((uint8_t *)buff, (size_t)len); \
uart_tx_characteristic->notify(true); \
delay(50); \
}
#else
#define MYLOG(...)
#endif
#endif
/** Application function definitions */
void setup_app(void);
bool init_app(void);
void app_event_handler(void);
void ble_data_handler(void) __attribute__((weak));
void lora_data_handler(void);
/** Temperature + Humidity stuff */
bool init_bme(void);
bool read_bme(void);
void start_bme(void);
/** Accelerometer stuff */
bool init_acc(void);
void clear_acc_int(void);
uint16_t *read_acc(void);
// GNSS functions
bool init_gnss(void);
bool poll_gnss(void);
// LoRaWan functions
/** Include the WisBlock-API-V2 */
#include <WisBlock-API-V2.h> // Click to install library: http://librarymanager/All#WisBlock-API-V2
struct tracker_data_s
{
uint8_t data_flag1 = 0x01; // 1
uint8_t data_flag2 = 0x88; // 2
uint8_t lat_1 = 0; // 3
uint8_t lat_2 = 0; // 4
uint8_t lat_3 = 0; // 5
uint8_t long_1 = 0; // 6
uint8_t long_2 = 0; // 7
uint8_t long_3 = 0; // 8
uint8_t alt_1 = 0; // 9
uint8_t alt_2 = 0; // 10
uint8_t alt_3 = 0; // 11
uint8_t data_flag3 = 0x08; // 12
uint8_t data_flag4 = 0x02; // 13
uint8_t batt_1 = 0; // 14
uint8_t batt_2 = 0; // 15
uint8_t data_flag5 = 0x03; // 16
uint8_t data_flag6 = 0x71; // 17
int8_t acc_x_1 = 0; // 18
int8_t acc_x_2 = 0; // 19
int8_t acc_y_1 = 0; // 20
int8_t acc_y_2 = 0; // 21
int8_t acc_z_1 = 0; // 22
int8_t acc_z_2 = 0; // 23
uint8_t data_flag7 = 0x07; // 24
uint8_t data_flag8 = 0x68; // 25
uint8_t humid_1 = 0; // 26
uint8_t data_flag9 = 0x02; // 27
uint8_t data_flag10 = 0x67; // 28
uint8_t temp_1 = 0; // 29
uint8_t temp_2 = 0; // 30
uint8_t data_flag11 = 0x06; // 31
uint8_t data_flag12 = 0x73; // 32
uint8_t press_1 = 0; // 33
uint8_t press_2 = 0; // 34
uint8_t data_flag13 = 0x04; // 35
uint8_t data_flag14 = 0x02; // 36
uint8_t gas_1 = 0; // 37
uint8_t gas_2 = 0; // 38
};
extern tracker_data_s g_tracker_data;
#define TRACKER_DATA_LEN 38 // sizeof(g_tracker_data) with BME680
#define TRACKER_DATA_SHORT_LEN 23 // sizeof(g_tracker_data) without BME680
/** Battery level uinion */
union batt_s
{
uint16_t batt16 = 0;
uint8_t batt8[2];
};
/** Latitude/Longitude value union */
union latLong_s
{
uint32_t val32;
uint8_t val8[4];
};
#endif