Added MAC_ADRESS checking and fixed some GUI bugs.
This commit is contained in:
parent
9a9e405851
commit
4af3bbc9be
|
@ -4,6 +4,9 @@
|
||||||
#include "icons.cpp" // icons
|
#include "icons.cpp" // icons
|
||||||
#include <Preferences.h> // Library for writing in the memory
|
#include <Preferences.h> // Library for writing in the memory
|
||||||
|
|
||||||
|
// MAC address of EEG headset device
|
||||||
|
String MAC_ADDRESS = "98:07:2d:7f:ea:15";
|
||||||
|
|
||||||
// store screen mode and brightness in the memory of the Core
|
// store screen mode and brightness in the memory of the Core
|
||||||
Preferences preferences;
|
Preferences preferences;
|
||||||
const char* key1 = "screenMode";
|
const char* key1 = "screenMode";
|
||||||
|
@ -27,6 +30,7 @@ boolean buttonPressed = false;
|
||||||
boolean connectingBluetooth = true;
|
boolean connectingBluetooth = true;
|
||||||
enum screenMode {DARK, LIGHT};
|
enum screenMode {DARK, LIGHT};
|
||||||
screenMode COLOR_MODE;
|
screenMode COLOR_MODE;
|
||||||
|
boolean setupGUI = false;
|
||||||
|
|
||||||
uint16_t COLORS[2] = {WHITE, BLACK};
|
uint16_t COLORS[2] = {WHITE, BLACK};
|
||||||
|
|
||||||
|
@ -104,14 +108,13 @@ void loop() {
|
||||||
connectBluetooth();
|
connectBluetooth();
|
||||||
}
|
}
|
||||||
|
|
||||||
M5.update();
|
if (!setupGUI && isConnected) {
|
||||||
drawBattery();
|
setupGUI = true;
|
||||||
|
|
||||||
if (!SerialBT.connected() && isConnected == true) {
|
|
||||||
isConnected = false;
|
|
||||||
drawGui();
|
drawGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
M5.update();
|
||||||
|
|
||||||
// read value from UART
|
// read value from UART
|
||||||
if(Serial2.available()){
|
if(Serial2.available()){
|
||||||
char c = Serial2.read();
|
char c = Serial2.read();
|
||||||
|
@ -127,18 +130,18 @@ void loop() {
|
||||||
if (!SerialBT.isClosed() && SerialBT.connected()) {
|
if (!SerialBT.isClosed() && SerialBT.connected()) {
|
||||||
if ((readOneByte() == 170) && readOneByte() == 170) {
|
if ((readOneByte() == 170) && readOneByte() == 170) {
|
||||||
payloadLength = readOneByte();
|
payloadLength = readOneByte();
|
||||||
if (payloadLength > 169) //Payload length can not be greater than 169
|
if (payloadLength > 169) // Payload length can not be greater than 169
|
||||||
return;
|
return;
|
||||||
|
|
||||||
generatedChecksum = 0;
|
generatedChecksum = 0;
|
||||||
|
|
||||||
for (int i = 0; i < payloadLength; i++) {
|
for (int i = 0; i < payloadLength; i++) {
|
||||||
payloadData[i] = readOneByte(); //Read payload into memory
|
payloadData[i] = readOneByte(); // Read payload into memory
|
||||||
generatedChecksum += payloadData[i];
|
generatedChecksum += payloadData[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
checksum = readOneByte(); //Read checksum byte from stream
|
checksum = readOneByte(); // Read checksum byte from stream
|
||||||
generatedChecksum = 255 - generatedChecksum; //Take one's compliment of generated checksum
|
generatedChecksum = 255 - generatedChecksum;
|
||||||
|
|
||||||
if(checksum == generatedChecksum) {
|
if(checksum == generatedChecksum) {
|
||||||
for(int i = 0; i < payloadLength; i++) { // Parse the payload
|
for(int i = 0; i < payloadLength; i++) { // Parse the payload
|
||||||
|
@ -171,7 +174,7 @@ void loop() {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
} // switch
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bigPacket) {
|
if(bigPacket) {
|
||||||
|
@ -270,15 +273,17 @@ void connectBluetooth() {
|
||||||
Serial.println("Found devices:");
|
Serial.println("Found devices:");
|
||||||
for (int i=0; i < btDeviceList->getCount(); i++) {
|
for (int i=0; i < btDeviceList->getCount(); i++) {
|
||||||
BTAdvertisedDevice *device=btDeviceList->getDevice(i);
|
BTAdvertisedDevice *device=btDeviceList->getDevice(i);
|
||||||
Serial.printf(" ----- %s %s %d\n", device->getAddress().toString().c_str(), device->getName().c_str(), device->getRSSI());
|
if (String(device->getAddress().toString().c_str()) == MAC_ADDRESS) {
|
||||||
std::map<int,std::string> channels=SerialBT.getChannels(device->getAddress());
|
Serial.printf(" ----- %s %s %d\n", device->getAddress().toString().c_str(), device->getName().c_str(), device->getRSSI());
|
||||||
Serial.printf("scanned for services, found %d\n", channels.size());
|
std::map<int,std::string> channels=SerialBT.getChannels(device->getAddress());
|
||||||
for(auto const &entry : channels) {
|
Serial.printf("scanned for services, found %d\n", channels.size());
|
||||||
Serial.printf(" channel %d (%s)\n", entry.first, entry.second.c_str());
|
for(auto const &entry : channels) {
|
||||||
}
|
Serial.printf(" channel %d (%s)\n", entry.first, entry.second.c_str());
|
||||||
if(channels.size() > 0) {
|
}
|
||||||
addr = device->getAddress();
|
if(channels.size() > 0) {
|
||||||
channel=channels.begin()->first;
|
addr = device->getAddress();
|
||||||
|
channel=channels.begin()->first;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(addr) {
|
if(addr) {
|
||||||
|
@ -286,7 +291,6 @@ void connectBluetooth() {
|
||||||
SerialBT.connect(addr, channel, sec_mask, role);
|
SerialBT.connect(addr, channel, sec_mask, role);
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
wasConnected = true;
|
wasConnected = true;
|
||||||
drawGui();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Didn't find any devices");
|
Serial.println("Didn't find any devices");
|
||||||
|
@ -330,12 +334,6 @@ void drawGui() {
|
||||||
M5.lcd.drawBitmap(240, 5, 30, 50, (uint16_t *)bluetoothLight);
|
M5.lcd.drawBitmap(240, 5, 30, 50, (uint16_t *)bluetoothLight);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isConnected == false) { // IF BLUETOOTH DISCONNECTED
|
|
||||||
for (int i = 0; i < 4; i++) { // thicker line
|
|
||||||
M5.lcd.drawLine(240 + i, 55, 270 + i, 5, RED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
drawBattery();
|
drawBattery();
|
||||||
|
|
||||||
M5.Lcd.drawLine(0, 60, 320, 60, COLORS[COLOR_MODE]);
|
M5.Lcd.drawLine(0, 60, 320, 60, COLORS[COLOR_MODE]);
|
||||||
|
@ -381,13 +379,17 @@ void drawBluetoothConnecting() {
|
||||||
void drawBluetoothFailed() {
|
void drawBluetoothFailed() {
|
||||||
M5.lcd.fillRect(0, 65, 320, 110, (COLORS[COLOR_MODE] - 1) % 2);
|
M5.lcd.fillRect(0, 65, 320, 110, (COLORS[COLOR_MODE] - 1) % 2);
|
||||||
if (wasConnected) {
|
if (wasConnected) {
|
||||||
M5.lcd.fillRect(0, 0, 150, 55, (COLORS[COLOR_MODE] - 1) % 2);
|
M5.lcd.fillRect(0, 0, 150, 60, (COLORS[COLOR_MODE] - 1) % 2);
|
||||||
M5.lcd.fillRect(0, 185, 320, 240, (COLORS[COLOR_MODE] - 1) % 2);
|
M5.lcd.fillRect(0, 185, 320, 240, (COLORS[COLOR_MODE] - 1) % 2);
|
||||||
M5.lcd.fillRect(0, 185, 320, 240, (COLORS[COLOR_MODE] - 1) % 2);
|
M5.lcd.fillRect(0, 185, 320, 240, (COLORS[COLOR_MODE] - 1) % 2);
|
||||||
M5.Lcd.drawString("Bluetooth: disconnected", 20, 110, 4);
|
M5.Lcd.drawString("Bluetooth: disconnected", 20, 110, 4);
|
||||||
} else {
|
} else {
|
||||||
M5.Lcd.drawString("connecting failed", 50, 110, 4);
|
M5.Lcd.drawString("connecting failed", 50, 110, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) { // thicker line
|
||||||
|
M5.lcd.drawLine(240 + i, 55, 270 + i, 5, RED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bluetoothBlinking() {
|
void bluetoothBlinking() {
|
||||||
|
|
Loading…
Reference in a new issue