-
Notifications
You must be signed in to change notification settings - Fork 1
/
RN41_42.h
169 lines (149 loc) · 5.15 KB
/
RN41_42.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
/*
Name: RN41.h
Created: 6/7/2017 9:46:16 PM
Author: Chris
Editor: http://www.visualmicro.com
*/
#ifndef _RN41_42_h
#define _RN41_42_h
//Define pin to pin connections
#define RN41_42_RESET 10 //Reset
#define RN41_42_GPIO2 7 //Connection State
#define RN41_42_GPIO3 3 //Auto Discovery/Pairing
//#define RN41_42_GPIO4 //Factory Reset
//#define RN41_42_GPIO6 //Auto-Connect
//#define RN41_42_GPIO7 //Baud Rate
#define revBufSize 16
#define DEBUG
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
class RN41_42{
public:
char recvBuf[revBufSize];
RN41_42(HardwareSerial& _serial);
RN41_42(HardwareSerial& _serial, char configChar);
void begin(unsigned long baudrate);
void begin();
void end();
bool enterCommandMode();
bool exitCommandMode();
void sendMessage(char message[32]);
void sendChar(char c);
char *recieveMessage();
uint8_t available();
char read();
//Dipswitch/GPIO Functions
#ifdef RN41_42_GPIO4
void factoryReset();
#endif // RN41_42_GPIO4
#ifdef RN41_42_GPIO3
void autoDiscoveryPairing(bool en);
#endif // RN41_42_GPIO3
#ifdef RN41_42_GPIO6
void autoConnect(bool en);
#endif // RN41_42_GPIO6
#ifdef RN41_42_GPIO7
void setBaudRate9600(bool en);
#endif // RN41_42_GPIO7
//Set Commands
bool setS7(bool en); //S7
bool setAuthenticationMode(uint8_t authMode); //SA
bool setBreak(uint8_t breakVal); //SB
bool setServiceClass(uint16_t hex); //SC
bool setDeviceClass(uint16_t hex); //SD
bool setUUID(char hex[32]); //SE
bool restoreFactoryDefaults(); //SF,1
bool setHIDRegister(uint16_t hex); //SH
bool setInquiryScanWindow(uint16_t hex); //SI
bool setPageScanWindow(uint16_t hex); //SJ
bool setUARTParity(char parity); //SL
bool setMode(uint8_t mode); //SM
bool setDeviceName(char name[21]); //SN
bool setExtendedStatusString(char name[9]); //SO
bool setPinCode(char pin[5]); //SP
bool setMask(uint8_t mask); //SQ
bool setRemoteAddress(char address[13]); //SR
bool eraseRemoteAddress(); //SR,Z
bool setRemoteAddressLastObserved(); //SR,I
bool setServiceName(char name[21]); //SS
bool setConfigTimer(uint8_t value); //ST
bool setUARTBaud(uint8_t baud); //SU
bool setSniff(uint16_t hex); //SW
bool setBonding(bool en); //SX
bool setTransmitPower(uint16_t hex); //SY
bool setNonStandardBaud(uint8_t multi); //SZ
bool setProfile(uint8_t value); //S~
bool setSerializedFriendlyName(char name[16]);//S-
bool setRoleSwitch(bool en); //S?
bool setConfigChar(char c); //S$
bool setLPConnectMode(uint8_t hex); //S|
//Get Commands
char *getBasicSettings(); //D
char *getExtendedSettings(); //E
char *getBluetoothAddress(); //GB
char *getConnectedRemoteAddress();//GF
bool getConnectionStatus(); //GK
char *getStoredRemoteAddress(); //GR
char *getGPIOStatus(); //G&
//Action Commands
char *displayDipwitchValues(); //&
bool connectToStoredAddress(); //C
bool connectToAddress(char address[13]); //C,<address>
bool connectToAddressFast(char address[13]); //CF
bool connectToLastFoundAddressFast(); //CFI
bool connectToStoredRemoteAddressFast(); //CFR
bool connectToAddressTimed(char address[13], uint8_t time); //CT
bool fastDataMode(); //F,1
char *help(); //H
char *performInquiryScan(uint8_t time); //I,<value 1>
char *performInquiryScan(uint8_t time, char cod[7]); //I,<value 1>,<value 2>
char *performInquiryScanNN(uint8_t time); //IN,<value 1>
char *performInquiryScanNN(uint8_t time, char cod[7]); //IN,<value 1>,<value 2>
char *scanRSSI(); //IQ
char *performRovingInquiryScan(uint8_t time); //IS
char *performCableReplaceInquiryScan(uint8_t time); //IR
bool hidePIN(); //J
bool killConnection(); //K,
char *linkQuality(); //L
char *remoteModemSignalStatus(); //M
char *otherSettings(); //O
void passMessage(char mes[32]); //P
bool quietMode(); //Q
bool quietMode(uint8_t mode); //Q,0 or Q,1 or Q,2
uint8_t quietStatus(); //Q,?
bool reset(); //R,1 or GPIO
bool passThrough(bool en); //T
bool uartChangeTemp(char baud[5], char parity); //U
char *getFirmwareVersion(); //V
bool enableDiscoveryConnection(); //W
void sleep(); //Z
//GPIO Commands
bool pinMode(uint8_t pin, uint8_t dir); //S@
bool digitalWrite(uint8_t pin, uint8_t val); //S& and S*
bool pinModePowerUp(uint8_t pin, uint8_t dir); //S%
bool digitalWritePowerUp(uint8_t pin, uint8_t val); //S^
private:
//Vaiables
HardwareSerial& serial;
bool _commandMode;
unsigned long _baud;
char _configChar[2];
//GPIO Bitmasks
uint8_t gpioSetDir = 0U;
uint8_t gpioDir = 0U;
uint8_t gpioSetVal = 0U;
uint8_t gpioVal = 0U;
uint8_t gpio811 = 0U;
uint8_t gpioSetDirPowerUp = 0U;
uint8_t gpioDirPowerUp = 0U;
uint8_t gpioSetValPowerUp = 0U;
uint8_t gpioValPowerUp = 0U;
//Private Commands
void setupIO();
char *getSingleLineResponse();
bool isAOK();
};
#endif