From 9b2ef497c42bfd4a454c33c72375a22f56273840 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Tue, 28 May 2024 14:14:12 +0100 Subject: [PATCH 01/68] New version string for testing --- src/OpenEarable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index 04a568a..9da5ef6 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -30,7 +30,7 @@ #include const String device_name = "OpenEarable"; -const String firmware_version = "1.3.0"; +const String firmware_version = "1.3.1b"; const String hardware_version = "1.3.0"; bool _data_logger_flag = false; From 126f5657cd3379593de6af972bc9ad137fdc2463 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 29 May 2024 16:41:48 +0100 Subject: [PATCH 02/68] Enabled writing of Logs files for IMU and Pressure sensor --- src/OpenEarable.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index 9da5ef6..885feda 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -33,7 +33,7 @@ const String device_name = "OpenEarable"; const String firmware_version = "1.3.1b"; const String hardware_version = "1.3.0"; -bool _data_logger_flag = false; +bool _data_logger_flag = true; void data_callback(int id, unsigned int timestamp, uint8_t * data, int size); void config_callback(SensorConfigurationPacket *config); @@ -51,7 +51,7 @@ class OpenEarable { sd_manager.begin(); edge_ml_generic.set_config_callback(config_callback); - //edge_ml_generic.set_data_callback(data_callback); + edge_ml_generic.set_data_callback(data_callback); if (_debug) { _battery->debug(*_debug); From 9161ac0758828f5b5bbb8fd7cf96f18d870d642c Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 29 May 2024 16:43:13 +0100 Subject: [PATCH 03/68] Added separation of Log files into subfolder and single file for each recording --- src/sd_logger/SD_Logger.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/sd_logger/SD_Logger.cpp b/src/sd_logger/SD_Logger.cpp index 8703d83..35c0379 100644 --- a/src/sd_logger/SD_Logger.cpp +++ b/src/sd_logger/SD_Logger.cpp @@ -65,6 +65,33 @@ void SD_Logger::write_header() { bool SD_Logger::open_file() { if (_opened) return true; + // find the next available file name for the recording + const String logs_dir = "Logs"; + + if (!sd_manager.exists(logs_dir)) sd_manager.mkdir(logs_dir); + + ExFile file; + ExFile dir = sd_manager.sd->open(logs_dir); + + char fileName[64]; + char * split; + + int n = 1; + + // find highest Recording number + while (file = dir.openNextFile()) { + file.getName(fileName, sizeof(fileName)); + + split = strtok(fileName, "_"); + if (strcmp(split,"Logs") == 0) { + split = strtok(NULL, "_"); + n = max(n, atoi(split) + 1); + } + } + + // file name of the new recording + _name = "/" + logs_dir + "/Log_" + String(n) + "_" + String(millis()) + ".wav"; + _file = sd_manager.openFile(_name, true); _opened = _file.isOpen(); return _opened; From 2dfef0684e2e50261ccf9d5b8cfc5ed913e6a083 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 30 May 2024 14:14:20 +0100 Subject: [PATCH 04/68] Disable serial logging of battery status to avoid cluttering of serial logs --- src/battery_service/Battery_Service.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/battery_service/Battery_Service.cpp b/src/battery_service/Battery_Service.cpp index 2b75d2c..cb50db9 100644 --- a/src/battery_service/Battery_Service.cpp +++ b/src/battery_service/Battery_Service.cpp @@ -11,11 +11,11 @@ void Battery_Service::update() { if (battery->check_battery()) { const int battery_level = battery->get_battery_level(); const int charing_state = battery->get_charging_state(); - if (_debug) { - _debug->print("Battery Level % is now: "); - _debug->println(battery_level); - _debug->println(charing_state); - } + // if (_debug) { + // _debug->print("Battery Level % is now: "); + // _debug->println(battery_level); + // _debug->println(charing_state); + // } batteryLevelC->setValue(battery_level); chargingStateC->setValue(charing_state); } From ceb38d94630923e981d49d6efcadd304fd4d0256 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 30 May 2024 14:15:44 +0100 Subject: [PATCH 05/68] Added serial logging to SDLogger --- src/sd_logger/SD_Logger.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/sd_logger/SD_Logger.cpp b/src/sd_logger/SD_Logger.cpp index 35c0379..d9ec874 100644 --- a/src/sd_logger/SD_Logger.cpp +++ b/src/sd_logger/SD_Logger.cpp @@ -7,6 +7,7 @@ bool SD_Logger::_opened = false; char SD_Logger::_buffer[LOGGER_BUFFER_SIZE]; int SD_Logger::_index = 0; String SD_Logger::_name = "Log.csv"; +Stream * _debug{}; bool SD_Logger::begin() { _index = 0; @@ -17,6 +18,11 @@ bool SD_Logger::begin() { return _file.isOpen(); } +void SD_Logger::debug(Stream &stream) { + _debug = &stream; + _debug->println("SDLogger debug set correctly!"); +} + void SD_Logger::end() { //sd_manager.end(); } From c3f45cac0754ca07b4bfffce8b57766b40d80547 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 30 May 2024 14:16:41 +0100 Subject: [PATCH 06/68] Added configuration of serial debug for SDLogger --- src/OpenEarable.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index 885feda..b0b4e2c 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -55,9 +55,11 @@ class OpenEarable { if (_debug) { _battery->debug(*_debug); + SD_Logger::debug(*_debug); } if (_data_logger_flag) { + _debug->println("Starting SDLogger"); SD_Logger::begin(); } From 0b64bc8d58df0b3ab357e06e75fc18a9e14684a1 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 30 May 2024 14:17:34 +0100 Subject: [PATCH 07/68] Removed serial initialization from main header --- src/OpenEarable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index b0b4e2c..da35e96 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -43,7 +43,7 @@ class OpenEarable { OpenEarable() = default; void begin() { - Serial.begin(0); + // Serial.begin(0); _interface = new SensorManager_Earable(); _battery = new Battery_Service(); From 47bde19bf82884ae413e0b22c6e5eec0d92afc0a Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 30 May 2024 14:18:10 +0100 Subject: [PATCH 08/68] Added debugging over serial of SDLogger (header parameters) --- src/sd_logger/SD_Logger.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sd_logger/SD_Logger.h b/src/sd_logger/SD_Logger.h index ae76944..ddba4ea 100644 --- a/src/sd_logger/SD_Logger.h +++ b/src/sd_logger/SD_Logger.h @@ -3,16 +3,18 @@ #include "utils/SDManager.h" #include "EdgeML_Custom.h" +#include // #define LOGGER_BUFFER_SIZE 1024 #define LOGGER_BUFFER_SIZE 2048 -class SD_Logger { +class SD_Logger{ public: static bool begin(); static void end(); static void set_name(String name); + static void debug(Stream &stream); static void data_callback(int, unsigned int, const String&); private: From 6ec7e948bfc78c26b9e1ff058d0165a01f6284ad Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 30 May 2024 14:19:03 +0100 Subject: [PATCH 09/68] Fixed creation of new file when new recording are started. Added debugging prints. --- src/sd_logger/SD_Logger.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/sd_logger/SD_Logger.cpp b/src/sd_logger/SD_Logger.cpp index d9ec874..4b4cb18 100644 --- a/src/sd_logger/SD_Logger.cpp +++ b/src/sd_logger/SD_Logger.cpp @@ -12,7 +12,7 @@ Stream * _debug{}; bool SD_Logger::begin() { _index = 0; if(!sd_manager.begin()) return false; - sd_manager.remove(_name); + if (_debug) _debug->println("Initialising file"); if (!open_file()) return false; write_header(); return _file.isOpen(); @@ -89,14 +89,19 @@ bool SD_Logger::open_file() { file.getName(fileName, sizeof(fileName)); split = strtok(fileName, "_"); - if (strcmp(split,"Logs") == 0) { + if (strcmp(split,"Log") == 0) { split = strtok(NULL, "_"); n = max(n, atoi(split) + 1); } } // file name of the new recording - _name = "/" + logs_dir + "/Log_" + String(n) + "_" + String(millis()) + ".wav"; + _name = "/" + logs_dir + "/Log_" + String(n) + "_" + String(millis()) + ".csv"; + + if (_debug) { + _debug->println("Log filename:"); + _debug->println(_name); + } _file = sd_manager.openFile(_name, true); _opened = _file.isOpen(); From cc1c09d1b698b2014f318642fc225e6e8130039b Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Fri, 31 May 2024 17:25:59 +0100 Subject: [PATCH 10/68] Added individual loggers for IMU and BARO --- src/sd_logger/BARO_Logger.cpp | 115 ++++++++++++++++++++++++++++++++++ src/sd_logger/BARO_Logger.h | 34 ++++++++++ src/sd_logger/IMU_Logger.cpp | 115 ++++++++++++++++++++++++++++++++++ src/sd_logger/IMU_Logger.h | 34 ++++++++++ 4 files changed, 298 insertions(+) create mode 100644 src/sd_logger/BARO_Logger.cpp create mode 100644 src/sd_logger/BARO_Logger.h create mode 100644 src/sd_logger/IMU_Logger.cpp create mode 100644 src/sd_logger/IMU_Logger.h diff --git a/src/sd_logger/BARO_Logger.cpp b/src/sd_logger/BARO_Logger.cpp new file mode 100644 index 0000000..8a676a7 --- /dev/null +++ b/src/sd_logger/BARO_Logger.cpp @@ -0,0 +1,115 @@ +#include "BARO_Logger.h" + +#include + +ExFatFile BARO_Logger::_file; +bool BARO_Logger::_opened = false; +char BARO_Logger::_buffer[LOGGER_BUFFER_SIZE]; +int BARO_Logger::_index = 0; +String BARO_Logger::_name = "Baro.csv"; +Stream * _debug{}; + +bool BARO_Logger::begin() { + _index = 0; + if(!sd_manager.begin()) return false; + if (_debug) _debug->println("Initialising baro file"); + if (!open_file()) return false; + write_header(); + return _file.isOpen(); +} + +void BARO_Logger::debug(Stream &stream) { + _debug = &stream; + _debug->println("BAROLogger debug set correctly!"); +} + +void BARO_Logger::end() { + //sd_manager.end(); +} + +void BARO_Logger::set_name(String name) { + _name = std::move(name); + _opened = false; +} + +void BARO_Logger::data_callback(int id, unsigned int timestamp, const String & data_string) { + if (id == -1) { + dump_to_sd(); + _file.close(); + _opened = false; + return; + }; + + String text = String(id); + text += ", " + String(timestamp); + text += ", " + data_string; + text += "\r\n"; + + if (text.length() + _index > LOGGER_BUFFER_SIZE) { + dump_to_sd(); + } + + text.toCharArray(&(_buffer[_index]), text.length()); + _index += text.length() - 1; // -1 to remove null terminator +} + +void BARO_Logger::dump_to_sd() { + if (!open_file()) return; + if (_index == 0) return; + sd_manager.write_block(&_file, (uint8_t*)_buffer, _index); + memset(_buffer, 0, LOGGER_BUFFER_SIZE); + _index = 0; +} + +void BARO_Logger::write_header() { + _index = 0; + String header = "ID, TIMESTAMP, Data1, Data2"; + header.toCharArray(&(_buffer[_index]), header.length()); + _index += header.length() - 1; // -1 to remove null terminator + dump_to_sd(); +} + +bool BARO_Logger::open_file() { + if (_opened) return true; + // find the next available file name for the recording + const String logs_dir = "Baro"; + + if (!sd_manager.exists(logs_dir)) sd_manager.mkdir(logs_dir); + + ExFile file; + ExFile dir = sd_manager.sd->open(logs_dir); + + char fileName[64]; + char * split; + + int n = 1; + + // find highest Recording number + while (file = dir.openNextFile()) { + file.getName(fileName, sizeof(fileName)); + + split = strtok(fileName, "_"); + if (strcmp(split,"Baro") == 0) { + split = strtok(NULL, "_"); + n = max(n, atoi(split) + 1); + } + } + + // file name of the new recording + _name = "/" + logs_dir + "/Baro_" + String(n) + "_" + String(millis()) + ".csv"; + + if (_debug) { + _debug->println("Log filename:"); + _debug->println(_name); + } + + _file = sd_manager.openFile(_name, true); + _opened = _file.isOpen(); + return _opened; +} + + + + + + diff --git a/src/sd_logger/BARO_Logger.h b/src/sd_logger/BARO_Logger.h new file mode 100644 index 0000000..181ea17 --- /dev/null +++ b/src/sd_logger/BARO_Logger.h @@ -0,0 +1,34 @@ +#ifndef OPEN_EARABLE_SD_LOGGER_H +#define OPEN_EARABLE_SD_LOGGER_H + +#include "utils/SDManager.h" +#include "EdgeML_Custom.h" +#include + +// #define LOGGER_BUFFER_SIZE 1024 +#define LOGGER_BUFFER_SIZE 2048 + +class BARO_Logger{ +public: + static bool begin(); + static void end(); + + static void set_name(String name); + static void debug(Stream &stream); + + static void data_callback(int, unsigned int, const String&); +private: + static ExFatFile _file; + static bool _opened; + + static int _index; + static char _buffer[LOGGER_BUFFER_SIZE]; + + static String _name; + + static void dump_to_sd(); + static void write_header(); + static bool open_file(); +}; + +#endif //OPEN_EARABLE_SD_LOGGER_H diff --git a/src/sd_logger/IMU_Logger.cpp b/src/sd_logger/IMU_Logger.cpp new file mode 100644 index 0000000..1fd6f57 --- /dev/null +++ b/src/sd_logger/IMU_Logger.cpp @@ -0,0 +1,115 @@ +#include "IMU_Logger.h" + +#include + +ExFatFile IMU_Logger::_file; +bool IMU_Logger::_opened = false; +char IMU_Logger::_buffer[LOGGER_BUFFER_SIZE]; +int IMU_Logger::_index = 0; +String IMU_Logger::_name = "Imu.csv"; +Stream * _debug{}; + +bool IMU_Logger::begin() { + _index = 0; + if(!sd_manager.begin()) return false; + if (_debug) _debug->println("Initialising imu file"); + if (!open_file()) return false; + write_header(); + return _file.isOpen(); +} + +void IMU_Logger::debug(Stream &stream) { + _debug = &stream; + _debug->println("IMULogger debug set correctly!"); +} + +void IMU_Logger::end() { + //sd_manager.end(); +} + +void IMU_Logger::set_name(String name) { + _name = std::move(name); + _opened = false; +} + +void IMU_Logger::data_callback(int id, unsigned int timestamp, const String & data_string) { + if (id == -1) { + dump_to_sd(); + _file.close(); + _opened = false; + return; + }; + + String text = String(id); + text += ", " + String(timestamp); + text += ", " + data_string; + text += "\r\n"; + + if (text.length() + _index > LOGGER_BUFFER_SIZE) { + dump_to_sd(); + } + + text.toCharArray(&(_buffer[_index]), text.length()); + _index += text.length() - 1; // -1 to remove null terminator +} + +void IMU_Logger::dump_to_sd() { + if (!open_file()) return; + if (_index == 0) return; + sd_manager.write_block(&_file, (uint8_t*)_buffer, _index); + memset(_buffer, 0, LOGGER_BUFFER_SIZE); + _index = 0; +} + +void IMU_Logger::write_header() { + _index = 0; + String header = "ID, TIMESTAMP, Data1, Data2, Data3, Data4, Data5, Data6, Data7, Data8, Data9\n\r"; + header.toCharArray(&(_buffer[_index]), header.length()); + _index += header.length() - 1; // -1 to remove null terminator + dump_to_sd(); +} + +bool IMU_Logger::open_file() { + if (_opened) return true; + // find the next available file name for the recording + const String logs_dir = "Imu"; + + if (!sd_manager.exists(logs_dir)) sd_manager.mkdir(logs_dir); + + ExFile file; + ExFile dir = sd_manager.sd->open(logs_dir); + + char fileName[64]; + char * split; + + int n = 1; + + // find highest Recording number + while (file = dir.openNextFile()) { + file.getName(fileName, sizeof(fileName)); + + split = strtok(fileName, "_"); + if (strcmp(split,"Imu") == 0) { + split = strtok(NULL, "_"); + n = max(n, atoi(split) + 1); + } + } + + // file name of the new recording + _name = "/" + logs_dir + "/Imu_" + String(n) + "_" + String(millis()) + ".csv"; + + if (_debug) { + _debug->println("Log filename:"); + _debug->println(_name); + } + + _file = sd_manager.openFile(_name, true); + _opened = _file.isOpen(); + return _opened; +} + + + + + + diff --git a/src/sd_logger/IMU_Logger.h b/src/sd_logger/IMU_Logger.h new file mode 100644 index 0000000..da3855b --- /dev/null +++ b/src/sd_logger/IMU_Logger.h @@ -0,0 +1,34 @@ +#ifndef OPEN_EARABLE_SD_LOGGER_H +#define OPEN_EARABLE_SD_LOGGER_H + +#include "utils/SDManager.h" +#include "EdgeML_Custom.h" +#include + +// #define LOGGER_BUFFER_SIZE 1024 +#define LOGGER_BUFFER_SIZE 2048 + +class IMU_Logger{ +public: + static bool begin(); + static void end(); + + static void set_name(String name); + static void debug(Stream &stream); + + static void data_callback(int, unsigned int, const String&); +private: + static ExFatFile _file; + static bool _opened; + + static int _index; + static char _buffer[LOGGER_BUFFER_SIZE]; + + static String _name; + + static void dump_to_sd(); + static void write_header(); + static bool open_file(); +}; + +#endif //OPEN_EARABLE_SD_LOGGER_H From 9950b21ba9fa63c36b2d3f5f2ed051f1a650744d Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Fri, 31 May 2024 17:26:31 +0100 Subject: [PATCH 11/68] Started transitioning main library for individual loggers for IMU and BARO --- src/OpenEarable.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index da35e96..f5f5c0e 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -25,7 +25,7 @@ #include -#include +#include #include @@ -55,12 +55,12 @@ class OpenEarable { if (_debug) { _battery->debug(*_debug); - SD_Logger::debug(*_debug); + IMU_Logger::debug(*_debug); } if (_data_logger_flag) { _debug->println("Starting SDLogger"); - SD_Logger::begin(); + IMU_Logger::begin(); } // Can both be initialized without extra cost @@ -131,7 +131,7 @@ class OpenEarable { static void data_callback(int id, unsigned int timestamp, uint8_t * data, int size) { if (_data_logger_flag) { String data_string = edge_ml_generic.parse_to_string(id, data); - SD_Logger::data_callback(id, timestamp, data_string); + IMU_Logger::data_callback(id, timestamp, data_string); } } From 503b65f688ecdc8c015b15c04c8246d7d5edbb59 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Mon, 3 Jun 2024 12:00:22 +0100 Subject: [PATCH 12/68] Edit name of Baro logger for clarity. Added config callback. --- src/sd_logger/BARO_Logger.cpp | 66 ++++++++++++++++++++++------------- src/sd_logger/BARO_Logger.h | 8 +++-- 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/sd_logger/BARO_Logger.cpp b/src/sd_logger/BARO_Logger.cpp index 8a676a7..9f7e648 100644 --- a/src/sd_logger/BARO_Logger.cpp +++ b/src/sd_logger/BARO_Logger.cpp @@ -2,37 +2,34 @@ #include -ExFatFile BARO_Logger::_file; -bool BARO_Logger::_opened = false; -char BARO_Logger::_buffer[LOGGER_BUFFER_SIZE]; -int BARO_Logger::_index = 0; -String BARO_Logger::_name = "Baro.csv"; -Stream * _debug{}; - -bool BARO_Logger::begin() { +ExFatFile BAROLogger::_file; +bool BAROLogger::_opened = false; +char BAROLogger::_buffer[LOGGER_BUFFER_SIZE]; +int BAROLogger::_index = 0; +String BAROLogger::_name = "Baro.csv"; +Stream * _baro_debug{}; + +bool BAROLogger::begin() { _index = 0; if(!sd_manager.begin()) return false; - if (_debug) _debug->println("Initialising baro file"); - if (!open_file()) return false; - write_header(); - return _file.isOpen(); + return true; } -void BARO_Logger::debug(Stream &stream) { - _debug = &stream; - _debug->println("BAROLogger debug set correctly!"); +void BAROLogger::debug(Stream &stream) { + _baro_debug = &stream; + _baro_debug->println("BAROLogger debug set correctly!"); } -void BARO_Logger::end() { +void BAROLogger::end() { //sd_manager.end(); } -void BARO_Logger::set_name(String name) { +void BAROLogger::set_name(String name) { _name = std::move(name); _opened = false; } -void BARO_Logger::data_callback(int id, unsigned int timestamp, const String & data_string) { +void BAROLogger::data_callback(int id, unsigned int timestamp, const String & data_string) { if (id == -1) { dump_to_sd(); _file.close(); @@ -53,7 +50,28 @@ void BARO_Logger::data_callback(int id, unsigned int timestamp, const String & d _index += text.length() - 1; // -1 to remove null terminator } -void BARO_Logger::dump_to_sd() { +void BAROLogger::config_callback(SensorConfigurationPacket *config) { + + if (config->sampleRate == 0) { + if (_file.isOpen()){ + dump_to_sd(); + _file.close(); + _opened = false; + return; + } + } + + if (_baro_debug) _baro_debug->println("Initialising baro file"); + if (!open_file()){ + if (_baro_debug) _baro_debug->println("Error opening the BARO file"); + return; + } + write_header(); + if (_file.isOpen()) + task_manager.begin(config->sampleRate, -1); +} + +void BAROLogger::dump_to_sd() { if (!open_file()) return; if (_index == 0) return; sd_manager.write_block(&_file, (uint8_t*)_buffer, _index); @@ -61,7 +79,7 @@ void BARO_Logger::dump_to_sd() { _index = 0; } -void BARO_Logger::write_header() { +void BAROLogger::write_header() { _index = 0; String header = "ID, TIMESTAMP, Data1, Data2"; header.toCharArray(&(_buffer[_index]), header.length()); @@ -69,7 +87,7 @@ void BARO_Logger::write_header() { dump_to_sd(); } -bool BARO_Logger::open_file() { +bool BAROLogger::open_file() { if (_opened) return true; // find the next available file name for the recording const String logs_dir = "Baro"; @@ -98,9 +116,9 @@ bool BARO_Logger::open_file() { // file name of the new recording _name = "/" + logs_dir + "/Baro_" + String(n) + "_" + String(millis()) + ".csv"; - if (_debug) { - _debug->println("Log filename:"); - _debug->println(_name); + if (_baro_debug) { + _baro_debug->println("Log filename:"); + _baro_debug->println(_name); } _file = sd_manager.openFile(_name, true); diff --git a/src/sd_logger/BARO_Logger.h b/src/sd_logger/BARO_Logger.h index 181ea17..89b5120 100644 --- a/src/sd_logger/BARO_Logger.h +++ b/src/sd_logger/BARO_Logger.h @@ -1,14 +1,15 @@ -#ifndef OPEN_EARABLE_SD_LOGGER_H -#define OPEN_EARABLE_SD_LOGGER_H +#ifndef OPEN_EARABLE_BARO_LOGGER_H +#define OPEN_EARABLE_BARO_LOGGER_H #include "utils/SDManager.h" #include "EdgeML_Custom.h" #include +#include // #define LOGGER_BUFFER_SIZE 1024 #define LOGGER_BUFFER_SIZE 2048 -class BARO_Logger{ +class BAROLogger{ public: static bool begin(); static void end(); @@ -17,6 +18,7 @@ class BARO_Logger{ static void debug(Stream &stream); static void data_callback(int, unsigned int, const String&); + static void config_callback(SensorConfigurationPacket * config); private: static ExFatFile _file; static bool _opened; From a5790edec8c1b3ef2bf740bc9914aa957e064a10 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Mon, 3 Jun 2024 12:01:06 +0100 Subject: [PATCH 13/68] Edit name of IMU logger for clarity. Added config callback. --- src/sd_logger/IMU_Logger.cpp | 65 +++++++++++++++++++++++------------- src/sd_logger/IMU_Logger.h | 10 +++--- 2 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/sd_logger/IMU_Logger.cpp b/src/sd_logger/IMU_Logger.cpp index 1fd6f57..f4979a7 100644 --- a/src/sd_logger/IMU_Logger.cpp +++ b/src/sd_logger/IMU_Logger.cpp @@ -2,37 +2,34 @@ #include -ExFatFile IMU_Logger::_file; -bool IMU_Logger::_opened = false; -char IMU_Logger::_buffer[LOGGER_BUFFER_SIZE]; -int IMU_Logger::_index = 0; -String IMU_Logger::_name = "Imu.csv"; -Stream * _debug{}; - -bool IMU_Logger::begin() { +ExFatFile IMULogger::_file; +bool IMULogger::_opened = false; +char IMULogger::_buffer[LOGGER_BUFFER_SIZE]; +int IMULogger::_index = 0; +String IMULogger::_name = "Imu.csv"; +Stream * _imu_debug{}; + +bool IMULogger::begin() { _index = 0; if(!sd_manager.begin()) return false; - if (_debug) _debug->println("Initialising imu file"); - if (!open_file()) return false; - write_header(); - return _file.isOpen(); + return true; } -void IMU_Logger::debug(Stream &stream) { - _debug = &stream; - _debug->println("IMULogger debug set correctly!"); +void IMULogger::debug(Stream &stream) { + _imu_debug = &stream; + _imu_debug->println("IMULogger debug set correctly!"); } -void IMU_Logger::end() { +void IMULogger::end() { //sd_manager.end(); } -void IMU_Logger::set_name(String name) { +void IMULogger::set_name(String name) { _name = std::move(name); _opened = false; } -void IMU_Logger::data_callback(int id, unsigned int timestamp, const String & data_string) { +void IMULogger::data_callback(int id, unsigned int timestamp, const String & data_string) { if (id == -1) { dump_to_sd(); _file.close(); @@ -53,7 +50,27 @@ void IMU_Logger::data_callback(int id, unsigned int timestamp, const String & da _index += text.length() - 1; // -1 to remove null terminator } -void IMU_Logger::dump_to_sd() { +void IMULogger::config_callback(SensorConfigurationPacket *config) { + if (config->sampleRate == 0) { + if (_file.isOpen()){ + dump_to_sd(); + _file.close(); + _opened = false; + return; + } + } + + if (_imu_debug) _imu_debug->println("Initialising imu file"); + if (!open_file()){ + if (_imu_debug) _imu_debug->println("Error opening the IMU file"); + return; + } + write_header(); + if (_file.isOpen()) + task_manager.begin(-1, config->sampleRate); +} + +void IMULogger::dump_to_sd() { if (!open_file()) return; if (_index == 0) return; sd_manager.write_block(&_file, (uint8_t*)_buffer, _index); @@ -61,7 +78,7 @@ void IMU_Logger::dump_to_sd() { _index = 0; } -void IMU_Logger::write_header() { +void IMULogger::write_header() { _index = 0; String header = "ID, TIMESTAMP, Data1, Data2, Data3, Data4, Data5, Data6, Data7, Data8, Data9\n\r"; header.toCharArray(&(_buffer[_index]), header.length()); @@ -69,7 +86,7 @@ void IMU_Logger::write_header() { dump_to_sd(); } -bool IMU_Logger::open_file() { +bool IMULogger::open_file() { if (_opened) return true; // find the next available file name for the recording const String logs_dir = "Imu"; @@ -98,9 +115,9 @@ bool IMU_Logger::open_file() { // file name of the new recording _name = "/" + logs_dir + "/Imu_" + String(n) + "_" + String(millis()) + ".csv"; - if (_debug) { - _debug->println("Log filename:"); - _debug->println(_name); + if (_imu_debug) { + _imu_debug->println("Log filename:"); + _imu_debug->println(_name); } _file = sd_manager.openFile(_name, true); diff --git a/src/sd_logger/IMU_Logger.h b/src/sd_logger/IMU_Logger.h index da3855b..560087c 100644 --- a/src/sd_logger/IMU_Logger.h +++ b/src/sd_logger/IMU_Logger.h @@ -1,14 +1,15 @@ -#ifndef OPEN_EARABLE_SD_LOGGER_H -#define OPEN_EARABLE_SD_LOGGER_H +#ifndef OPEN_EARABLE_IMU_LOGGER_H +#define OPEN_EARABLE_IMU_LOGGER_H #include "utils/SDManager.h" #include "EdgeML_Custom.h" #include +#include // #define LOGGER_BUFFER_SIZE 1024 #define LOGGER_BUFFER_SIZE 2048 -class IMU_Logger{ +class IMULogger{ public: static bool begin(); static void end(); @@ -17,6 +18,7 @@ class IMU_Logger{ static void debug(Stream &stream); static void data_callback(int, unsigned int, const String&); + static void config_callback(SensorConfigurationPacket * config); private: static ExFatFile _file; static bool _opened; @@ -31,4 +33,4 @@ class IMU_Logger{ static bool open_file(); }; -#endif //OPEN_EARABLE_SD_LOGGER_H +#endif //OPEN_EARABLE_IMU_LOGGER_H From 7d46d95168eea569b2ad593bc30e0e04c61d78f5 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Mon, 3 Jun 2024 12:01:52 +0100 Subject: [PATCH 14/68] Adapted to new naming for sensor loggers. Moved to config callback for sensor logger. --- src/OpenEarable.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index f5f5c0e..e8d8f00 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -26,6 +26,7 @@ #include #include +#include #include @@ -55,12 +56,14 @@ class OpenEarable { if (_debug) { _battery->debug(*_debug); - IMU_Logger::debug(*_debug); + IMULogger::debug(*_debug); + BAROLogger::debug(*_debug); } if (_data_logger_flag) { _debug->println("Starting SDLogger"); - IMU_Logger::begin(); + IMULogger::begin(); + BAROLogger::begin(); } // Can both be initialized without extra cost @@ -131,7 +134,8 @@ class OpenEarable { static void data_callback(int id, unsigned int timestamp, uint8_t * data, int size) { if (_data_logger_flag) { String data_string = edge_ml_generic.parse_to_string(id, data); - IMU_Logger::data_callback(id, timestamp, data_string); + if (id == BARO_TEMP) BAROLogger::data_callback(id, timestamp, data_string); + else if (id == ACC_GYRO_MAG) IMULogger::data_callback(id, timestamp, data_string); } } @@ -142,8 +146,8 @@ OpenEarable open_earable; void OpenEarable::config_callback(SensorConfigurationPacket *config) { if (config->sensorId == PDM_MIC) Recorder::config_callback(config); - else if (config->sensorId == BARO_TEMP) task_manager.begin(config->sampleRate, -1); - else if (config->sensorId == ACC_GYRO_MAG) task_manager.begin(-1, config->sampleRate); + else if (config->sensorId == BARO_TEMP) BAROLogger::config_callback(config); + else if (config->sensorId == ACC_GYRO_MAG) IMULogger::config_callback(config); else { if (i2s_player.is_running()) { i2s_player.stop(); From b23a7d7f1bf999e4d0fdaf0fbd608b1ad9992b5f Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Mon, 3 Jun 2024 12:02:46 +0100 Subject: [PATCH 15/68] Removed vscode folder from src --- src/.vscode/settings.json | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 src/.vscode/settings.json diff --git a/src/.vscode/settings.json b/src/.vscode/settings.json deleted file mode 100644 index 5633f79..0000000 --- a/src/.vscode/settings.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "files.associations": { - "*.cps": "javascript", - "type_traits": "cpp", - "limits": "cpp", - "chrono": "cpp", - "algorithm": "cpp", - "typeinfo": "cpp", - "__locale": "cpp", - "string": "cpp", - "string_view": "cpp", - "__string": "cpp", - "istream": "cpp", - "*.txt": "cpp", - "cstddef": "cpp" - } -} \ No newline at end of file From ff2bbc811728553e94106c317e419655902c06d9 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Mon, 3 Jun 2024 12:03:11 +0100 Subject: [PATCH 16/68] Enabled debugging in Arduino example --- examples/App/App.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/App/App.ino b/examples/App/App.ino index 2f6bf2d..a219b15 100644 --- a/examples/App/App.ino +++ b/examples/App/App.ino @@ -12,7 +12,7 @@ #include "OpenEarable.h" // Set DEBUG to true in order to enable debug print -#define DEBUG false +#define DEBUG true void setup() { From 0c71d85b1bae3c40022413f20a83906945508ca5 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Mon, 3 Jun 2024 14:12:30 +0100 Subject: [PATCH 17/68] Fixed BARO header --- src/sd_logger/BARO_Logger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sd_logger/BARO_Logger.cpp b/src/sd_logger/BARO_Logger.cpp index 9f7e648..02638ff 100644 --- a/src/sd_logger/BARO_Logger.cpp +++ b/src/sd_logger/BARO_Logger.cpp @@ -81,7 +81,7 @@ void BAROLogger::dump_to_sd() { void BAROLogger::write_header() { _index = 0; - String header = "ID, TIMESTAMP, Data1, Data2"; + String header = "ID, TIMESTAMP, Data1, Data2\n\r "; header.toCharArray(&(_buffer[_index]), header.length()); _index += header.length() - 1; // -1 to remove null terminator dump_to_sd(); From e3cf77ef4e625911843188ae51cb810af1b099c5 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Mon, 3 Jun 2024 14:13:15 +0100 Subject: [PATCH 18/68] Fixed setting of config when sampling rate is 0 --- src/sd_logger/BARO_Logger.cpp | 4 ++-- src/sd_logger/IMU_Logger.cpp | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sd_logger/BARO_Logger.cpp b/src/sd_logger/BARO_Logger.cpp index 02638ff..e406241 100644 --- a/src/sd_logger/BARO_Logger.cpp +++ b/src/sd_logger/BARO_Logger.cpp @@ -53,12 +53,12 @@ void BAROLogger::data_callback(int id, unsigned int timestamp, const String & da void BAROLogger::config_callback(SensorConfigurationPacket *config) { if (config->sampleRate == 0) { - if (_file.isOpen()){ + if (_opened){ dump_to_sd(); _file.close(); _opened = false; - return; } + return; } if (_baro_debug) _baro_debug->println("Initialising baro file"); diff --git a/src/sd_logger/IMU_Logger.cpp b/src/sd_logger/IMU_Logger.cpp index f4979a7..743f34a 100644 --- a/src/sd_logger/IMU_Logger.cpp +++ b/src/sd_logger/IMU_Logger.cpp @@ -51,13 +51,14 @@ void IMULogger::data_callback(int id, unsigned int timestamp, const String & dat } void IMULogger::config_callback(SensorConfigurationPacket *config) { + if (config->sampleRate == 0) { - if (_file.isOpen()){ + if (_opened){ dump_to_sd(); _file.close(); _opened = false; - return; } + return; } if (_imu_debug) _imu_debug->println("Initialising imu file"); From 7967aa885b21c9c4da3d397b74ddf605a33a5ac3 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Mon, 3 Jun 2024 20:10:04 +0100 Subject: [PATCH 19/68] Added RGB LED status for recordings. --- src/OpenEarable.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index e8d8f00..4fedb79 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -36,6 +36,8 @@ const String hardware_version = "1.3.0"; bool _data_logger_flag = true; +uint8_t led_color[3] = {0, 0, 0}; + void data_callback(int id, unsigned int timestamp, uint8_t * data, int size); void config_callback(SensorConfigurationPacket *config); @@ -140,10 +142,43 @@ class OpenEarable { } static void config_callback(SensorConfigurationPacket *config); + static void update_current_led_status(SensorConfigurationPacket *config); }; OpenEarable open_earable; +void OpenEarable::update_current_led_status(SensorConfigurationPacket *config){ + + if (config->sensorId == PDM_MIC) { + if (int(config->sampleRate) > 0) { + led_color[0] = 255; + } else { + led_color[0] = 0; + } + } else if (config->sensorId == BARO_TEMP) { + if (int(config->sampleRate) > 0) { + led_color[1] = 255; + } else { + led_color[1] = 0; + } + } else if (config->sensorId == ACC_GYRO_MAG) { + if (int(config->sampleRate) > 0) { + led_color[2] = 255; + } else { + led_color[2] = 0; + } + } + + if (open_earable._debug) { + open_earable._debug->println("Current_status: "); + for (int i = 0; i < 3; i++) { + open_earable._debug->println(led_color[i]); + } + } + + earable_led.set_color(led_color); +} + void OpenEarable::config_callback(SensorConfigurationPacket *config) { if (config->sensorId == PDM_MIC) Recorder::config_callback(config); else if (config->sensorId == BARO_TEMP) BAROLogger::config_callback(config); @@ -155,6 +190,7 @@ void OpenEarable::config_callback(SensorConfigurationPacket *config) { i2s_player.start(); } } + update_current_led_status(config); //else task_manager.begin(); } From 345c2a770d5e40ac45af0de0d0df185e49f04e39 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Tue, 4 Jun 2024 13:20:46 +0100 Subject: [PATCH 20/68] Fixed header of logs for actual name of sensors channels --- src/sd_logger/BARO_Logger.cpp | 2 +- src/sd_logger/IMU_Logger.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sd_logger/BARO_Logger.cpp b/src/sd_logger/BARO_Logger.cpp index e406241..d734970 100644 --- a/src/sd_logger/BARO_Logger.cpp +++ b/src/sd_logger/BARO_Logger.cpp @@ -81,7 +81,7 @@ void BAROLogger::dump_to_sd() { void BAROLogger::write_header() { _index = 0; - String header = "ID, TIMESTAMP, Data1, Data2\n\r "; + String header = "timestamp,temp,pressure\n\r "; header.toCharArray(&(_buffer[_index]), header.length()); _index += header.length() - 1; // -1 to remove null terminator dump_to_sd(); diff --git a/src/sd_logger/IMU_Logger.cpp b/src/sd_logger/IMU_Logger.cpp index 743f34a..a870e69 100644 --- a/src/sd_logger/IMU_Logger.cpp +++ b/src/sd_logger/IMU_Logger.cpp @@ -81,7 +81,7 @@ void IMULogger::dump_to_sd() { void IMULogger::write_header() { _index = 0; - String header = "ID, TIMESTAMP, Data1, Data2, Data3, Data4, Data5, Data6, Data7, Data8, Data9\n\r"; + String header = "timestamp,acc_x,acc_y,acc_z,acc_x,gyro_y,gyro_z,magn_x,magn_y,magn_z\n\r"; header.toCharArray(&(_buffer[_index]), header.length()); _index += header.length() - 1; // -1 to remove null terminator dump_to_sd(); From f469e3677017cfa489a037c90d1fe46eb4b140e1 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Tue, 4 Jun 2024 13:22:18 +0100 Subject: [PATCH 21/68] Readded sensor_id as column in logs --- src/sd_logger/BARO_Logger.cpp | 2 +- src/sd_logger/IMU_Logger.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sd_logger/BARO_Logger.cpp b/src/sd_logger/BARO_Logger.cpp index d734970..000b6d9 100644 --- a/src/sd_logger/BARO_Logger.cpp +++ b/src/sd_logger/BARO_Logger.cpp @@ -81,7 +81,7 @@ void BAROLogger::dump_to_sd() { void BAROLogger::write_header() { _index = 0; - String header = "timestamp,temp,pressure\n\r "; + String header = "sensor_id,timestamp,temp,pressure\n\r "; header.toCharArray(&(_buffer[_index]), header.length()); _index += header.length() - 1; // -1 to remove null terminator dump_to_sd(); diff --git a/src/sd_logger/IMU_Logger.cpp b/src/sd_logger/IMU_Logger.cpp index a870e69..6b40c1d 100644 --- a/src/sd_logger/IMU_Logger.cpp +++ b/src/sd_logger/IMU_Logger.cpp @@ -81,7 +81,7 @@ void IMULogger::dump_to_sd() { void IMULogger::write_header() { _index = 0; - String header = "timestamp,acc_x,acc_y,acc_z,acc_x,gyro_y,gyro_z,magn_x,magn_y,magn_z\n\r"; + String header = "sensor_id,timestamp,acc_x,acc_y,acc_z,acc_x,gyro_y,gyro_z,magn_x,magn_y,magn_z\n\r"; header.toCharArray(&(_buffer[_index]), header.length()); _index += header.length() - 1; // -1 to remove null terminator dump_to_sd(); From b5aec7c564bb337fd4816e7e8055089a120f0551 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Tue, 4 Jun 2024 13:26:12 +0100 Subject: [PATCH 22/68] Revert "Readded sensor_id as column in logs" This reverts commit f469e3677017cfa489a037c90d1fe46eb4b140e1. --- src/sd_logger/BARO_Logger.cpp | 2 +- src/sd_logger/IMU_Logger.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sd_logger/BARO_Logger.cpp b/src/sd_logger/BARO_Logger.cpp index 000b6d9..d734970 100644 --- a/src/sd_logger/BARO_Logger.cpp +++ b/src/sd_logger/BARO_Logger.cpp @@ -81,7 +81,7 @@ void BAROLogger::dump_to_sd() { void BAROLogger::write_header() { _index = 0; - String header = "sensor_id,timestamp,temp,pressure\n\r "; + String header = "timestamp,temp,pressure\n\r "; header.toCharArray(&(_buffer[_index]), header.length()); _index += header.length() - 1; // -1 to remove null terminator dump_to_sd(); diff --git a/src/sd_logger/IMU_Logger.cpp b/src/sd_logger/IMU_Logger.cpp index 6b40c1d..a870e69 100644 --- a/src/sd_logger/IMU_Logger.cpp +++ b/src/sd_logger/IMU_Logger.cpp @@ -81,7 +81,7 @@ void IMULogger::dump_to_sd() { void IMULogger::write_header() { _index = 0; - String header = "sensor_id,timestamp,acc_x,acc_y,acc_z,acc_x,gyro_y,gyro_z,magn_x,magn_y,magn_z\n\r"; + String header = "timestamp,acc_x,acc_y,acc_z,acc_x,gyro_y,gyro_z,magn_x,magn_y,magn_z\n\r"; header.toCharArray(&(_buffer[_index]), header.length()); _index += header.length() - 1; // -1 to remove null terminator dump_to_sd(); From cb9e2c307cc4eeacf82d3ca0c71ac2913fcdea77 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Tue, 4 Jun 2024 13:29:56 +0100 Subject: [PATCH 23/68] Removed ID from samples written to logs --- src/sd_logger/BARO_Logger.cpp | 3 +-- src/sd_logger/IMU_Logger.cpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/sd_logger/BARO_Logger.cpp b/src/sd_logger/BARO_Logger.cpp index d734970..a7204b9 100644 --- a/src/sd_logger/BARO_Logger.cpp +++ b/src/sd_logger/BARO_Logger.cpp @@ -37,8 +37,7 @@ void BAROLogger::data_callback(int id, unsigned int timestamp, const String & da return; }; - String text = String(id); - text += ", " + String(timestamp); + String text = String(timestamp); text += ", " + data_string; text += "\r\n"; diff --git a/src/sd_logger/IMU_Logger.cpp b/src/sd_logger/IMU_Logger.cpp index a870e69..df30004 100644 --- a/src/sd_logger/IMU_Logger.cpp +++ b/src/sd_logger/IMU_Logger.cpp @@ -37,8 +37,7 @@ void IMULogger::data_callback(int id, unsigned int timestamp, const String & dat return; }; - String text = String(id); - text += ", " + String(timestamp); + String text = String(timestamp); text += ", " + data_string; text += "\r\n"; From ed488295deceb8ca5da402827c8a7a6cca1f8cf4 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Tue, 4 Jun 2024 16:23:58 +0100 Subject: [PATCH 24/68] Added debugging to Recorder --- src/OpenEarable.h | 1 + src/audio_pdm/Recorder.cpp | 12 ++++++++++++ src/audio_pdm/Recorder.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index e8d8f00..6fdd7b3 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -58,6 +58,7 @@ class OpenEarable { _battery->debug(*_debug); IMULogger::debug(*_debug); BAROLogger::debug(*_debug); + Recorder::debug(*_debug); } if (_data_logger_flag) { diff --git a/src/audio_pdm/Recorder.cpp b/src/audio_pdm/Recorder.cpp index e8f080b..99a5371 100644 --- a/src/audio_pdm/Recorder.cpp +++ b/src/audio_pdm/Recorder.cpp @@ -3,6 +3,8 @@ uint8_t PDM_BUFFER[pdm_b_size * pdm_b_count] __attribute__((aligned (16))); +Stream * _rec_debug{}; + Recorder::Recorder() { } @@ -41,6 +43,11 @@ void Recorder::end() { _available = false; } +void Recorder::debug(Stream &stream) { + _rec_debug = &stream; + _rec_debug->println("Recorder debug set correctly!"); +} + void Recorder::print_info() { Serial.println("RECORDER INFO:"); Serial.print("sample rate: "); @@ -148,6 +155,11 @@ void Recorder::config_callback(SensorConfigurationPacket *config) { // file name of the new recording String file_name = "/" + recording_dir + "/Recording_" + String(n) + "_" + String(millis()) + ".wav"; + if (_rec_debug) { + _rec_debug->println("Recording:"); + _rec_debug->println(file_name); + } + // set WaveRecorder recorder.setTarget(new WavRecorder(file_name)); diff --git a/src/audio_pdm/Recorder.h b/src/audio_pdm/Recorder.h index 0912ed8..0ee1b89 100644 --- a/src/audio_pdm/Recorder.h +++ b/src/audio_pdm/Recorder.h @@ -5,6 +5,7 @@ #include "EdgeML_Custom.h" #include "utils/SDManager.h" +#include #include "AudioTarget.h" #include "utils/BufferedInputStream.h" @@ -36,6 +37,7 @@ class Recorder { void print_info(); static void config_callback(SensorConfigurationPacket * config); + static void debug(Stream &stream); AudioTarget * target; InputDevice * device; From 9456f098649ac18e537a5f6824d0b8e320d8bac9 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Tue, 4 Jun 2024 18:08:33 +0100 Subject: [PATCH 25/68] Updated Firmware version for possible future merge with upstream repo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ddcebf8..78c12b3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 🦻 OpenEarable - Firmware v1.3.0 +# 🦻 OpenEarable - Firmware v1.3.1 OpenEarable is a new, open-source, Arduino-based platform for ear-based sensing applications. It provides a versatile prototyping platform with support for various sensors and actuators, making it suitable for earable research and development. From 6bc9bf72a2fe317c96f4aa28000952a1cf6767f4 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Tue, 4 Jun 2024 18:09:37 +0100 Subject: [PATCH 26/68] Added first draft of script to setup Arduino environment --- scripts/install.sh | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 scripts/install.sh diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100644 index 0000000..2503b89 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# Path to your Arduino15 folder (replace with your actual path) +ARDUINO_15_PATH="/path/to/Arduino15" + +# Resources folder path (replace with your actual path) +RESOURCES_PATH="../resources" + +# Check if Arduino15 folder exists +if [ ! -d "$ARDUINO_15_PATH" ]; then + echo "Error: Arduino15 folder not found at $ARDUINO_15_PATH" + exit 1 +fi + +# Check if Resources folder exists +if [ ! -d "$RESOURCES_PATH" ]; then + echo "Error: Resources folder not found at $RESOURCES_PATH" + exit 1 +fi + +# SPI, Wire, and Variant Setup +SPI_DIR="$RESOURCES_PATH/spi_files/SPI" +WIRE_DIR="$RESOURCES_PATH/wire_files/Wire" +VARIANT_DIR="$RESOURCES_PATH/variant" + +# Navigate to libraries directory +LIB_DIR="$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/4.0.4/libraries" + +# Check mbed_nano version (modify if needed) +MBED_NANO_VERSION="4.0.4" + +# Install mbed_nano board (if not already installed) +if ! grep -q "mbed_nano:$MBED_NANO_VERSION" boards.txt; then + echo "Installing mbed_nano board version $MBED_NANO_VERSION..." + arduino-cli boards install arduino:mbed_nano:$MBED_NANO_VERSION +fi + +# Replace SPI library +echo "Replacing SPI library..." +rm -rf "$LIB_DIR/SPI" +cp -r "$SPI_DIR" "$LIB_DIR" + +# Replace Wire library +echo "Replacing Wire library..." +rm -rf "$LIB_DIR/Wire" +cp -r "$WIRE_DIR" "$LIB_DIR" +rm "$LIB_DIR/Wire.cpp" + +# Copy RingBuffer files +echo "Copying RingBuffer files..." +cp "$RESOURCES_PATH/wire_files/RingBuffer.h" "$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/cores/arduino" +cp "$RESOURCES_PATH/wire_files/RingBuffer.cpp" "$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/cores/arduino" + +# Replace nrfx_spim files +echo "Replacing nrfx_spim files..." +cp "$RESOURCES_PATH/spi_files/nrfx_spim.h" "$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/cores/arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/drivers/include" +cp "$RESOURCES_PATH/spi_files/nrfx_spim.c" "$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/cores/arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/drivers/src" + +# Replace variant files +echo "Replacing variant files..." +cp "$RESOURCES_PATH/variant/pins_arduino.h" "$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/variants/ARDUINO_NANO33BLE" +cp "$RESOURCES_PATH/variant/variant.cpp" "$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/variants/ARDUINO_NANO33BLE" + +# sdFat Library Setup +SDFAT_LIB_DIR="$HOME/Documents/Arduino/libraries/SdFat_-_Adafruit_Fork" # Update path if needed + +# Check if sDFat library exists +if [ ! -d "$SDFAT_LIB_DIR" ]; then + echo "Warning: SdFat library not found at SDFAT\_LIB\_DIR" +echo "Please install the SdFat library from Bill Greiman\." +exit 1 +fi +\# Replace SdFatConfig\.h +echo "Replacing SdFatConfig\.h\.\.\." +cp " \ No newline at end of file From 54bf42c4667800249975767c7636b1d9578ac888 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 5 Jun 2024 13:19:19 +0100 Subject: [PATCH 27/68] Changed firmware version to 1.3.1 --- src/OpenEarable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index dc2ea17..ff31f61 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -31,7 +31,7 @@ #include const String device_name = "OpenEarable"; -const String firmware_version = "1.3.1b"; +const String firmware_version = "1.3.1"; const String hardware_version = "1.3.0"; bool _data_logger_flag = true; From a9895a3c6bc1c835421221ecc21e26daba2e9365 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 12 Jun 2024 16:13:45 +0100 Subject: [PATCH 28/68] Modified TaskManager behaviour to allow writing of all data when sampling high speed IMU data --- src/task_manager/TaskManager.cpp | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/task_manager/TaskManager.cpp b/src/task_manager/TaskManager.cpp index f714b22..69bc7fe 100644 --- a/src/task_manager/TaskManager.cpp +++ b/src/task_manager/TaskManager.cpp @@ -72,21 +72,15 @@ void TaskManager::update() { void TaskManager::update_edge_ml() { unsigned int now = millis(); + if (now - _baro_last >= _baro_delay) { + sensorProvider.update_sensor(BARO_TEMP, true); + _baro_last = now; + } + if (now - _imu_last >= _imu_delay) { + sensorProvider.update_sensor(ACC_GYRO_MAG, true); + _imu_last = now; + } if (now - _edge_ml_last >= _edge_ml_delay) { - //Serial.print("delay: "); - //Serial.println(now - _edge_ml_last - _edge_ml_delay); - - //edge_ml_generic.update(true); - sensorProvider.update_manager(); - if (now - _baro_last >= _baro_delay) { - sensorProvider.update_sensor(BARO_TEMP, true); - _baro_last = now; - } - if (now - _imu_last >= _imu_delay) { - sensorProvider.update_sensor(ACC_GYRO_MAG, true); - _imu_last = now; - } - bleHandler_G.update(); //Serial.print(" edge_ml time: "); //Serial.println(millis() - now); @@ -94,9 +88,8 @@ void TaskManager::update_edge_ml() { _edge_ml_last = now; _buffer_flag = false; //now = millis(); + // BLE.poll(); } - - BLE.poll(); } int TaskManager::update_audio(Provider * provider, int max_buffers) { @@ -115,7 +108,7 @@ void TaskManager::begin(float baro_samplerate, float imu_samplerate) { if (baro_samplerate >= 0) _baro_delay = (int) baro_samplerate > 0 ? (1000.0/baro_samplerate) : _default_loop_delay; if (imu_samplerate >= 0) _imu_delay = (int) imu_samplerate > 0 ? (1000.0/imu_samplerate) : _default_loop_delay; - _edge_ml_delay = min(_baro_delay, _imu_delay); + _edge_ml_delay = max(_baro_delay, _imu_delay); /*float edge_rate = max(baro_samplerate, imu_samplerate); From a490fa7c0db1caa4eede2d8713a38f4a31642411 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 12 Jun 2024 22:15:50 +0100 Subject: [PATCH 29/68] Added delays to example App to let console connect --- examples/App/App.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/App/App.ino b/examples/App/App.ino index a219b15..a88cf83 100644 --- a/examples/App/App.ino +++ b/examples/App/App.ino @@ -18,7 +18,9 @@ void setup() { #if DEBUG Serial.begin(115200); + delay(5000); open_earable.debug(Serial); + delay(5000); #endif open_earable.begin(); From 098fa2570aedc042d15bb174c81f6ae3f63c83bf Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 12 Jun 2024 22:21:47 +0100 Subject: [PATCH 30/68] Increased firmware version due to rework for high IMU sampling rate --- src/OpenEarable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index ff31f61..9095703 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -31,7 +31,7 @@ #include const String device_name = "OpenEarable"; -const String firmware_version = "1.3.1"; +const String firmware_version = "1.4.0"; const String hardware_version = "1.3.0"; bool _data_logger_flag = true; From 74a1ed43e0ae322b82ec712653f591a36cb4ee3d Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 12 Jun 2024 22:27:13 +0100 Subject: [PATCH 31/68] Edit library properties in preparation of new release --- library.properties | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library.properties b/library.properties index 80fa17d..54648c1 100644 --- a/library.properties +++ b/library.properties @@ -1,11 +1,11 @@ name=OpenEarable -version=1.3.0 -author=TECO / KIT -maintainer=TECO +version=1.4.0 +author=Mathias / Mobisys +maintainer=Mathias sentence=Firmware to use OpenEarable with the provided dashboard and edge-ml.org. paragraph=The firmware exposes a BLE API to control the IMU, pressure sensor, microphone, RGB LED and audio player. It also notifies about button state and battery changes. category=Sensors architectures=mbed_nano, nrf52 -url=https://github.com/OpenEarable/open-earable/tree/v1.3.0 +url=https://github.com/ThiasTux/open-earable includes=OpenEarable.h depends=EdgeML-Arduino, ArduinoBLE, Arduino_LPS22HB, STM32duino LSM6DSR, Adafruit BMP280 Library, DFRobot_BMX160 From f8fb41ad45dbab17fa8fe56d04742c95abf17dbf Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 12 Jun 2024 22:27:46 +0100 Subject: [PATCH 32/68] Increased version in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 78c12b3..c2f2ade 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 🦻 OpenEarable - Firmware v1.3.1 +# 🦻 OpenEarable - Firmware v1.4.0 OpenEarable is a new, open-source, Arduino-based platform for ear-based sensing applications. It provides a versatile prototyping platform with support for various sensors and actuators, making it suitable for earable research and development. From b2c995d9c792fab432a08f874066beca4231c932 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 12 Jun 2024 23:05:15 +0100 Subject: [PATCH 33/68] Added installation of board and libraries --- scripts/install.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/install.sh b/scripts/install.sh index 2503b89..5a99817 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,4 +1,24 @@ #!/bin/bash +# Install board +echo "Installing mbed_nano board version" +arduino-cli core install arduino:mbed_nano + +# Install dependecies +# Install EDGEML (1.3.3) +echo "Installing libraries..." +arduino-cli lib install EdgeML-Arduino@1.3.3 +arduino-cli lib install 'Adafruit BMP280 Library' +arduino-cli lib install "DFRobot_BMX160" +arduino-cli lib install "SdFat - Adafruit Fork" + + +tmp_output=$(arduino-cli core search arduino:mbed_nano | grep arduino:mbed_nano) +MBED_NANO_VERSION=$(echo "$tmp_output" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') +$version_number + +echo $MBED_NANO_VERSION + +OS=$(uname) # Path to your Arduino15 folder (replace with your actual path) ARDUINO_15_PATH="/path/to/Arduino15" From 41e549781a738ffd1d68cd11bb71132fd99198ff Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 12 Jun 2024 23:05:57 +0100 Subject: [PATCH 34/68] Added automatic detection of Arduino15 path for Linux and macOS --- scripts/install.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index 5a99817..b27aa58 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -21,7 +21,14 @@ echo $MBED_NANO_VERSION OS=$(uname) # Path to your Arduino15 folder (replace with your actual path) -ARDUINO_15_PATH="/path/to/Arduino15" +if [[ "$os" == "Linux" ]]; then + echo "This is a Linux system." + ARDUINO_15_PATH = "/home/$(whoami)/.arduino15" +elif [[ "$os" == "Darwin" ]]; then + echo "This is a macOS system." + ARDUINO_15_PATH = "/Users/$(whoami)/Library/Arduino15" + +echo $ARDUINO_15_PATH # Resources folder path (replace with your actual path) RESOURCES_PATH="../resources" From 43f071b6712ceaf9c0ee07bfbe313440f4781cd2 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 12 Jun 2024 23:07:25 +0100 Subject: [PATCH 35/68] Edit Arduino15 path to automatically include the board version --- scripts/install.sh | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) mode change 100644 => 100755 scripts/install.sh diff --git a/scripts/install.sh b/scripts/install.sh old mode 100644 new mode 100755 index b27aa58..9281321 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -51,16 +51,10 @@ WIRE_DIR="$RESOURCES_PATH/wire_files/Wire" VARIANT_DIR="$RESOURCES_PATH/variant" # Navigate to libraries directory -LIB_DIR="$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/4.0.4/libraries" +LIB_DIR="$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/libraries" -# Check mbed_nano version (modify if needed) -MBED_NANO_VERSION="4.0.4" - -# Install mbed_nano board (if not already installed) -if ! grep -q "mbed_nano:$MBED_NANO_VERSION" boards.txt; then - echo "Installing mbed_nano board version $MBED_NANO_VERSION..." - arduino-cli boards install arduino:mbed_nano:$MBED_NANO_VERSION -fi +# Create new board folder +NEW_LIB_DIR="$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/libraries" # Replace SPI library echo "Replacing SPI library..." From 97aeb4d38a54d60f230c5ecfb78e1b76278ecb1a Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 13 Jun 2024 11:03:43 +0100 Subject: [PATCH 36/68] Edited gitignore to add vscode Arduino development files --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7f94078..3588f6d 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,5 @@ src/main.cpp # VS Code -**/.vscode \ No newline at end of file +**/.vscode/c_cpp_properties.json +**/.vscode/settings.json \ No newline at end of file From d35e16d38fcc6a36ca9e11f4f39f44ac155e67e3 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 13 Jun 2024 11:04:39 +0100 Subject: [PATCH 37/68] Added vscode file for Arduino development --- .vscode/arduino.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .vscode/arduino.json diff --git a/.vscode/arduino.json b/.vscode/arduino.json new file mode 100644 index 0000000..90d37d3 --- /dev/null +++ b/.vscode/arduino.json @@ -0,0 +1,5 @@ +{ + "board": "arduino:openearable:nano33ble", + "sketch": "examples/App/App.ino", + "port": "/dev/tty.usbmodem11201" +} \ No newline at end of file From 82a2eeb580fc62c850a4098f75ac6cf611a49de6 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 13 Jun 2024 13:42:53 +0100 Subject: [PATCH 38/68] Completed install script to create a new board for Openearable. Tested on macos. --- scripts/install.sh | 73 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 9281321..afa2f02 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -11,7 +11,6 @@ arduino-cli lib install 'Adafruit BMP280 Library' arduino-cli lib install "DFRobot_BMX160" arduino-cli lib install "SdFat - Adafruit Fork" - tmp_output=$(arduino-cli core search arduino:mbed_nano | grep arduino:mbed_nano) MBED_NANO_VERSION=$(echo "$tmp_output" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') $version_number @@ -21,12 +20,13 @@ echo $MBED_NANO_VERSION OS=$(uname) # Path to your Arduino15 folder (replace with your actual path) -if [[ "$os" == "Linux" ]]; then +if [[ "$OS" == "Linux" ]]; then echo "This is a Linux system." - ARDUINO_15_PATH = "/home/$(whoami)/.arduino15" -elif [[ "$os" == "Darwin" ]]; then - echo "This is a macOS system." - ARDUINO_15_PATH = "/Users/$(whoami)/Library/Arduino15" + ARDUINO_15_PATH="/home/$(whoami)/.arduino15" +elif [[ "$OS" == "Darwin" ]]; then + echo This is a macOS system. + ARDUINO_15_PATH="/Users/$(whoami)/Library/Arduino15" +fi echo $ARDUINO_15_PATH @@ -50,11 +50,25 @@ SPI_DIR="$RESOURCES_PATH/spi_files/SPI" WIRE_DIR="$RESOURCES_PATH/wire_files/Wire" VARIANT_DIR="$RESOURCES_PATH/variant" -# Navigate to libraries directory -LIB_DIR="$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/libraries" +# Create new board for OpenEarable +BOARD_DIR="$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION" +NEW_BOARD_DIR="$ARDUINO_15_PATH/packages/arduino/hardware/openearable/$MBED_NANO_VERSION" + +echo "Creating folder for new Openearable board..." +mkdir "$ARDUINO_15_PATH/packages/arduino/hardware/openearable" +cp -R $BOARD_DIR $NEW_BOARD_DIR +rm -rf "$NEW_BOARD_DIR/variants/NANO_RP20240_CONNECT" + +echo "Replacing board names..." +if [[ "$OS" == "Linux" ]]; then + sed -i '/^nanorp2040connect/d' "$NEW_BOARD_DIR/boards.txt" + sed -i 's/nano33ble.name=Arduino Nano 33 BLE/nano33ble.name=Openearable/' "$NEW_BOARD_DIR/boards.txt" +elif [[ "$OS" == "Darwin" ]]; then + sed -i="" '/^nanorp2040connect/d' "$NEW_BOARD_DIR/boards.txt" + sed -i="" 's/nano33ble.name=Arduino Nano 33 BLE/nano33ble.name=Openearable/' "$NEW_BOARD_DIR/boards.txt" +fi -# Create new board folder -NEW_LIB_DIR="$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/libraries" +LIB_DIR="$NEW_BOARD_DIR/libraries/" # Replace SPI library echo "Replacing SPI library..." @@ -65,32 +79,47 @@ cp -r "$SPI_DIR" "$LIB_DIR" echo "Replacing Wire library..." rm -rf "$LIB_DIR/Wire" cp -r "$WIRE_DIR" "$LIB_DIR" -rm "$LIB_DIR/Wire.cpp" # Copy RingBuffer files echo "Copying RingBuffer files..." -cp "$RESOURCES_PATH/wire_files/RingBuffer.h" "$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/cores/arduino" -cp "$RESOURCES_PATH/wire_files/RingBuffer.cpp" "$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/cores/arduino" +cp "$RESOURCES_PATH/wire_files/RingBuffer.h" "$ARDUINO_15_PATH/packages/arduino/hardware/openearable/$MBED_NANO_VERSION/cores/arduino" +cp "$RESOURCES_PATH/wire_files/RingBuffer.cpp" "$ARDUINO_15_PATH/packages/arduino/hardware/openearable/$MBED_NANO_VERSION/cores/arduino" # Replace nrfx_spim files echo "Replacing nrfx_spim files..." -cp "$RESOURCES_PATH/spi_files/nrfx_spim.h" "$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/cores/arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/drivers/include" -cp "$RESOURCES_PATH/spi_files/nrfx_spim.c" "$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/cores/arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/drivers/src" +cp "$RESOURCES_PATH/spi_files/nrfx_spim.h" "$ARDUINO_15_PATH/packages/arduino/hardware/openearable/$MBED_NANO_VERSION/cores/arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/drivers/include/" +cp "$RESOURCES_PATH/spi_files/nrfx_spim.c" "$ARDUINO_15_PATH/packages/arduino/hardware/openearable/$MBED_NANO_VERSION/cores/arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/drivers/src/" # Replace variant files echo "Replacing variant files..." -cp "$RESOURCES_PATH/variant/pins_arduino.h" "$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/variants/ARDUINO_NANO33BLE" -cp "$RESOURCES_PATH/variant/variant.cpp" "$ARDUINO_15_PATH/packages/arduino/hardware/mbed_nano/$MBED_NANO_VERSION/variants/ARDUINO_NANO33BLE" +cp "$RESOURCES_PATH/variant/pins_arduino.h" "$ARDUINO_15_PATH/packages/arduino/hardware/openearable/$MBED_NANO_VERSION/variants/ARDUINO_NANO33BLE" +cp "$RESOURCES_PATH/variant/variant.cpp" "$ARDUINO_15_PATH/packages/arduino/hardware/openearable/$MBED_NANO_VERSION/variants/ARDUINO_NANO33BLE" # sdFat Library Setup SDFAT_LIB_DIR="$HOME/Documents/Arduino/libraries/SdFat_-_Adafruit_Fork" # Update path if needed # Check if sDFat library exists if [ ! -d "$SDFAT_LIB_DIR" ]; then - echo "Warning: SdFat library not found at SDFAT\_LIB\_DIR" -echo "Please install the SdFat library from Bill Greiman\." + echo "Warning: SdFat library not found at $SDFAT_LIB_DIR" +echo "Please install the SdFat library from Bill Greiman." +exit 1 +fi +# Replace SdFatConfig.h +echo "Replacing SdFatConfig.h..." +cp "$RESOURCES_PATH/sdfat_config/SdFatConfig.h" "$SDFAT_LIB_DIR/" + +# sdFat Library Setup +BMP280_LIB_DIR="$HOME/Documents/Arduino/libraries/Adafruit_BMP280_Library" # Update path if needed + +# Check if sDFat library exists +if [ ! -d "$BMP280_LIB_DIR" ]; then + echo "Warning: BMP280 library not found at $BMP280_LIB_DIR" +echo "Please install the BMP280 library." exit 1 fi -\# Replace SdFatConfig\.h -echo "Replacing SdFatConfig\.h\.\.\." -cp " \ No newline at end of file +# Replace SdFatConfig.h +echo "Replacing BMP280 Files..." +cp "$RESOURCES_PATH/Adafruit_BMP280_Library/Adafruit_BMP280.cpp" "$BMP280_LIB_DIR/" +cp "$RESOURCES_PATH/Adafruit_BMP280_Library/Adafruit_BMP280.h" "$BMP280_LIB_DIR/" + +echo "Done. If you have issues, please reboot first." \ No newline at end of file From 5d6596ec8f3b949fce19fcfbc63bee0f1893e7a9 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 13 Jun 2024 13:57:03 +0100 Subject: [PATCH 39/68] Updated README for automatic configuration procedure --- README.md | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c2f2ade..1d24674 100644 --- a/README.md +++ b/README.md @@ -43,10 +43,29 @@ OpenEarable is controlled and streams sensor data via BLE (Bluetooth Low Energy) ## Setup -### Arduino IDE +### Automatic setup (Preferred method!!) + +If you are on Linux or macOS, you can setup you environment using the script in `script/install.sh`. In order to so, please install the `arduino-cli` following the guide [here](https://arduino.github.io/arduino-cli/0.35/installation/). + +#### macOS +For macos using brew: + +```brew install arduino-cli``` + +#### Env setup + +To setup the environment, navigate to `scripts` and then run: + +```./install.sh``` + +The script uses `arduino-cli` to download and install all the dependencies (i.e. board, libraries, etc.) and to make the required changes to the libraries. The script also generate a new board so that the original Mbed OS Nano installation remains untouched in case you are developing also with other Nano boards (plus it doesn't get touched if the Nano board installation gets updated). + +### Manual setup (Not recommended) + +#### Arduino IDE Download and install the Arduino IDE. OpenEarable is based on the "Arduino Nano 33 BLE Sense" board. Therefore, you first have to install the required dependencies ("Arduino Mbed OS Nano Boards" via boards manager) in your Arduino IDE following this [Setup Guide](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-board-manager#mbed-os-nano). -### Arduino Libraries +#### Arduino Libraries The following Arduino Libraries have to be installed in your Arduino IDE by navigating to `Sketch -> Include Library -> Manage Libraries`: - [EdgeML-Arduino (version 1.3.3)](https://github.com/edge-ml/EdgeML-Arduino), which includes the following dependencies that are also required and automatically installed: - [ArduinoBLE](https://github.com/arduino-libraries/ArduinoBLE) @@ -55,11 +74,11 @@ The following Arduino Libraries have to be installed in your Arduino IDE by navi - [SdFat - Adafruit Fork](https://github.com/adafruit/SdFat) -### SD Card Setup +#### SD Card Setup In order to be compatible with the OpenEarable library the SD card needs to be formatted with the exFAT format. Make sure to have a sufficiently fast SD card. (Required SD Card: SandDisk class 10 and class A30) -### SPI, Wire, and Variant Setup +#### SPI, Wire, and Variant Setup The default Arduino implementation of the SPI library does not meet the required speed. To address this, optimized SPI files are provided. Follow the steps below to integrate these files into Arduino. All referenced files can be found in the "resources" folder in the "spi_files" subfolder. @@ -86,7 +105,7 @@ To fully integrate the optimized SPI files, changes to the Arduino Nano 33 BLE b 10. Navigate back to the `Arduino15` folder. Navigate to `packages/arduino/hardware/mbed_nano/4.0.4/variants/ARDUINO_NANO33BLE`. Replace `pins_arduino.h` and `variant.cpp `with the files provided under `resources/variant` of this repository. -### sdFat Library Setup +#### sdFat Library Setup One of the library dependencies is the SdFat library from Bill Greiman. This library is used to send data to the SD card. To achieve the desired write speeds of up to 1.5Mbps the library has to be modified slighlty. @@ -95,13 +114,13 @@ To achieve the desired write speeds of up to 1.5Mbps the library has to be modif 3. Inside the `src` folder, replace the `SdFatConfig.h` with the provided `SdFatConfig.h` file found in the `resources/sdfat_config` folder of this repository. -### BMP280 Library Setup +#### BMP280 Library Setup The BMP280 library has to be slightly modified. 1. Go to the `Arduino/libraries` folder (commonly found in your `Documents` folder) and locate the `Adafruit_BMP280_Library` folder. 2. Replace the files `Adafruit_BMP280.cpp` and `Adafruit_BMP280.h` with the files found in the `resources/Adafruit_BMP280_Library` folder of this repository. -### Reboot +#### Reboot To make sure that all your changes are applied correctly, restart your computer. ## Usage From 08b2c567c2f09b28b58be051feac156b51389e75 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 13 Jun 2024 13:57:19 +0100 Subject: [PATCH 40/68] Updated README for automatic configuration procedure --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d24674..0675e89 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ The BMP280 library has to be slightly modified. To make sure that all your changes are applied correctly, restart your computer. ## Usage + ### Install OpenEarable Now that all dependencies are configured, the last step is to install this repository as a library as follows: @@ -158,7 +159,7 @@ void loop() With this minimum sketch, all internal functionality is activated and OpenEarable becomes controllable via our [Dashboard](https://github.com/OpenEarable/dashboard), via [EdgeML](https://edge-ml.org/), and via the BLE API. ### Flashing -To flash the firmware, make sure you select `Arduino Nano 33 BLE` as target and the port that your OpenEarable is connected to. Then simply press the `Upload` arrow. +To flash the firmware, make sure you select `Openearable` as target (or `Arduino Nano 33 BLE` if you used the manual setup procedure) and the port that your OpenEarable is connected to. Then simply press the `Upload` arrow. ### Dashboard From 633e547bd21985b42866f35e878fb28a01facee1 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 13 Jun 2024 14:30:37 +0100 Subject: [PATCH 41/68] Added note about v1.4.0 firmware and fixed ToC --- README.md | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0675e89..19fd522 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,16 @@ OpenEarable is a new, open-source, Arduino-based platform for ear-based sensing ## Table of Contents - [Introduction](#Introduction) + - [Note about v1.4.0](#note-about-v140) - [Setup](#Setup) - - [Arduino IDE](#Arduino-IDE) - - [Arduino Libraries](#Arduino-Libraries) - - [SD Card Setup](#SD-Card-Setup) - - [SPI Setup](#SPI-Setup) - - [sdfat Library Setup](#sdfat-Library-Setup) - - [BMP280 Library Setup](#BMP280-Library-Setup) + - [Automatic setup (Preferred)](#automatic-setup-preferred-method) + - [Manual setup (Not recommended)](#manual-setup-not-recommended) + - [Arduino IDE](#Arduino-IDE) + - [Arduino Libraries](#Arduino-Libraries) + - [SD Card Setup](#SD-Card-Setup) + - [SPI Setup](#SPI-Setup) + - [sdfat Library Setup](#sdfat-Library-Setup) + - [BMP280 Library Setup](#BMP280-Library-Setup) - [Usage](#Usage) - [Install OpenEarable](#Install-OpenEarable) - [Default Firmware](#Default-Firmware) @@ -38,7 +41,14 @@ OpenEarable is a new, open-source, Arduino-based platform for ear-based sensing OpenEarable is designed to enable ear-based sensing applications by offering a flexible and open-source hardware platform. It incorporates a range of sensors, including a 9-axis inertial measurement unit, an ear canal pressure and temperature sensor, an inward-facing ultrasound microphone, a speaker, a push button, and a controllable RGB LED. With these features, OpenEarable provides researchers and developers with the ability to explore various application scenarios. For more information visit the [OpenEarable](https://open-earable.teco.edu/) website. -OpenEarable is controlled and streams sensor data via BLE (Bluetooth Low Energy). Audio is played from and recorded to the internal SD card (required card SanDisk Extreme Class 3, must be formatted as exFAT). OpenEarable is compatible with the provided [dashboard](https://github.com/OpenEarable/dashboard) and [edge-ml](https://edge-ml.org/). +OpenEarable is controlled and streams sensor data via BLE (Bluetooth Low Energy). Audio is played from and recorded to the internal SD card (required card SanDisk Extreme Class 3, must be formatted as exFAT). OpenEarable is compatible with the provided [dashboard](https://github.com/OpenEarable/dashboard) and [edge-ml](https://edge-ml.org/). + +### Note about v1.4.0 + +Version 1.4.0 of the firmware is designed for offline data collection. By default, all data (IMU, Baro/Temp and Audio) are logged on the SD card. **Choose a very fast SDCard!!** Here's some examples we tested: +- Samsung EVO Plus +- SanDisk Extreme Pro +Note that even for the same class, not all SDcard from different manufacturers have the same performance!! ## Setup From 2cf91daa830cf1a2c740ba08ab5068ecc5be99bd Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 13 Jun 2024 16:15:47 +0100 Subject: [PATCH 42/68] Fixed folder for editing SDFat library --- scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index afa2f02..1d2c8e8 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -96,7 +96,7 @@ cp "$RESOURCES_PATH/variant/pins_arduino.h" "$ARDUINO_15_PATH/packages/arduino/h cp "$RESOURCES_PATH/variant/variant.cpp" "$ARDUINO_15_PATH/packages/arduino/hardware/openearable/$MBED_NANO_VERSION/variants/ARDUINO_NANO33BLE" # sdFat Library Setup -SDFAT_LIB_DIR="$HOME/Documents/Arduino/libraries/SdFat_-_Adafruit_Fork" # Update path if needed +SDFAT_LIB_DIR="$HOME/Documents/Arduino/libraries/SdFat_-_Adafruit_Fork/src" # Update path if needed # Check if sDFat library exists if [ ! -d "$SDFAT_LIB_DIR" ]; then From 919d7f4340294de6fa35bd006a3deeb922e42350 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 13 Jun 2024 16:16:42 +0100 Subject: [PATCH 43/68] Added info about v1.4.0 --- README.md | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 19fd522..319ef18 100644 --- a/README.md +++ b/README.md @@ -45,28 +45,54 @@ OpenEarable is controlled and streams sensor data via BLE (Bluetooth Low Energy) ### Note about v1.4.0 +#### SD card logging + Version 1.4.0 of the firmware is designed for offline data collection. By default, all data (IMU, Baro/Temp and Audio) are logged on the SD card. **Choose a very fast SDCard!!** Here's some examples we tested: - Samsung EVO Plus - SanDisk Extreme Pro Note that even for the same class, not all SDcard from different manufacturers have the same performance!! +#### Bluetooth streaming + +Because the main focus is to log the data locally on the SD card, this version of the firmware streams limited amount of data over BLE. By default, the streaming over BLE happens at 10 Hz, no matter what sampling rate you set for the recordings. + +#### RGB led + +In order to let researcher know whether the device is recording or not without being always connected to the dashboard, the RGB led is used to show the recording status. If a certain colour is on, then the corresponding sensor data is being recorded: + +- Red: Microphone +- Green: Baro/Temp +- Blue: IMU + +Obviously, any combination of sensors enabled/disable will result in a mixed colour for the led (within the hardware limits!!) (i.e. if microphone and baro/tempo are being recorded then the led would be yellow). + ## Setup ### Automatic setup (Preferred method!!) +Clone this repo in your Arduino library folder, usually in under `Documents/Arduino/libraries`: + +```bash +git clone https://github.com/ThiasTux/open-earable OpenEarable +``` + If you are on Linux or macOS, you can setup you environment using the script in `script/install.sh`. In order to so, please install the `arduino-cli` following the guide [here](https://arduino.github.io/arduino-cli/0.35/installation/). #### macOS For macos using brew: -```brew install arduino-cli``` +```bash +brew install arduino-cli +``` #### Env setup To setup the environment, navigate to `scripts` and then run: -```./install.sh``` +```bash +./install.sh +``` The script uses `arduino-cli` to download and install all the dependencies (i.e. board, libraries, etc.) and to make the required changes to the libraries. The script also generate a new board so that the original Mbed OS Nano installation remains untouched in case you are developing also with other Nano boards (plus it doesn't get touched if the Nano board installation gets updated). From c7990aa5829d8c8718f052302cae06c4472f8ed0 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 13 Jun 2024 16:18:43 +0100 Subject: [PATCH 44/68] Fixed readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 319ef18..b161921 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ OpenEarable is controlled and streams sensor data via BLE (Bluetooth Low Energy) Version 1.4.0 of the firmware is designed for offline data collection. By default, all data (IMU, Baro/Temp and Audio) are logged on the SD card. **Choose a very fast SDCard!!** Here's some examples we tested: - Samsung EVO Plus - SanDisk Extreme Pro + Note that even for the same class, not all SDcard from different manufacturers have the same performance!! #### Bluetooth streaming From f560051ce0d1234fcfd098298ec25b11ef06c815 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 13 Jun 2024 16:22:56 +0100 Subject: [PATCH 45/68] Set fixed delay for BLE streaming of data (10 Hz) --- src/task_manager/TaskManager.cpp | 2 -- src/task_manager/TaskManager.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/task_manager/TaskManager.cpp b/src/task_manager/TaskManager.cpp index 69bc7fe..8a80d74 100644 --- a/src/task_manager/TaskManager.cpp +++ b/src/task_manager/TaskManager.cpp @@ -108,8 +108,6 @@ void TaskManager::begin(float baro_samplerate, float imu_samplerate) { if (baro_samplerate >= 0) _baro_delay = (int) baro_samplerate > 0 ? (1000.0/baro_samplerate) : _default_loop_delay; if (imu_samplerate >= 0) _imu_delay = (int) imu_samplerate > 0 ? (1000.0/imu_samplerate) : _default_loop_delay; - _edge_ml_delay = max(_baro_delay, _imu_delay); - /*float edge_rate = max(baro_samplerate, imu_samplerate); if (edge_rate <= 0) { diff --git a/src/task_manager/TaskManager.h b/src/task_manager/TaskManager.h index 67ae475..c9e0393 100644 --- a/src/task_manager/TaskManager.h +++ b/src/task_manager/TaskManager.h @@ -19,7 +19,7 @@ class TaskManager { //float _rate_factor = 1.25; - int _edge_ml_delay; + int _edge_ml_delay = 100; unsigned int _edge_ml_last; unsigned int _baro_last; unsigned int _imu_last; From fbee027df73951389316732cb7340dfcd41abbed Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 19 Jun 2024 17:23:24 +0100 Subject: [PATCH 46/68] Added renaming of earable according to left/right. Increased library version. Fixed null pointer that caused bootloop --- README.md | 12 +++++++++++- examples/App/App.ino | 11 +++++++---- src/OpenEarable.h | 10 +++++----- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b161921..ebe3557 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ For more information visit the [OpenEarable](https://open-earable.teco.edu/) web OpenEarable is controlled and streams sensor data via BLE (Bluetooth Low Energy). Audio is played from and recorded to the internal SD card (required card SanDisk Extreme Class 3, must be formatted as exFAT). OpenEarable is compatible with the provided [dashboard](https://github.com/OpenEarable/dashboard) and [edge-ml](https://edge-ml.org/). -### Note about v1.4.0 +### Note about firmwares >v1.4.0 #### SD card logging @@ -67,6 +67,16 @@ In order to let researcher know whether the device is recording or not without b Obviously, any combination of sensors enabled/disable will result in a mixed colour for the led (within the hardware limits!!) (i.e. if microphone and baro/tempo are being recorded then the led would be yellow). +#### Device naming + +The new firmware introduces the possibility to change the names of the devices programmatically. This simplifies the usage in data collections where a left and a right earable are used. By default, the name is "OpenEarable" as per previous firmwares. +The left or right names can be given when programming and **MUST BE** `OELeft` or `OERight`. +The firmware will then + +#### Dashboard + +In order to use the new version of the firmware, especially if the custom names are used for left/right earables, we suggest to use the modified dashboard available [here](https://github.com/ThiasTux/openearable-dashboard). + ## Setup diff --git a/examples/App/App.ino b/examples/App/App.ino index a88cf83..8f3868c 100644 --- a/examples/App/App.ino +++ b/examples/App/App.ino @@ -4,15 +4,18 @@ * OpenEarable Dashboard: openearable.github.io/dashboard/ * edge-ml: app.edge-ml.org * - * Firmware-version: 1.3.0 - * Release-date: 6.10.2023 + * Firmware-version: 1.4.1 + * Release-date: 17.06.2024 */ #include "Arduino.h" #include "OpenEarable.h" // Set DEBUG to true in order to enable debug print -#define DEBUG true +#define DEBUG false + +// Change name to OELeft or OERight before flashing ("OpenEarable" if left as default value) +String d_name = "OpenEarable"; void setup() { @@ -23,7 +26,7 @@ void setup() delay(5000); #endif - open_earable.begin(); + open_earable.begin(d_name); } void loop() diff --git a/src/OpenEarable.h b/src/OpenEarable.h index 9095703..650ee1d 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -30,8 +30,8 @@ #include -const String device_name = "OpenEarable"; -const String firmware_version = "1.4.0"; +String device_name; +const String firmware_version = "1.4.1"; const String hardware_version = "1.3.0"; bool _data_logger_flag = true; @@ -45,8 +45,9 @@ class OpenEarable { public: OpenEarable() = default; - void begin() { - // Serial.begin(0); + void begin(String d_name) { + + device_name = d_name; _interface = new SensorManager_Earable(); _battery = new Battery_Service(); @@ -64,7 +65,6 @@ class OpenEarable { } if (_data_logger_flag) { - _debug->println("Starting SDLogger"); IMULogger::begin(); BAROLogger::begin(); } From 704dca0705d2f64d6beff90f4de4f82679f76844 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 19 Jun 2024 17:23:39 +0100 Subject: [PATCH 47/68] Increased library version --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 54648c1..706ed8b 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=OpenEarable -version=1.4.0 +version=1.4.1 author=Mathias / Mobisys maintainer=Mathias sentence=Firmware to use OpenEarable with the provided dashboard and edge-ml.org. From e3415dbf557298537201dadc96cd9227bd16ff47 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Fri, 21 Jun 2024 11:44:17 +0100 Subject: [PATCH 48/68] Changed gain to 40 as default value --- src/audio_pdm/PDM_Mic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/audio_pdm/PDM_Mic.h b/src/audio_pdm/PDM_Mic.h index 92d3cb9..810d4b4 100644 --- a/src/audio_pdm/PDM_Mic.h +++ b/src/audio_pdm/PDM_Mic.h @@ -70,7 +70,7 @@ class PDM_Mic : public InputDevice { int _channels = 1; int _sampleRate = 16000; - int _gain = 80; + int _gain = 40; bool _first = true; From 887766fb38ec6a268b9907e2b0ac954a0daa3d66 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 18 Jul 2024 14:11:51 +0100 Subject: [PATCH 49/68] Set dev branch example app for debugging --- examples/App/App.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/App/App.ino b/examples/App/App.ino index 8f3868c..cb02bc7 100644 --- a/examples/App/App.ino +++ b/examples/App/App.ino @@ -12,10 +12,10 @@ #include "OpenEarable.h" // Set DEBUG to true in order to enable debug print -#define DEBUG false +#define DEBUG true // Change name to OELeft or OERight before flashing ("OpenEarable" if left as default value) -String d_name = "OpenEarable"; +String d_name = "OERight"; void setup() { From 54889c73f42079e3c9519ba22a8788f59090a6cf Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Tue, 6 Aug 2024 16:27:05 +0100 Subject: [PATCH 50/68] Added dual channel recording for dual microphone eartips --- src/audio_pdm/AudioTarget.h | 1 + src/audio_pdm/InputDevice.h | 3 +++ src/audio_pdm/PDM_Mic.cpp | 13 +++++++++---- src/audio_pdm/PDM_Mic.h | 5 +++-- src/audio_pdm/Recorder.cpp | 14 ++++++++++++++ src/audio_pdm/Recorder.h | 2 ++ src/audio_pdm/WavRecorder.cpp | 5 +++++ src/audio_pdm/WavRecorder.h | 2 ++ src/utils/WAVWriter.h | 1 + 9 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/audio_pdm/AudioTarget.h b/src/audio_pdm/AudioTarget.h index a803979..7e43030 100644 --- a/src/audio_pdm/AudioTarget.h +++ b/src/audio_pdm/AudioTarget.h @@ -6,6 +6,7 @@ class AudioTarget : public Provider { public: virtual void setSampleRate(int sample_rate) = 0; + virtual void setChannels(int channels) = 0; }; #endif \ No newline at end of file diff --git a/src/audio_pdm/InputDevice.h b/src/audio_pdm/InputDevice.h index f6f118a..5bd0d34 100644 --- a/src/audio_pdm/InputDevice.h +++ b/src/audio_pdm/InputDevice.h @@ -13,6 +13,9 @@ class InputDevice : public Consumer { virtual int setSampleRate(int _sampleRate) = 0; virtual int getSampleRate() = 0; + virtual int setChannels(int _channels) = 0; + virtual int getChannels() = 0; + void setBuffer(uint8_t * buffer, int blockSize, int blockCount) { stream->buffer.set_buffer(buffer, blockSize, blockCount); } diff --git a/src/audio_pdm/PDM_Mic.cpp b/src/audio_pdm/PDM_Mic.cpp index 1bc2213..790fc84 100644 --- a/src/audio_pdm/PDM_Mic.cpp +++ b/src/audio_pdm/PDM_Mic.cpp @@ -130,7 +130,7 @@ bool PDM_Mic::begin() { // clear the buffer stream->buffer.reset(); - nrf_pdm_buffer_set((uint32_t*)stream->buffer.getWritePointer(), stream->buffer.getBlockSize() / (sizeof(int16_t) * _channels)); + nrf_pdm_buffer_set((uint32_t*)stream->buffer.getWritePointer(), stream->buffer.getBlockSize() / (sizeof(int16_t) * 1)); // set the PDM IRQ priority and enable NVIC_SetPriority(PDM_IRQn, PDM_IRQ_PRIORITY); @@ -196,8 +196,9 @@ void PDM_Mic::setPins(int dinPin, int clkPin) { _clkPin = clkPin; } -void PDM_Mic::setChannels(int channels) { - _channels = channels; +int PDM_Mic::setChannels(int channels) { + _channels = constrain(channels,1,2); + return _channels; } int PDM_Mic::setSampleRate(int sampleRate) { @@ -214,6 +215,10 @@ int PDM_Mic::getSampleRate() { return _sampleRate; } +int PDM_Mic::getChannels() { + return _channels; +} + void PDM_Mic::IrqHandler(bool halftranfer) { if (nrf_pdm_event_check(NRF_PDM_EVENT_STARTED)) { nrf_pdm_event_clear(NRF_PDM_EVENT_STARTED); @@ -226,7 +231,7 @@ void PDM_Mic::IrqHandler(bool halftranfer) { } // switch to the next buffer - nrf_pdm_buffer_set((uint32_t*)stream->buffer.getWritePointer(1), stream->buffer.getBlockSize() / (sizeof(int16_t) * _channels)); + nrf_pdm_buffer_set((uint32_t*)stream->buffer.getWritePointer(1), stream->buffer.getBlockSize() / (sizeof(int16_t) * 1)); //stream->buffer.incrementWritePointer(); // call receive callback if provided diff --git a/src/audio_pdm/PDM_Mic.h b/src/audio_pdm/PDM_Mic.h index 810d4b4..00c2c82 100644 --- a/src/audio_pdm/PDM_Mic.h +++ b/src/audio_pdm/PDM_Mic.h @@ -50,9 +50,10 @@ class PDM_Mic : public InputDevice { void setGain(int gain); void setPins(int dinPin, int clkPin); - void setChannels(int channels); + int setChannels(int channels) override; int getSampleRate() override; + int getChannels() override; void setBlockBufferSizes(int blockSize, int blockCount); @@ -70,7 +71,7 @@ class PDM_Mic : public InputDevice { int _channels = 1; int _sampleRate = 16000; - int _gain = 40; + int _gain = 60; bool _first = true; diff --git a/src/audio_pdm/Recorder.cpp b/src/audio_pdm/Recorder.cpp index 99a5371..ef4201a 100644 --- a/src/audio_pdm/Recorder.cpp +++ b/src/audio_pdm/Recorder.cpp @@ -19,12 +19,20 @@ void Recorder::setSampleRate(int sample_rate) { if (target) target->setSampleRate(_sampleRate); } +void Recorder::setChannels(int channels) { + _channels = channels; + if (device) _channels = device->setChannels(channels); + if (target) target->setChannels(_channels); +} + bool Recorder::begin() { if (_available) return true; if (!device || !target) return false; device->setBuffer(PDM_BUFFER, pdm_b_size, pdm_b_count); _sampleRate = device->setSampleRate(_sampleRate); + _channels = device->setChannels(_channels); target->setSampleRate(_sampleRate); + target->setChannels(_channels); target->begin(); if (!target->available()) return false; _available = device->begin(); @@ -50,6 +58,8 @@ void Recorder::debug(Stream &stream) { void Recorder::print_info() { Serial.println("RECORDER INFO:"); + Serial.print("channels: "); + Serial.println(_channels); Serial.print("sample rate: "); Serial.println(_sampleRate); Serial.print("target: "); @@ -95,10 +105,12 @@ void Recorder::stop() { void Recorder::setDevice(InputDevice * device) { this->device = device; _sampleRate = device->setSampleRate(_sampleRate); + _channels = device->setChannels(_channels); if (target) { target->setStream(&(device->stream)); target->setSampleRate(_sampleRate); + target->setChannels(_channels); } } @@ -125,6 +137,8 @@ void Recorder::config_callback(SensorConfigurationPacket *config) { // Check for valid sample rate recorder.setSampleRate(sample_rate); + recorder.setChannels(2); + // Make sure that pdm mic is not running already! recorder.stop(); diff --git a/src/audio_pdm/Recorder.h b/src/audio_pdm/Recorder.h index 0ee1b89..aa2f149 100644 --- a/src/audio_pdm/Recorder.h +++ b/src/audio_pdm/Recorder.h @@ -33,6 +33,7 @@ class Recorder { void setTarget(AudioTarget * target); void setDevice(InputDevice * device); void setSampleRate(int sample_rate); + void setChannels(int channels); void print_info(); @@ -45,6 +46,7 @@ class Recorder { bool available(); private: int _sampleRate; + int _channels; bool _running = false; bool _available = false; }; diff --git a/src/audio_pdm/WavRecorder.cpp b/src/audio_pdm/WavRecorder.cpp index b0a79e1..d0cc92c 100644 --- a/src/audio_pdm/WavRecorder.cpp +++ b/src/audio_pdm/WavRecorder.cpp @@ -12,6 +12,7 @@ bool WavRecorder::begin() { (*stream)->open(); _wavWriter->setName(_name); _wavWriter->setSampleRate(_sampleRate); + _wavWriter->setChannels(_channels); const bool writer_begin = _wavWriter->begin(); if (writer_begin) start(); return writer_begin; @@ -21,6 +22,10 @@ void WavRecorder::setSampleRate(int sampleRate) { _sampleRate = sampleRate; } +void WavRecorder::setChannels(int channels) { + _channels = channels; +} + bool WavRecorder::available() { return _stream; } diff --git a/src/audio_pdm/WavRecorder.h b/src/audio_pdm/WavRecorder.h index 66ef0bd..8615d2d 100644 --- a/src/audio_pdm/WavRecorder.h +++ b/src/audio_pdm/WavRecorder.h @@ -23,6 +23,7 @@ class WavRecorder : public AudioTarget { void setSampleRate(int sampleRate) override; void setGain(int gain); + void setChannels(int channels); void enable_serial_data(); void disable_serial_data(); @@ -35,6 +36,7 @@ class WavRecorder : public AudioTarget { const String _name; int _sampleRate = 0; + int _channels = 1; WAVWriter * _wavWriter; }; diff --git a/src/utils/WAVWriter.h b/src/utils/WAVWriter.h index cbc47c3..aca206f 100644 --- a/src/utils/WAVWriter.h +++ b/src/utils/WAVWriter.h @@ -12,6 +12,7 @@ class WAVWriter { public: WAVWriter(); ~WAVWriter(); + bool begin(); void end(); From 018a9a35fb4d9ed1abc6637cc8587c8ebd7024ed Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 8 Aug 2024 15:34:06 +0100 Subject: [PATCH 51/68] Increase hardware version for dual mic --- src/OpenEarable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index 650ee1d..4c20bcf 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -32,7 +32,7 @@ String device_name; const String firmware_version = "1.4.1"; -const String hardware_version = "1.3.0"; +const String hardware_version = "1.4.0"; bool _data_logger_flag = true; From 17ccc8db968a331af177d29c258dd7466d67243d Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 8 Aug 2024 15:39:09 +0100 Subject: [PATCH 52/68] Added configurable gains for each mic --- src/audio_pdm/PDM_Mic.cpp | 35 ++++++++++++++++++----------------- src/audio_pdm/PDM_Mic.h | 10 ++++++---- src/audio_pdm/Recorder.cpp | 22 ++++++++++++++++------ 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/audio_pdm/PDM_Mic.cpp b/src/audio_pdm/PDM_Mic.cpp index 790fc84..78ceace 100644 --- a/src/audio_pdm/PDM_Mic.cpp +++ b/src/audio_pdm/PDM_Mic.cpp @@ -6,7 +6,6 @@ //#include #include "nrf_pdm.h" -#define DEFAULT_PDM_GAIN 20 #define PDM_IRQ_PRIORITY 7 #define NRF_PDM_FREQ_1280K (nrf_pdm_freq_t)(0x0A000000UL) ///< PDM_CLK= 1.280 MHz (32 MHz / 25) => Fs= 20000 Hz [Ratio80 => Fs= 16000 Hz] @@ -96,10 +95,20 @@ bool PDM_Mic::begin() { switch (_channels) { case 2: nrf_pdm_mode_set(NRF_PDM_MODE_STEREO, NRF_PDM_EDGE_LEFTFALLING); + nrf_pdm_gain_set(constrain(_gain_l, 0x00, 0x50), constrain(_gain_r, 0x00, 0x50)); break; case 1: - nrf_pdm_mode_set(NRF_PDM_MODE_MONO, NRF_PDM_EDGE_LEFTFALLING); + if (_gain_l < 0) { + // right mic + nrf_pdm_mode_set(NRF_PDM_MODE_MONO, NRF_PDM_EDGE_LEFTRISING); + nrf_pdm_gain_set(constrain(_gain_r, 0x00, 0x50), constrain(_gain_l, 0x00, 0x50)); + } else { + // left mic + nrf_pdm_mode_set(NRF_PDM_MODE_MONO, NRF_PDM_EDGE_LEFTFALLING); + nrf_pdm_gain_set(constrain(_gain_l, 0x00, 0x50), constrain(_gain_r, 0x00, 0x50)); + } + break; default: @@ -108,11 +117,6 @@ bool PDM_Mic::begin() { return false; // unsupported } - if(_gain == -1) { - _gain = DEFAULT_PDM_GAIN; - } - nrf_pdm_gain_set(_gain, _gain); - // configure the I/O and mux pinMode(_clkPin, OUTPUT); digitalWrite(_clkPin, LOW); @@ -141,13 +145,6 @@ bool PDM_Mic::begin() { return _available; } -bool PDM_Mic::begin(int channels, int sampleRate/*, bool high*/) { - _channels = channels; - _sampleRate = sampleRate; - - return begin(); -} - bool PDM_Mic::available() { return _available; } @@ -206,9 +203,13 @@ int PDM_Mic::setSampleRate(int sampleRate) { return _sampleRate; } -void PDM_Mic::setGain(int gain) { - _gain = gain; - if (_available) nrf_pdm_gain_set(_gain, _gain); +void PDM_Mic::setGain(int8_t gain_left, int8_t gain_right) { + _gain_l = gain_left; + _gain_r = gain_right; + + //setChannels((_gain_l >= 0) + (_gain_r >= 0)); + + //if (_available) nrf_pdm_gain_set(constrain(_gain_l, 0x00, 0x50), constrain(_gain_r, 0x00, 0x50)); } int PDM_Mic::getSampleRate() { diff --git a/src/audio_pdm/PDM_Mic.h b/src/audio_pdm/PDM_Mic.h index 00c2c82..3a69fcd 100644 --- a/src/audio_pdm/PDM_Mic.h +++ b/src/audio_pdm/PDM_Mic.h @@ -9,6 +9,9 @@ #include #endif +#define DEFAULT_PDM_GAIN 0x50 +#define MIC_OFF 0xFF + const int valid_sample_rates[] = { 16000, 20000, @@ -29,8 +32,6 @@ class PDM_Mic : public InputDevice { virtual ~PDM_Mic(); bool begin() override; - bool begin(int channels, int sampleRate); - void end() override; void start() override; @@ -47,7 +48,7 @@ class PDM_Mic : public InputDevice { //PORTENTA_H7 min -12 max 51 //NANO 33 BLE SENSe min 0 max 80 //NICLA_VISION min 0 max 8 - void setGain(int gain); + void setGain(int8_t gain_left, int8_t gain_right); void setPins(int dinPin, int clkPin); int setChannels(int channels) override; @@ -71,7 +72,8 @@ class PDM_Mic : public InputDevice { int _channels = 1; int _sampleRate = 16000; - int _gain = 60; + int8_t _gain_l = DEFAULT_PDM_GAIN; + int8_t _gain_r = DEFAULT_PDM_GAIN; bool _first = true; diff --git a/src/audio_pdm/Recorder.cpp b/src/audio_pdm/Recorder.cpp index ef4201a..8469e72 100644 --- a/src/audio_pdm/Recorder.cpp +++ b/src/audio_pdm/Recorder.cpp @@ -1,5 +1,6 @@ #include "Recorder.h" #include "WavRecorder.h" +#include "PDM_Mic.h" uint8_t PDM_BUFFER[pdm_b_size * pdm_b_count] __attribute__((aligned (16))); @@ -77,6 +78,8 @@ void Recorder::print_info() { Serial.println("SET"); if (device->available()) { Serial.println("device: available"); + Serial.print("device channels: "); + Serial.println(device->getChannels()); Serial.print("device samplerate: "); Serial.println(device->getSampleRate()); } else Serial.println("device: not available"); @@ -118,6 +121,7 @@ void Recorder::setTarget(AudioTarget * target) { this->target = target; if (!target) return; target->setSampleRate(_sampleRate); + target->setChannels(_channels); if (device) this->target->setStream(&(device->stream)); } @@ -128,19 +132,25 @@ void Recorder::config_callback(SensorConfigurationPacket *config) { // Get sample rate int sample_rate = int(config->sampleRate); - // End sensor if sample rate is 0 - if (sample_rate == 0) { - recorder.stop(); + // Make sure that pdm mic is not running + recorder.stop(); + + // only end recording if sample rate is 0 or both mics are turned off + if (sample_rate == 0 || (config->latency & 0xFFFF) == 0xFFFF) { return; } // Check for valid sample rate recorder.setSampleRate(sample_rate); - recorder.setChannels(2); + int8_t gain_l = config->latency & 0xFF; + int8_t gain_r = (config->latency >> 8) & 0xFF; - // Make sure that pdm mic is not running already! - recorder.stop(); + // number of channels + recorder.setChannels((gain_l >= 0) + (gain_r >= 0)); + + // set gain for each channel + pdm_mic.setGain(gain_l, gain_r); // find the next available file name for the recording const String recording_dir = "Recordings"; From 9af5004a1199d7ff4a46197d99e82b379ce686a3 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 14 Aug 2024 12:48:36 +0100 Subject: [PATCH 53/68] Reduced overhead when baro and imu are not being sampled --- src/task_manager/TaskManager.cpp | 16 ++++++++++------ src/task_manager/TaskManager.h | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/task_manager/TaskManager.cpp b/src/task_manager/TaskManager.cpp index 8a80d74..ee0e62d 100644 --- a/src/task_manager/TaskManager.cpp +++ b/src/task_manager/TaskManager.cpp @@ -72,13 +72,17 @@ void TaskManager::update() { void TaskManager::update_edge_ml() { unsigned int now = millis(); - if (now - _baro_last >= _baro_delay) { - sensorProvider.update_sensor(BARO_TEMP, true); - _baro_last = now; + if (_baro_delay > 0){ + if (now - _baro_last >= _baro_delay) { + sensorProvider.update_sensor(BARO_TEMP, true); + _baro_last = now; + } } - if (now - _imu_last >= _imu_delay) { - sensorProvider.update_sensor(ACC_GYRO_MAG, true); - _imu_last = now; + if (_imu_delay > 0) { + if (now - _imu_last >= _imu_delay) { + sensorProvider.update_sensor(ACC_GYRO_MAG, true); + _imu_last = now; + } } if (now - _edge_ml_last >= _edge_ml_delay) { bleHandler_G.update(); diff --git a/src/task_manager/TaskManager.h b/src/task_manager/TaskManager.h index c9e0393..345704e 100644 --- a/src/task_manager/TaskManager.h +++ b/src/task_manager/TaskManager.h @@ -13,7 +13,7 @@ class TaskManager { private: int _current_conf_num; - const int _default_loop_delay = 50; + const int _default_loop_delay = -1; int _baro_delay = _default_loop_delay; int _imu_delay = _default_loop_delay; From e3a4c934c0ffede7fc4f2f44044ef6086c261fa1 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 14 Aug 2024 12:57:00 +0100 Subject: [PATCH 54/68] Change default loop timing for edgeml --- src/task_manager/TaskManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/task_manager/TaskManager.h b/src/task_manager/TaskManager.h index 345704e..3740e0d 100644 --- a/src/task_manager/TaskManager.h +++ b/src/task_manager/TaskManager.h @@ -19,7 +19,7 @@ class TaskManager { //float _rate_factor = 1.25; - int _edge_ml_delay = 100; + int _edge_ml_delay = 20; unsigned int _edge_ml_last; unsigned int _baro_last; unsigned int _imu_last; From 056b0bb607ae4ace3c01eface81fefb4749cb3ab Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 14 Aug 2024 13:12:14 +0100 Subject: [PATCH 55/68] Removed LED status for recording --- src/OpenEarable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index 4c20bcf..67a28b8 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -191,7 +191,7 @@ void OpenEarable::config_callback(SensorConfigurationPacket *config) { i2s_player.start(); } } - update_current_led_status(config); + // update_current_led_status(config); //else task_manager.begin(); } From d3dac8ae760f97e91cd59ac6f83e566cba5ee5cb Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Wed, 14 Aug 2024 13:41:18 +0100 Subject: [PATCH 56/68] Revert "Removed LED status for recording" This reverts commit 056b0bb607ae4ace3c01eface81fefb4749cb3ab. --- src/OpenEarable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index 67a28b8..4c20bcf 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -191,7 +191,7 @@ void OpenEarable::config_callback(SensorConfigurationPacket *config) { i2s_player.start(); } } - // update_current_led_status(config); + update_current_led_status(config); //else task_manager.begin(); } From 3b8e9c843994b03e2c1653ab4a1cd3759058dfbf Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Mon, 19 Aug 2024 10:41:32 +0100 Subject: [PATCH 57/68] Swapped gains for inner/outer mic --- src/audio_pdm/Recorder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/audio_pdm/Recorder.cpp b/src/audio_pdm/Recorder.cpp index 8469e72..97c5c85 100644 --- a/src/audio_pdm/Recorder.cpp +++ b/src/audio_pdm/Recorder.cpp @@ -143,8 +143,8 @@ void Recorder::config_callback(SensorConfigurationPacket *config) { // Check for valid sample rate recorder.setSampleRate(sample_rate); - int8_t gain_l = config->latency & 0xFF; - int8_t gain_r = (config->latency >> 8) & 0xFF; + int8_t gain_r = config->latency & 0xFF; + int8_t gain_l = (config->latency >> 8) & 0xFF; // number of channels recorder.setChannels((gain_l >= 0) + (gain_r >= 0)); From 972e5671bcdc339ed6a4ad0f1facbbc67db4a54c Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Tue, 3 Sep 2024 14:25:15 +0100 Subject: [PATCH 58/68] Fixed wrong header for gyro data --- src/sd_logger/IMU_Logger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sd_logger/IMU_Logger.cpp b/src/sd_logger/IMU_Logger.cpp index df30004..27350b3 100644 --- a/src/sd_logger/IMU_Logger.cpp +++ b/src/sd_logger/IMU_Logger.cpp @@ -80,7 +80,7 @@ void IMULogger::dump_to_sd() { void IMULogger::write_header() { _index = 0; - String header = "timestamp,acc_x,acc_y,acc_z,acc_x,gyro_y,gyro_z,magn_x,magn_y,magn_z\n\r"; + String header = "timestamp,acc_x,acc_y,acc_z,gyro_x,gyro_y,gyro_z,magn_x,magn_y,magn_z\n\r"; header.toCharArray(&(_buffer[_index]), header.length()); _index += header.length() - 1; // -1 to remove null terminator dump_to_sd(); From f0b13eb1bb2903a52acb38e359d351ae4d5a3848 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Tue, 24 Sep 2024 19:50:43 +0100 Subject: [PATCH 59/68] Added occlusion test --- src/OpenEarable.h | 6 +- src/audio_pdm/BLEStream.cpp | 121 ++++++++++++++++++++++ src/audio_pdm/BLEStream.h | 36 +++++++ src/audio_pdm/PDM_Mic.cpp | 12 ++- src/audio_pdm/Recorder.cpp | 59 ++++++----- src/audio_pdm/WavRecorder.h | 6 +- src/audio_play/SOSFilter.cpp | 41 ++++++++ src/audio_play/SOSFilter.h | 27 +++++ src/custom_sensor/PDM_Sensor.cpp | 37 +++++++ src/custom_sensor/PDM_Sensor.h | 33 ++++++ src/custom_sensor/SensorID_Earable.h | 45 +++++++- src/custom_sensor/SensorManager_Earable.h | 7 +- 12 files changed, 385 insertions(+), 45 deletions(-) create mode 100644 src/audio_pdm/BLEStream.cpp create mode 100644 src/audio_pdm/BLEStream.h create mode 100644 src/audio_play/SOSFilter.cpp create mode 100644 src/audio_play/SOSFilter.h create mode 100644 src/custom_sensor/PDM_Sensor.cpp create mode 100644 src/custom_sensor/PDM_Sensor.h diff --git a/src/OpenEarable.h b/src/OpenEarable.h index 4c20bcf..830ebf4 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -31,7 +31,7 @@ #include String device_name; -const String firmware_version = "1.4.1"; +const String firmware_version = "1.5.0"; const String hardware_version = "1.4.0"; bool _data_logger_flag = true; @@ -92,6 +92,7 @@ class OpenEarable { task_manager.begin(); + BLE.setConnectionInterval(0x0006, 0x000C); BLE.advertise(); }; @@ -99,9 +100,6 @@ class OpenEarable { _battery->update(); task_manager.update(); - - //interrupt based - //earable_btn.update(); }; void debug(Stream &stream) { diff --git a/src/audio_pdm/BLEStream.cpp b/src/audio_pdm/BLEStream.cpp new file mode 100644 index 0000000..e5d119f --- /dev/null +++ b/src/audio_pdm/BLEStream.cpp @@ -0,0 +1,121 @@ +#include "BLEStream.h" +#include "EdgeML.h" +#include "../custom_sensor/PDM_Sensor.h" +#include "Recorder.h" // for debugging only + +#define FILT_ORDER 2 + +const float a[FILT_ORDER][3] = {{1, -1.36511724, 0.47759225}, + {1, -1.6117271 , 0.74452084}}; +const float b[FILT_ORDER][3] = {{9.33498613e-04, 1.86699723e-03, 9.33498613e-04}, + {1, 2, 1}}; + +int16_t ble_buffer[AUDIO_STREAM_PACKAGE_SIZE]; +int16_t sos_buffer[pdm_b_size / sizeof(int16_t)]; +int index_ble = 0; +//const int down_sample = 32; +const int down_sample = 8; + +BLEStream::BLEStream() { + filter = new SOSFilter(FILT_ORDER, b, a); +} + +BLEStream::~BLEStream() { + delete filter; +} + +bool BLEStream::begin() { + (*stream)->open(); + + //_wavWriter->setSampleRate(_sampleRate); + //_wavWriter->setChannels(_channels); + //const bool writer_begin = _wavWriter->begin(); + //if (writer_begin) start(); + //return writer_begin; + + start(); + return true; +} + +void BLEStream::setSampleRate(int sampleRate) { + _sampleRate = sampleRate; +} + +void BLEStream::setChannels(int channels) { + _channels = channels; +} + +bool BLEStream::available() { + return _stream; +} + +void BLEStream::end() { + if (_stream) stop(); + + (*stream)->close(); +} + +void BLEStream::setStream(BufferedStream ** stream) { + if (_stream) end(); + this->stream = stream; +} + +int BLEStream::provide(int max_cont) { + if (!_stream) return 0; + + int cont = min((*stream)->get_contiguous_blocks(), max_cont); + + if (!cont) return 0; + + if (initial_drop > 0) { + const int n = min(initial_drop, cont); + (*stream)->provide(n); + initial_drop -= n; + cont -= n; + + if (!cont) return n; + } + + uint8_t *read_pointer = (*stream)->buffer.getReadPointer(); + const int block_size = (*stream)->buffer.getBlockSize(); + + for (int i = 0; iupdate((int16_t *) sos_buffer, block_size / sizeof(int16_t)); + for (int k = 0; k < block_size / sizeof(int16_t); k+=down_sample) { + ble_buffer[index_ble++] = sos_buffer[k]; + if (index_ble == AUDIO_STREAM_PACKAGE_SIZE) { + index_ble = 0; + + sensorProvider.update_manager(); + pdm_sensor.setBuffer((uint8_t*) ble_buffer); + sensorProvider.update_sensor(PDM_MIC, true); + bleHandler_G.update(); + + delay(8); + } + } + } + + // Serial.print("PDM: "); + // Serial.println(recorder.available() ? (*recorder.target->stream)->remaining() : -1); + + (*stream)->provide(cont); + + return cont; +} + +void BLEStream::start() { + if (_stream) return; + + filter->reset(); + index_ble = 0; + + _stream = true; +} + +void BLEStream::stop() { + if (!_stream) return; + + _stream = false; +} \ No newline at end of file diff --git a/src/audio_pdm/BLEStream.h b/src/audio_pdm/BLEStream.h new file mode 100644 index 0000000..786fcd0 --- /dev/null +++ b/src/audio_pdm/BLEStream.h @@ -0,0 +1,36 @@ +#ifndef BLE_STREAM_SENSOR_H +#define BLE_STREAM_SENSOR_H + +#include "EdgeML_Custom.h" +#include "AudioTarget.h" +#include +#include "../audio_play/SOSFilter.h" + +class BLEStream : public AudioTarget { +public: + BLEStream(); + ~BLEStream(); + + int provide(int n) override; + bool available() override; + bool begin() override; + void end() override; + void setStream(BufferedStream ** stream) override; + + void start(); + void stop(); + + void setSampleRate(int sampleRate) override; + void setChannels(int channels) override; +private: + bool _stream = false; + + int initial_drop = 1; + + int _sampleRate = 0; + int _channels = 1; + + SOSFilter * filter; +}; + +#endif //OPEN_EARABLE_PDM_MIC_SENSOR_H diff --git a/src/audio_pdm/PDM_Mic.cpp b/src/audio_pdm/PDM_Mic.cpp index 78ceace..e41ed6a 100644 --- a/src/audio_pdm/PDM_Mic.cpp +++ b/src/audio_pdm/PDM_Mic.cpp @@ -207,9 +207,15 @@ void PDM_Mic::setGain(int8_t gain_left, int8_t gain_right) { _gain_l = gain_left; _gain_r = gain_right; - //setChannels((_gain_l >= 0) + (_gain_r >= 0)); - - //if (_available) nrf_pdm_gain_set(constrain(_gain_l, 0x00, 0x50), constrain(_gain_r, 0x00, 0x50)); + if (_available) { + if (_channels == 1 && _gain_l < 0) { + // right mic active (right and left gain need to be swapped) + nrf_pdm_gain_set(constrain(_gain_r, 0x00, 0x50), constrain(_gain_l, 0x00, 0x50)); + } else { + // left mic + nrf_pdm_gain_set(constrain(_gain_l, 0x00, 0x50), constrain(_gain_r, 0x00, 0x50)); + } + } } int PDM_Mic::getSampleRate() { diff --git a/src/audio_pdm/Recorder.cpp b/src/audio_pdm/Recorder.cpp index 97c5c85..1bf2449 100644 --- a/src/audio_pdm/Recorder.cpp +++ b/src/audio_pdm/Recorder.cpp @@ -1,5 +1,6 @@ #include "Recorder.h" #include "WavRecorder.h" +#include "BLEStream.h" #include "PDM_Mic.h" uint8_t PDM_BUFFER[pdm_b_size * pdm_b_count] __attribute__((aligned (16))); @@ -152,43 +153,49 @@ void Recorder::config_callback(SensorConfigurationPacket *config) { // set gain for each channel pdm_mic.setGain(gain_l, gain_r); - // find the next available file name for the recording - const String recording_dir = "Recordings"; + if (((config->latency >> 16) & 0xFF) == 1) { + // ocllusion test + recorder.setTarget(new BLEStream()); + } else { - if (!sd_manager.exists(recording_dir)) sd_manager.mkdir(recording_dir); + // find the next available file name for the recording + const String recording_dir = "Recordings"; - ExFile file; - ExFile dir = sd_manager.sd->open(recording_dir); + if (!sd_manager.exists(recording_dir)) sd_manager.mkdir(recording_dir); - char fileName[64]; - char * split; + ExFile file; + ExFile dir = sd_manager.sd->open(recording_dir); - int n = 1; + char fileName[64]; + char * split; - // find highest Recording number - while (file = dir.openNextFile()) { - file.getName(fileName, sizeof(fileName)); + int n = 1; - split = strtok(fileName, "_"); - if (strcmp(split,"Recording") == 0) { - split = strtok(NULL, "_"); - n = max(n, atoi(split) + 1); + // find highest Recording number + while (file = dir.openNextFile()) { + file.getName(fileName, sizeof(fileName)); + + split = strtok(fileName, "_"); + if (strcmp(split,"Recording") == 0) { + split = strtok(NULL, "_"); + n = max(n, atoi(split) + 1); + } } - } - // file name of the new recording - String file_name = "/" + recording_dir + "/Recording_" + String(n) + "_" + String(millis()) + ".wav"; + // file name of the new recording + String file_name = "/" + recording_dir + "/Recording_" + String(n) + "_" + String(millis()) + ".wav"; - if (_rec_debug) { - _rec_debug->println("Recording:"); - _rec_debug->println(file_name); - } + if (_rec_debug) { + _rec_debug->println("Recording:"); + _rec_debug->println(file_name); + } - // set WaveRecorder - recorder.setTarget(new WavRecorder(file_name)); + // set WaveRecorder + recorder.setTarget(new WavRecorder(file_name)); - // Start pdm mic - recorder.record(); + // Start pdm mic + recorder.record(); + } } Recorder recorder; \ No newline at end of file diff --git a/src/audio_pdm/WavRecorder.h b/src/audio_pdm/WavRecorder.h index 8615d2d..f9fd880 100644 --- a/src/audio_pdm/WavRecorder.h +++ b/src/audio_pdm/WavRecorder.h @@ -22,11 +22,7 @@ class WavRecorder : public AudioTarget { void stop(); void setSampleRate(int sampleRate) override; - void setGain(int gain); - void setChannels(int channels); - - void enable_serial_data(); - void disable_serial_data(); + void setChannels(int channels) override; String get_name(); private: diff --git a/src/audio_play/SOSFilter.cpp b/src/audio_play/SOSFilter.cpp new file mode 100644 index 0000000..cebcd2c --- /dev/null +++ b/src/audio_play/SOSFilter.cpp @@ -0,0 +1,41 @@ +#include "SOSFilter.h" + +#include + +SOSFilter::SOSFilter(int order, const float (*b)[3], const float (*a)[3]) { + this->order = order; + this->b = b; + this->a = a; + + //buffer.resize(order, std::vector(2, 0.0f)); + buffer = new float*[order]; + for (int i = 0; i < order; ++i) { + buffer[i] = new float[2]{0.0f, 0.0f}; // Speicher für 2 Verzögerungen pro Sektion + } +} + +SOSFilter::~SOSFilter() { + //reset(); +} + +void SOSFilter::reset() { + for(int i = 0; i < order; i++) { + //std::memset(buffer[i].data(), 0, 2 * sizeof(float)); + std::memset(buffer[i], 0, 2 * sizeof(float)); + } +} + +void SOSFilter::update(int16_t * data, int length) { + float y[order+1] = {0}; + for (int n = 0; n < length; n++) { + y[0] = data[n]; + + for (int k = 0; k < order; k++) { + y[k+1] = b[k][0] * y[k] + buffer[k][0]; + buffer[k][0] = b[k][1] * y[k] - a[k][1] * y[k+1] + buffer[k][1]; + buffer[k][1] = b[k][2] * y[k] - a[k][2] * y[k+1]; + } + + data[n] = constrain(y[order],-1*(1<<15),(1<<15)-1); + } +} \ No newline at end of file diff --git a/src/audio_play/SOSFilter.h b/src/audio_play/SOSFilter.h new file mode 100644 index 0000000..62e5ca3 --- /dev/null +++ b/src/audio_play/SOSFilter.h @@ -0,0 +1,27 @@ +#ifndef OPEN_EARABLE_SOS_H +#define OPEN_EARABLE_SOS_H + +#include "Arduino.h" +#include + +#define SOS_ORDER 3 + +/** + * Directorform II Transposed + */ +class SOSFilter { +public: + SOSFilter(int order, const float (*b)[3], const float (*a)[3]); + ~SOSFilter(); + + void reset(); + void update(int16_t * data, int length); +private: + int order; + const float (*b)[3]; + const float (*a)[3]; + //std::vector> buffer; + float **buffer; +}; + +#endif //OPEN_EARABLE_AUDIO_PLAYER_H diff --git a/src/custom_sensor/PDM_Sensor.cpp b/src/custom_sensor/PDM_Sensor.cpp new file mode 100644 index 0000000..07e6821 --- /dev/null +++ b/src/custom_sensor/PDM_Sensor.cpp @@ -0,0 +1,37 @@ +#include "PDM_Sensor.h" +//#include "../audio_pdm/BLEStream.h" + +PDM_Sensor::PDM_Sensor() { + +} + +void PDM_Sensor::start() { + if (available) return; + + available = true; +} + +void PDM_Sensor::end() { + if (!available) return; + + available = false; +} + +void PDM_Sensor::get_data(int sensorID, byte *data) { + if (sensorID != PDM_MIC) { + memset(data, 0, sizeof(int16_t) * AUDIO_STREAM_PACKAGE_SIZE); /////?????? + return; + } + + memcpy(data, _buffer, sizeof(int16_t) * AUDIO_STREAM_PACKAGE_SIZE); +} + +void PDM_Sensor::setBuffer(uint8_t * buffer) { + _buffer = buffer; +} + +int PDM_Sensor::get_sensor_count() { + return sensor_count; +} + +PDM_Sensor pdm_sensor; \ No newline at end of file diff --git a/src/custom_sensor/PDM_Sensor.h b/src/custom_sensor/PDM_Sensor.h new file mode 100644 index 0000000..7afad8a --- /dev/null +++ b/src/custom_sensor/PDM_Sensor.h @@ -0,0 +1,33 @@ +#ifndef EDGE_ML_EARABLE_PDM_SENSOR_H +#define EDGE_ML_EARABLE_PDM_SENSOR_H + +#include "EdgeML_Custom.h" +#include "SensorID_Earable.h" + +class PDM_Sensor : public SensorInterface { +public: + PDM_Sensor(); + + void start() override; + void end() override; + + void setBuffer(uint8_t * buffer); + void get_data(int ID, byte * data) override; + + int get_sensor_count() override; + + static const int sensor_count = 1; +private: + bool available = false; + + uint8_t * _buffer; + + //PDM_MIC + + //int16_t data[16]; +}; + +extern PDM_Sensor pdm_sensor; + + +#endif //EDGE_ML_EARABLE_IMU_SENSOR_H diff --git a/src/custom_sensor/SensorID_Earable.h b/src/custom_sensor/SensorID_Earable.h index 6d09d4f..7412029 100644 --- a/src/custom_sensor/SensorID_Earable.h +++ b/src/custom_sensor/SensorID_Earable.h @@ -3,6 +3,8 @@ #include "EdgeML_Custom.h" +#define AUDIO_STREAM_PACKAGE_SIZE 16 + const int SENSOR_COUNT = 3; const int MODULE_COUNT_PHYSICAL = 3; const int SPECIAL_SENSOR_COUNT = 1; @@ -22,7 +24,8 @@ const int SpecialSensors[SPECIAL_SENSOR_COUNT] = { enum ModuleID { MODULE_IMU, MODULE_BARO, - MODULE_DUMMY + MODULE_PDM, + //MODULE_DUMMY }; const SensorComponent ACC_COMPONENTS[] = { @@ -42,6 +45,40 @@ const SensorComponent PRESSURE_TEMP_COMPONENTS[] = { {"BARO", PARSE_TYPE_FLOAT, "Pressure", "kPa"} }; +const SensorComponent PDM_MIC_COMPONENTS[] = { + {"MIC", PARSE_TYPE_INT16, "0", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "1", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "2", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "3", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "4", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "5", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "6", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "7", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "8", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "9", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "10", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "11", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "12", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "13", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "14", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "15", "AMP"}, + /*{"MIC", PARSE_TYPE_INT16, "16", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "17", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "18", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "19", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "20", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "21", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "22", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "23", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "24", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "25", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "26", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "27", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "28", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "29", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "30", "AMP"}, + {"MIC", PARSE_TYPE_INT16, "31", "AMP"},*/ +}; const SensorConfig CONFIG[SENSOR_COUNT] = { { @@ -61,9 +98,9 @@ const SensorConfig CONFIG[SENSOR_COUNT] = { { "PDM MIC", PDM_MIC, - MODULE_DUMMY, - 0, - {} + MODULE_PDM, //MODULE_DUMMY, + AUDIO_STREAM_PACKAGE_SIZE, + PDM_MIC_COMPONENTS }, }; diff --git a/src/custom_sensor/SensorManager_Earable.h b/src/custom_sensor/SensorManager_Earable.h index 854b379..5c77200 100644 --- a/src/custom_sensor/SensorManager_Earable.h +++ b/src/custom_sensor/SensorManager_Earable.h @@ -4,19 +4,20 @@ #include "SensorID_Earable.h" #include "IMU_Sensor.h" #include "BARO_Sensor.h" +#include "PDM_Sensor.h" class SensorManager_Earable : public SensorManagerInterface { public: void setup() override { IMU_Sensor * imu = new IMU_Sensor(); BARO_Sensor * baro = new BARO_Sensor(); - DummySensor * dummy = new DummySensor(); + // DummySensor * dummy = new DummySensor(); - SensorInterface ** modules = new SensorInterface * [MODULE_COUNT_PHYSICAL] {imu, baro, dummy}; + SensorInterface ** modules = new SensorInterface * [MODULE_COUNT_PHYSICAL] {imu, baro, &pdm_sensor}; SensorManagerInterface::set_modules(modules); SensorManagerInterface::set_sensor_counts(SENSOR_COUNT, MODULE_COUNT_PHYSICAL); - SensorManagerInterface::set_special_sensors(SpecialSensors, SPECIAL_SENSOR_COUNT); + //SensorManagerInterface::set_special_sensors(SpecialSensors, SPECIAL_SENSOR_COUNT); SensorManagerInterface::set_sensor_configs(CONFIG); } From 1f4e3794fe1de444756f6e53289ddf20eed03320 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Tue, 24 Sep 2024 20:49:57 +0100 Subject: [PATCH 60/68] Added BLEDevice header --- src/OpenEarable.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index 830ebf4..be25655 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -5,6 +5,8 @@ #ifndef EDGE_ML_EARABLE_EDGEML_EARABLE_H #define EDGE_ML_EARABLE_EDGEML_EARABLE_H +#include + #include "EdgeML.h" #include #include "button_service/Button.h" From 8cbd10e02f9244a75c8b1c4cf79f9d3c8feb3a70 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Fri, 27 Sep 2024 16:42:19 +0100 Subject: [PATCH 61/68] improve dynamic memory efficiency --- src/audio_pdm/BLEStream.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/audio_pdm/BLEStream.cpp b/src/audio_pdm/BLEStream.cpp index e5d119f..5e89b03 100644 --- a/src/audio_pdm/BLEStream.cpp +++ b/src/audio_pdm/BLEStream.cpp @@ -10,11 +10,11 @@ const float a[FILT_ORDER][3] = {{1, -1.36511724, 0.47759225}, const float b[FILT_ORDER][3] = {{9.33498613e-04, 1.86699723e-03, 9.33498613e-04}, {1, 2, 1}}; + +const int down_sample = 8; int16_t ble_buffer[AUDIO_STREAM_PACKAGE_SIZE]; -int16_t sos_buffer[pdm_b_size / sizeof(int16_t)]; +int16_t sos_buffer[down_sample]; int index_ble = 0; -//const int down_sample = 32; -const int down_sample = 8; BLEStream::BLEStream() { filter = new SOSFilter(FILT_ORDER, b, a); @@ -26,12 +26,6 @@ BLEStream::~BLEStream() { bool BLEStream::begin() { (*stream)->open(); - - //_wavWriter->setSampleRate(_sampleRate); - //_wavWriter->setChannels(_channels); - //const bool writer_begin = _wavWriter->begin(); - //if (writer_begin) start(); - //return writer_begin; start(); return true; @@ -80,10 +74,10 @@ int BLEStream::provide(int max_cont) { const int block_size = (*stream)->buffer.getBlockSize(); for (int i = 0; iupdate((int16_t *) sos_buffer, block_size / sizeof(int16_t)); - for (int k = 0; k < block_size / sizeof(int16_t); k+=down_sample) { - ble_buffer[index_ble++] = sos_buffer[k]; + for (int k = 0; k < block_size; k+=down_sample * sizeof(int16_t)) { + memcpy(sos_buffer, read_pointer + i * block_size + k, down_sample * sizeof(int16_t)); + filter->update((int16_t *) sos_buffer, down_sample); + ble_buffer[index_ble++] = sos_buffer[0]; if (index_ble == AUDIO_STREAM_PACKAGE_SIZE) { index_ble = 0; From ee8e4838f6f6433268232cc945437205b482956a Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Mon, 30 Sep 2024 14:21:17 +0100 Subject: [PATCH 62/68] Reduced Recorder buffer size to improve dynamic memory allocation --- src/audio_pdm/Recorder.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/audio_pdm/Recorder.h b/src/audio_pdm/Recorder.h index aa2f149..1202dbb 100644 --- a/src/audio_pdm/Recorder.h +++ b/src/audio_pdm/Recorder.h @@ -11,7 +11,7 @@ #include "utils/BufferedInputStream.h" #include "InputDevice.h" -const int pdm_b_size = 6144; //4096; +const int pdm_b_size = 4096; //4096; const int pdm_b_count = 8; extern uint8_t PDM_BUFFER[pdm_b_size * pdm_b_count] __attribute__((aligned (16))); From 534fcbd4fc1e7906d9a159eb026f2975357175f9 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Mon, 30 Sep 2024 17:55:41 +0100 Subject: [PATCH 63/68] Fixed starting of recorder. Reverted firmware version for compatibility issue. --- src/OpenEarable.h | 2 +- src/audio_pdm/Recorder.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index be25655..e1c2c2f 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -33,7 +33,7 @@ #include String device_name; -const String firmware_version = "1.5.0"; +const String firmware_version = "1.4.0"; const String hardware_version = "1.4.0"; bool _data_logger_flag = true; diff --git a/src/audio_pdm/Recorder.cpp b/src/audio_pdm/Recorder.cpp index 1bf2449..ecbfa1d 100644 --- a/src/audio_pdm/Recorder.cpp +++ b/src/audio_pdm/Recorder.cpp @@ -193,9 +193,9 @@ void Recorder::config_callback(SensorConfigurationPacket *config) { // set WaveRecorder recorder.setTarget(new WavRecorder(file_name)); - // Start pdm mic - recorder.record(); } + // Start pdm mic + recorder.record(); } Recorder recorder; \ No newline at end of file From 95c09bca57c319ce1dd1b0ba7bd767cbdbcfb44d Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Thu, 24 Oct 2024 15:21:31 +0100 Subject: [PATCH 64/68] Fixed incorrect sampling rate for some PDM values --- src/audio_pdm/PDM_Mic.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/audio_pdm/PDM_Mic.cpp b/src/audio_pdm/PDM_Mic.cpp index e41ed6a..fe46fe9 100644 --- a/src/audio_pdm/PDM_Mic.cpp +++ b/src/audio_pdm/PDM_Mic.cpp @@ -47,6 +47,7 @@ bool PDM_Mic::begin() { break; case 20000: // Untested + NRF_PDM->RATIO = ((PDM_RATIO_RATIO_Ratio64 << PDM_RATIO_RATIO_Pos) & PDM_RATIO_RATIO_Msk); nrf_pdm_clock_set(NRF_PDM_FREQ_1280K); break; case 25000: @@ -56,6 +57,7 @@ bool PDM_Mic::begin() { break; case 31250: // Untested + NRF_PDM->RATIO = ((PDM_RATIO_RATIO_Ratio64 << PDM_RATIO_RATIO_Pos) & PDM_RATIO_RATIO_Msk); nrf_pdm_clock_set(NRF_PDM_FREQ_2000K); break; case 33333: @@ -69,6 +71,7 @@ bool PDM_Mic::begin() { nrf_pdm_clock_set(NRF_PDM_FREQ_3200K); break; case 41667: + NRF_PDM->RATIO = ((PDM_RATIO_RATIO_Ratio64 << PDM_RATIO_RATIO_Pos) & PDM_RATIO_RATIO_Msk); nrf_pdm_clock_set(NRF_PDM_FREQ_2667K); break; case 50000: @@ -84,6 +87,7 @@ bool PDM_Mic::begin() { break; case 62500: // Untested + NRF_PDM->RATIO = ((PDM_RATIO_RATIO_Ratio64 << PDM_RATIO_RATIO_Pos) & PDM_RATIO_RATIO_Msk); nrf_pdm_clock_set(NRF_PDM_FREQ_4000K); break; default: From 7b4a915f2e1fe75adcb5c06393e49039b764b4d0 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Sun, 27 Oct 2024 17:06:17 +0000 Subject: [PATCH 65/68] Fixed conflict on main library --- src/OpenEarable.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/OpenEarable.h b/src/OpenEarable.h index c97075e..e1c2c2f 100644 --- a/src/OpenEarable.h +++ b/src/OpenEarable.h @@ -6,10 +6,6 @@ #define EDGE_ML_EARABLE_EDGEML_EARABLE_H #include -<<<<<<< HEAD -======= -//#include ->>>>>>> 5a63f42c29641b46282ff7efb579fc1110031275 #include "EdgeML.h" #include From 6b2ddd0e236c371fe39891c967f517b3c1cee5a7 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Mon, 28 Oct 2024 15:52:58 +0000 Subject: [PATCH 66/68] Fixed left/right gain to reflect inner/outer gains in dashboard --- src/audio_pdm/Recorder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/audio_pdm/Recorder.cpp b/src/audio_pdm/Recorder.cpp index 4aa7570..a7d650e 100644 --- a/src/audio_pdm/Recorder.cpp +++ b/src/audio_pdm/Recorder.cpp @@ -144,8 +144,8 @@ void Recorder::config_callback(SensorConfigurationPacket *config) { // Check for valid sample rate recorder.setSampleRate(sample_rate); - int8_t gain_l = config->latency & 0xFF; - int8_t gain_r = (config->latency >> 8) & 0xFF; + int8_t gain_r = config->latency & 0xFF; + int8_t gain_l = (config->latency >> 8) & 0xFF; // number of channels recorder.setChannels((gain_l >= 0) + (gain_r >= 0)); From e03bc55bf3c0f38afde55d7031aacb961910e852 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Fri, 1 Nov 2024 14:57:17 +0000 Subject: [PATCH 67/68] Reverted to default name for sensor --- examples/App/App.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/App/App.ino b/examples/App/App.ino index cb02bc7..744696c 100644 --- a/examples/App/App.ino +++ b/examples/App/App.ino @@ -15,7 +15,7 @@ #define DEBUG true // Change name to OELeft or OERight before flashing ("OpenEarable" if left as default value) -String d_name = "OERight"; +String d_name = "OpenEarable"; void setup() { From cec32a2a80c9d344ae67fd4005b0a95d0f6e97c5 Mon Sep 17 00:00:00 2001 From: Mathias Ciliberto Date: Fri, 1 Nov 2024 14:59:22 +0000 Subject: [PATCH 68/68] Removed .vscode from tracked files due to PlatformIO deployment --- .gitignore | 1 + .vscode/arduino.json | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 .vscode/arduino.json diff --git a/.gitignore b/.gitignore index 3588f6d..679ac69 100644 --- a/.gitignore +++ b/.gitignore @@ -39,5 +39,6 @@ src/main.cpp # VS Code +**/.vscode **/.vscode/c_cpp_properties.json **/.vscode/settings.json \ No newline at end of file diff --git a/.vscode/arduino.json b/.vscode/arduino.json deleted file mode 100644 index 90d37d3..0000000 --- a/.vscode/arduino.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "board": "arduino:openearable:nano33ble", - "sketch": "examples/App/App.ino", - "port": "/dev/tty.usbmodem11201" -} \ No newline at end of file