Cleaned code.

This commit is contained in:
Vojtěch Pour 2022-12-14 09:25:15 +01:00
parent 1f47db22f2
commit 6cd1eb7fe8

View file

@ -1,15 +1,13 @@
#define DEBUGOUTPUT 0
#include <map> // Bluetooth
#include <BluetoothSerial.h> // Bluetooth
#include <M5Core2.h>
#include "icons.cpp" // icons
#include <Preferences.h>
#include <Preferences.h> // Library for writing in the memory
// store screen mode and brightness in the memory of the Core
Preferences preferences;
const char* key1 = "lightDark";
const char* key1 = "screenMode";
const char* key2 = "brightness";
int lightMode;
// UART communication variables
#define RX_PIN 19
@ -68,6 +66,7 @@ TaskHandle_t TaskHandle_2;
void setup() {
M5.begin();
preferences.begin("Key");
Serial.print(preferences.getUInt(key1));
if (preferences.getUInt(key1) == 0) {
@ -75,6 +74,7 @@ void setup() {
} else {
COLOR_MODE = LIGHT;
}
M5.Axp.SetLcdVoltage(brightnessValues[preferences.getUInt(key2)]); // Set initial brightness
Serial2.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN); // UART communication
@ -133,7 +133,7 @@ void task1(void *pvParameters) {
Serial.printf("connecting to %s - %d\n", addr.toString().c_str(), channel);
SerialBT.connect(addr, channel, sec_mask, role);
isConnected = true;
//drawGui(COLOR_MODE);
drawGui(COLOR_MODE);
}
} else {
Serial.println("Didn't find any devices");
@ -142,6 +142,7 @@ void task1(void *pvParameters) {
} else {
Serial.println("Error on discoverAsync f.e. not workin after a \"connect\"");
}
while (1) {
if (!SerialBT.connected() && isConnected == true) {
isConnected = false;
@ -161,7 +162,6 @@ void task1(void *pvParameters) {
}
if (!SerialBT.isClosed() && SerialBT.connected()) {
if (ReadOneByte() == 170) {
if (ReadOneByte() == 170) {
payloadLength = ReadOneByte();
if (payloadLength > 169) //Payload length can not be greater than 169
@ -209,10 +209,9 @@ void task1(void *pvParameters) {
break;
default:
break;
} // switch
} // for loop
}
}
#if !DEBUGOUTPUT
if (bigPacket) {
updatePoorQuality();
updateAttention();
@ -249,19 +248,13 @@ void task1(void *pvParameters) {
Serial.print("EEG POWER: ");
Serial.print(String(eegPower[0]) + ", " + String(eegPower[1]) + ", " + String(eegPower[2]) + ", " + String(eegPower[3]) + ", " + String(eegPower[4]) + ", " + String(eegPower[5]) + ", " + String(eegPower[6]) + ", " + String(eegPower[7]));
Serial.print("\n");
} else {
Serial.println("NOT!");
}
#endif
bigPacket = false;
} else {
// Checksum Error
} // end if else for checksum
} // end if read 0xAA byte
}
}
} else {
Serial.println("NOT CONNECTED!");
delay(1000);
Serial.println("Bluetooth not connected!");
vTaskDelete(TaskHandle_1);
}
}
}
@ -332,10 +325,6 @@ byte ReadOneByte() {
if (!SerialBT.isClosed() && SerialBT.connected()) {
ByteRead = SerialBT.read();
#if DEBUGOUTPUT
Serial.print((char)ByteRead); // echo the same byte out the USB serial (for debug purposes)
#endif
return ByteRead;
} else {
Serial.println("not connected");