Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c77404f
Initial steps to enabling bluetooth
Joseph-Jacobson May 7, 2025
8a055f2
Merge pull request #326 from EmotiBit/master
Joseph-Jacobson May 7, 2025
2f41662
Next bluetooth build before creating test software
Joseph-Jacobson May 12, 2025
2244162
Adding multiple characteristics
Joseph-Jacobson Jul 15, 2025
80d7099
added read control- untested
Joseph-Jacobson Jul 15, 2025
01990cd
Merge branch 'feat-SplitterRefactor' into 1.12.1.feat-blePrototype-Ex…
Joseph-Jacobson Jul 16, 2025
9d4ba9c
Changes to parseIncomingControlPackets to enable bluetooth control pa…
Joseph-Jacobson Jul 17, 2025
d7acd3b
Initial Wireless Off Testing
Joseph-Jacobson Jul 22, 2025
0a735a5
removed gitIgnore
Joseph-Jacobson Jul 30, 2025
e58e169
Code cleanup
Joseph-Jacobson Jul 31, 2025
a70b0c9
tab fixes
Joseph-Jacobson Jul 31, 2025
3339bf0
removed sync code
Joseph-Jacobson Jul 31, 2025
5687d78
More tab changes
Joseph-Jacobson Jul 31, 2025
2db7d38
Code cleanup
Joseph-Jacobson Jul 31, 2025
a473162
Deleted workspace
Joseph-Jacobson Jul 31, 2025
2849d46
Merge branch 'feat-SplitterRefactor' into feat-blePrototype-Example
Joseph-Jacobson Jul 31, 2025
bbfd66b
enabled the ability to run debug mode + bluetooth at the same time
Joseph-Jacobson Jul 31, 2025
38f7c97
More cleanup
Joseph-Jacobson Jul 31, 2025
69bf798
Updated versioning
Joseph-Jacobson Aug 4, 2025
6e919d3
Bumped library
Joseph-Jacobson Aug 6, 2025
0ed979a
Spacing
Joseph-Jacobson Aug 6, 2025
1450c29
Merge branch 'master' into feat-blePrototype-Example
Joseph-Jacobson Sep 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 127 additions & 10 deletions EmotiBit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ uint8_t EmotiBit::setup(String firmwareVariant)
#endif

#ifdef ARDUINO_FEATHER_ESP32
esp_bt_controller_disable();
// ToDo: assess similarity with btStop();
setCpuFrequencyMhz(CPU_HZ / 1000000); // 80MHz has been tested working to save battery life
#endif

Expand Down Expand Up @@ -455,6 +453,12 @@ uint8_t EmotiBit::setup(String firmwareVariant)

while (!Serial.available() && millis() - now < 2000)
{
#ifdef ARDUINO_FEATHER_ESP32
if (digitalRead(buttonPin) && !_enableBluetooth) {
Serial.println("Bluetooth Enabled");
_enableBluetooth = true;
}
#endif // ARDUINO_FEATHER_ESP32
}
#ifdef ADAFRUIT_FEATHER_M0
AdcCorrection::AdcCorrectionValues adcCorrectionValues;
Expand Down Expand Up @@ -952,6 +956,20 @@ uint8_t EmotiBit::setup(String firmwareVariant)
Serial.println(factoryTestSerialOutput);
sleep(true);
}

if (_enableBluetooth == true)
{
#ifdef ARDUINO_FEATHER_ESP32
setPowerMode(PowerMode::BLUETOOTH);
#endif // ARDUINO_FEATHER_ESP32
}

else
{
#ifdef ARDUINO_FEATHER_ESP32
esp_bt_controller_disable();
// ToDo: assess similarity with btStop();
#endif
//WiFi Setup;
Serial.print("\nSetting up WiFi\n");
#if defined(ADAFRUIT_FEATHER_M0)
Expand Down Expand Up @@ -998,6 +1016,8 @@ uint8_t EmotiBit::setup(String firmwareVariant)
#endif

setPowerMode(PowerMode::NORMAL_POWER);
}

typeTags[(uint8_t)EmotiBit::DataType::EDA] = EmotiBitPacket::TypeTag::EDA;
typeTags[(uint8_t)EmotiBit::DataType::EDL] = EmotiBitPacket::TypeTag::EDL;
typeTags[(uint8_t)EmotiBit::DataType::EDR] = EmotiBitPacket::TypeTag::EDR;
Expand Down Expand Up @@ -1499,7 +1519,11 @@ void EmotiBit::parseIncomingControlPackets(String &controlPackets, uint16_t &pac
static String packet;
static EmotiBitPacket::Header header;
int16_t dataStartChar = 0;
#ifdef ARDUINO_FEATHER_ESP32
while (_emotiBitWiFi.readControl(packet) > 0 || _emotiBitBluetooth.readControl(packet) > 0) //Bluetooth and WiFi control packets are read in the same loop
#else
while (_emotiBitWiFi.readControl(packet) > 0)
#endif //ARDUINO_FEATHER_ESP32
{
Serial.println(packet);
dataStartChar = EmotiBitPacket::getHeader(packet, header);
Expand Down Expand Up @@ -1574,6 +1598,9 @@ void EmotiBit::parseIncomingControlPackets(String &controlPackets, uint16_t &pac
else if (header.typeTag.equals(EmotiBitPacket::TypeTag::MODE_WIRELESS_OFF)) {
setPowerMode(EmotiBit::PowerMode::WIRELESS_OFF);
}
else if (header.typeTag.equals(EmotiBitPacket::TypeTag::MODE_BLUETOOTH)) {
setPowerMode(EmotiBit::PowerMode::BLUETOOTH);
}
else if (header.typeTag.equals(EmotiBitPacket::TypeTag::MODE_HIBERNATE)) {
setPowerMode(EmotiBit::PowerMode::HIBERNATE);
}
Expand Down Expand Up @@ -3196,6 +3223,62 @@ void EmotiBit::readSensors()
led.setState(EmotiBitLedController::Led::BLUE, true);
led.setState(EmotiBitLedController::Led::YELLOW, true);
}

if (getPowerMode() == PowerMode::BLUETOOTH) {
#ifdef ARDUINO_FEATHER_ESP32
// Bluetooth connected status LED
if (_emotiBitBluetooth.deviceConnected) {
led.setState(EmotiBitLedController::Led::BLUE, true);
}
else {
// blink LED
static unsigned long onTime = 125; // msec
static unsigned long totalTime = 250; // msec changed to 250
static bool bleConnectedBlinkState = false;

static unsigned long bleConnBlinkTimer = millis();

unsigned long timeNow = millis();
if (timeNow - bleConnBlinkTimer < onTime)
{
led.setState(EmotiBitLedController::Led::BLUE, true);
}
else if (timeNow - bleConnBlinkTimer < totalTime)
{
led.setState(EmotiBitLedController::Led::BLUE, false);
}
else
{
bleConnBlinkTimer = timeNow;
}
}
// Battery LED
if (battIndicationSeq)
{
led.setState(EmotiBitLedController::Led::YELLOW, true);
}
else
{
led.setState(EmotiBitLedController::Led::YELLOW, false);
}

// Recording status LED
if (_sdWrite)
{
static uint32_t recordBlinkDuration = millis();
if (millis() - recordBlinkDuration >= 500)
{
led.setState(EmotiBitLedController::Led::RED, !led.getState(EmotiBitLedController::Led::RED));
recordBlinkDuration = millis();
}
}
else if (!_sdWrite && led.getState(EmotiBitLedController::Led::RED) == true)
{
led.setState(EmotiBitLedController::Led::RED, false);
}

#endif //ARDUINO_FEATHER_ESP32
}
else
{
// WiFi connected status LED
Expand Down Expand Up @@ -3446,6 +3529,11 @@ void EmotiBit::sendData()
if (getPowerMode() == PowerMode::NORMAL_POWER) {
_emotiBitWiFi.sendData(s);
}
if (getPowerMode() == PowerMode::BLUETOOTH) {
#ifdef ARDUINO_FEATHER_ESP32
_emotiBitBluetooth.sendData(s);
#endif //ARDUINO_FEATHER_ESP32
}
writeSdCardMessage(s);
firstIndex = lastIndex + 1;
}
Expand Down Expand Up @@ -3476,13 +3564,18 @@ void EmotiBit::sendData()

String s = _outDataPackets.substring(firstIndex, lastIndex + 1);

if (getPowerMode() == PowerMode::NORMAL_POWER) {
_emotiBitWiFi.sendData(s);
if (getPowerMode() == PowerMode::NORMAL_POWER) {
_emotiBitWiFi.sendData(s);
}
if (getPowerMode() == PowerMode::BLUETOOTH) {
#ifdef ARDUINO_FEATHER_ESP32
_emotiBitBluetooth.sendData(s);
#endif //ARDUINO_FEATHER_ESP32
}
writeSdCardMessage(s);
firstIndex = lastIndex + 1;
}
writeSdCardMessage(s);
firstIndex = lastIndex + 1;
}
_outDataPackets = "";
_outDataPackets = "";
}
}

Expand Down Expand Up @@ -3763,7 +3856,29 @@ void EmotiBit::setPowerMode(PowerMode mode)
else if (getPowerMode() == PowerMode::WIRELESS_OFF)
{
Serial.println("PowerMode::WIRELESS_OFF");

if (_enableBluetooth == true)
{
#ifdef ARDUINO_FEATHER_ESP32
_emotiBitBluetooth.end();
// _enableBluetooth = false;
#endif //ARDUINO_FEATHER_ESP32
}
else
{
_emotiBitWiFi.end();
}
}
else if (getPowerMode() == PowerMode::BLUETOOTH)
{
#ifdef ARDUINO_FEATHER_ESP32
if (_emotiBitBluetooth.isOff())
{
Serial.println("PowerMode::BLUETOOTH");
_emotiBitBluetooth.begin(emotibitDeviceId);
}

#endif //ARDUINO_FEATHER_ESP32
}
else if (getPowerMode() == PowerMode::HIBERNATE)
{
Expand Down Expand Up @@ -4331,12 +4446,14 @@ void EmotiBit::processDebugInputs(String &debugPackets, uint16_t &packetNumber)
}
else if (c == '>') {
_sendTestData = true;
//nameSdCardFile(); //temp

Serial.println("Entering Sending Test Data Mode");
}
else if (c == '<')
{
_sendTestData = false;
Serial.println("Exiting Sending Test Data Mode");
_sendTestData = true;
Serial.println("Entering Sending Test Data Mode");
}
else if (c == '@' && _sendTestData == true)
{
Expand Down
12 changes: 10 additions & 2 deletions EmotiBit.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifdef ARDUINO_FEATHER_ESP32
#include <SD.h>
#include "driver/adc.h"
#include <esp_bt.h>
#include <esp_bt.h> //consider moving into bluetooth
#else
#include <SdFat.h>
#include <ArduinoLowPower.h>
Expand All @@ -39,6 +39,9 @@
#include "FileTransferManager.h"
#endif
#include "EmotiBitConfigManager.h"
#ifdef ARDUINO_FEATHER_ESP32
#include "EmotiBitBluetooth.h"
#endif

class EmotiBit {

Expand Down Expand Up @@ -266,6 +269,7 @@ class EmotiBit {
MAX_LOW_POWER, // data not sent, time-syncing accuracy low
LOW_POWER, // data not sent, time-syncing accuracy high
NORMAL_POWER, // data sending, time-syncing accuracy high
BLUETOOTH,
length
};

Expand All @@ -280,6 +284,9 @@ class EmotiBit {
EmotiBitEda emotibitEda;
EmotiBitNvmController _emotibitNvmController;
#ifdef ARDUINO_FEATHER_ESP32
EmotiBitBluetooth _emotiBitBluetooth;
#endif //ARDUINO_FEATHER_ESP32
#ifdef ARDUINO_FEATHER_ESP32
FileTransferManager _fileTransferManager;
#endif
EmotiBitConfigManager _emotibitConfigManager;
Expand Down Expand Up @@ -429,6 +436,7 @@ class EmotiBit {
DataType _serialData = DataType::length;
volatile bool buttonPressed = false;
bool startBufferOverflowTest = false;
bool _enableBluetooth = false;

void setupFailed(const String failureMode, int buttonPin = -1, bool configFileError = false);
bool setupSdCard(bool loadConfig = true);
Expand Down Expand Up @@ -459,7 +467,7 @@ class EmotiBit {
bool processThermopileData(); // placeholder until separate EmotiBitThermopile controller is implemented
void writeSerialData(EmotiBit::DataType t);
void printEmotiBitInfo();

void nameSdCardFile();

/**
* Copies data buffer of the specified DataType into the passed array
Expand Down
Loading
Loading