FreematicsPlus.h
1.54 KB
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
/*************************************************************************
* Arduino library for Freematics ONE+ (ESP32)
* Distributed under BSD license
* Visit http://freematics.com for more information
* (C)2017 Developed by Stanley Huang <support@freematics.com.au>
*************************************************************************/
#include <Arduino.h>
#define PIN_XBEE_PWR 27
class Task
{
public:
Task():xHandle(0) {}
bool create(void (*task)(void*), const char* name, int priority = 0);
void destroy();
static void sleep(uint32_t ms);
private:
void* xHandle;
};
class Mutex
{
public:
Mutex();
void lock();
void unlock();
private:
void* xSemaphore;
};
class CFreematicsESP32
{
public:
// start xBee UART communication
virtual bool xbBegin(unsigned long baudrate = 115200L);
// read data to xBee UART
virtual int xbRead(char* buffer, int bufsize, unsigned int timeout = 1000);
// send data to xBee UART
virtual void xbWrite(const char* cmd);
// send data to xBee UART
virtual void xbWrite(const char* data, int len);
// receive data from xBee UART (returns 0/1/2)
virtual int xbReceive(char* buffer, int bufsize, unsigned int timeout = 1000, const char** expected = 0, byte expectedCount = 0);
// purge xBee UART buffer
virtual void xbPurge();
// toggle xBee module power
virtual void xbTogglePower();
// delay specified number of ms while receiving and processing GPS data (ought to be regularly called)
virtual void sleep(unsigned int ms);
// hibernate (lower power consumption)
virtual void hibernate(unsigned int ms);
};