-
Notifications
You must be signed in to change notification settings - Fork 27
/
io.h
123 lines (109 loc) · 2.71 KB
/
io.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
#include "soc/gpio_sig_map.h"
void read_sound() {
}
void read_GPS() {
}
#ifdef TOUCH0
void read_touch() {
byte touchPin[] = {
TOUCH0,
TOUCH1,
TOUCH2,
TOUCH3,
};
for (byte t = 0; t < 4; t++) {
int touchValue = touchRead(touchPin[t]); //do something with the touch?
// PT(touchValue);
// PT('\t');
}
// PTL();
}
#endif
void readEnvironment() {
#ifdef GYRO_PIN
if (gyroBalanceQ && !(frame % imuSkip))
imuUpdated = read_IMU();
#endif
read_sound();
read_GPS();
}
//— read master computer’s signals (middle level) —
//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Richard Li - 2020
//
//This example creates a bridge between Serial and Classical Bluetooth (SSP with authentication)
//and also demonstrate that SerialBT has the same functionalities as a normal Serial
#ifdef BT_SSP
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
boolean confirmRequestPending = true;
boolean BTconnected = false;
void BTConfirmRequestCallback(uint32_t numVal) {
confirmRequestPending = true;
Serial.println(numVal);
}
void BTAuthCompleteCallback(boolean success) {
confirmRequestPending = false;
if (success) {
BTconnected = true;
Serial.println("SSP Pairing success!!");
} else {
BTconnected = false;
Serial.println("SSP Pairing failed, rejected by user!!");
}
}
void blueSspSetup() {
PTH("SSP: ", strcat(readLongByBytes(EEPROM_BLE_NAME), "_SSP"));
SerialBT.enableSSP();
SerialBT.onConfirmRequest(BTConfirmRequestCallback);
SerialBT.onAuthComplete(BTAuthCompleteCallback);
SerialBT.begin(strcat(readLongByBytes(EEPROM_BLE_NAME), "_SSP")); //Bluetooth device name
Serial.println("The SSP device is started, now you can pair it with Bluetooth!");
}
//void readBlueSSP() {
// if (confirmRequestPending)
// {
// if (Serial.available())
// {
// int dat = Serial.read();
// if (dat == 'Y' || dat == 'y')
// {
// SerialBT.confirmReply(true);
// }
// else
// {
// SerialBT.confirmReply(false);
// }
// }
// }
// else
// {
// if (Serial.available())
// {
// SerialBT.write(Serial.read());
// }
// if (SerialBT.available())
// {
// Serial.write(SerialBT.read());
// }
// delay(20);
// }
//}
//end of Richard Li's code
#endif
template<typename T> void printToAllPorts(T text) {
#ifdef BT_BLE
if (deviceConnected)
bleWrite(String(text));
#endif
#ifdef BT_SSP
if (BTconnected)
SerialBT.println(text);
#endif
if (moduleActivatedQ[0])//serial2
Serial2.println(text);
PTL(text);
}