Skip to content

Conversation

jaketheduque
Copy link

@jaketheduque jaketheduque commented Aug 10, 2025

Description

The Brainflow SpO2 algorithm has been added into the base EmotiBit firmware.

Requirements

Notes for Reviewer

  • Added new function processSpO2 that calculates SpO2 from PPG data buffers and sends an SpO2 data packet
  • Added spo2 flag to acquireData that can enable/disable SpO2 calculation
  • Added new partition table under EmotiBit_stock_firmware for PlatformIO
  • Added removeBindingCPP.py under pio_scripts so that binding.cpp is not compiled during PlatformIO build
  • Add EmotiBit Brainflow SpO2 Algorithm to library.properties

Checklist to allow merge

  • All dependent repositories used were on branch master
  • Software
    • Get approval from the reviewer
    • Passed testing on Windows
    • Passed testing on macOS (for major changes/GUI changes/ PRs adding files distributed with the EmotiBit software)
    • Passed testing on linux (ubuntu) (for major changes/GUI changes/ PRs adding files distributed with the EmotiBit software)
    • Update software bundle version in ofxEmotiBitVersion.h
  • Firmware
    • Set testingMode to TestingMode::NONE
    • Set const bool DIGITAL_WRITE_DEBUG = false (if set true while testing)
    • Update version in EmotiBit.h
    • Update library.properties to the correct version (should match EmotiBit.h)
  • doxygen style comments included for new code snippets
  • Required documentation updated

Screenshots:

Summary by CodeRabbit

  • New Features

    • Added SpO2 measurement using PPG signals, producing a new SpO2 data stream alongside existing sensors (configurable in acquisition settings).
  • Bug Fixes

    • Corrected a debug message to show accurate information.
  • Chores

    • Added SpO2 algorithm dependency.
    • Updated build configuration (partitions, script to skip unused bindings) and minor include/order cleanups.
    • Updated firmware identifier to reflect the new capability.

@jaketheduque
Copy link
Author

@coderabbitai perform a code review and suggest any other details that should be added to the PR

Copy link

coderabbitai bot commented Aug 12, 2025

🧩 Analysis chain

I'll perform a comprehensive code review of this SpO2 feature addition. Let me first examine the code changes and key files to provide thorough feedback.


🏁 Script executed:

#!/bin/bash
# Get the PR diff to understand what files were changed
git diff --name-only HEAD~1 HEAD

# Show the actual changes in the diff
git diff HEAD~1 HEAD --stat

# Look for key files mentioned in the PR description
fd -t f "EmotiBit.h"
fd -t f "library.properties"
fd -t f "partition"
fd -t f "removeBindingCPP.py"

Length of output: 639


🏁 Script executed:

#!/bin/bash
# Since we can't get the diff directly, let's examine the key files mentioned in the PR
echo "=== EmotiBit.h ==="
cat EmotiBit.h | head -100

echo -e "\n=== library.properties ==="
cat library.properties

echo -e "\n=== partitions.csv ==="
cat EmotiBit_stock_firmware/partitions.csv

echo -e "\n=== removeBindingCPP.py ==="
cat pio_scripts/removeBindingCPP.py

# Look for SpO2 related code
echo -e "\n=== Searching for SpO2 related functions ==="
rg -A 5 "processSpO2" --type cpp

echo -e "\n=== Searching for spo2 flag usage ==="
rg -A 3 -B 3 "spo2.*flag\|flag.*spo2" --type cpp

Length of output: 4775


🏁 Script executed:

#!/bin/bash
# Look for the acquireData structure and spo2 flag
echo "=== Searching for acquireData structure ==="
rg -A 10 -B 5 "struct.*acquireData\|acquireData.*struct" --type cpp

echo -e "\n=== Searching for spo2 in acquireData ==="
rg -A 5 -B 5 "spo2" --type cpp

echo -e "\n=== Looking at the full processSpO2 function ==="
rg -A 30 "void EmotiBit::processSpO2" --type cpp

echo -e "\n=== Check for SpO2 data type definitions ==="
rg -A 3 -B 3 "SPO2\|SpO2" --type cpp | head -50

echo -e "\n=== Look for any SpO2 configuration or constants ==="
rg -A 3 -B 3 "SPO2_.*_SIZE\|SPO2_.*BUFFER" --type cpp

Length of output: 4492


🏁 Script executed:

#!/bin/bash
# Look for SPO2 constants and buffer size definitions
echo "=== Searching for SPO2_PPG_BUFFER_SIZE definition ==="
rg "SPO2_PPG_BUFFER_SIZE" --type cpp --type h

echo -e "\n=== Check EmotiBitPacket for SPO2 TypeTag ==="
rg -A 5 -B 5 "TypeTag.*SPO2\|SPO2.*TypeTag" --type cpp --type h

echo -e "\n=== Look for includes of Brainflow SpO2 Algorithm ==="
rg "Emotibit_Brainflow_SpO2_Algorithm\|get_oxygen_level" --type cpp --type h

echo -e "\n=== Check for any configuration files or settings ==="
fd -t f "config" -e json -e ini -e txt

echo -e "\n=== Look at EmotiBit.cpp processData function to see full context ==="
rg -A 20 -B 5 "void EmotiBit::processData" --type cpp

echo -e "\n=== Check for any test files or examples ==="
fd -t f -e ino | head -10

Length of output: 3329


🏁 Script executed:

#!/bin/bash
# Check the header includes for the brainflow algorithm
echo "=== Looking for includes in EmotiBit.h ==="
rg -A 2 -B 2 "#include.*Brainflow.*SpO2\|#include.*Emotibit_Brainflow" EmotiBit.h

echo -e "\n=== Check for EmotiBitPacket header file ==="
fd -t f "EmotiBitPacket" 

echo -e "\n=== Look for TypeTag definitions ==="
rg -A 5 -B 5 "enum.*TypeTag\|TypeTag.*enum" --type h

echo -e "\n=== Check the get_oxygen_level function usage ==="
rg -A 3 -B 3 "get_oxygen_level" --type cpp

echo -e "\n=== Look at config.txt ==="
cat EmotiBit_stock_firmware/config.txt

echo -e "\n=== Check for any documentation files ==="
fd -t f -e md -e txt | grep -i readme

echo -e "\n=== Look for version information ==="
rg -A 3 -B 3 "1\.14\.0" --type h --type cpp

Length of output: 1978


🏁 Script executed:

#!/bin/bash
# Look for the actual include statement for the brainflow algorithm
echo "=== All includes in EmotiBit.h ==="
grep "#include" EmotiBit.h

echo -e "\n=== Search for EmotiBitPacket in all files ==="
rg -l "EmotiBitPacket" --type h --type cpp | head -5

echo -e "\n=== Look for DataType enum ==="
rg -A 10 -B 5 "enum.*DataType\|DataType.*enum" --type h

echo -e "\n=== Check if there's a separate EmotiBitPacket file ==="
find . -name "*Packet*" -type f

echo -e "\n=== Look for any mentions of the exact include ==="
rg "Emotibit_Brainflow_SpO2_Algorithm\.h" --type h --type cpp

echo -e "\n=== Check main README ==="
head -30 README.md

Length of output: 2587


🏁 Script executed:

#!/bin/bash
# Let's examine the EmotiBitPacket usage to understand the TypeTag
echo "=== Looking at EmotiBitPacket TypeTag usage in EmotiBit.cpp ==="
rg -A 5 -B 5 "TypeTag.*SPO2\|SPO2.*TypeTag\|addPacket.*SPO2" EmotiBit.cpp

echo -e "\n=== Check EmotiBitWiFi.h for packet definitions ==="
rg -A 10 -B 5 "TypeTag\|SPO2" EmotiBitWiFi.h

echo -e "\n=== Look for all TypeTag entries to understand the enum ==="
rg -A 20 "TypeTag::" --type cpp --type h | head -40

echo -e "\n=== Check for unit tests or test cases ==="
find . -name "*test*" -type d | head -5

echo -e "\n=== Look for any example files that might show usage ==="
cat EmotiBit_stock_firmware/EmotiBit_stock_firmware.ino | head -50

echo -e "\n=== Check the documentation compatibility list for Brainflow ==="
rg -A 2 -B 2 -i "brainflow\|spo2.*algorithm" README.md

Length of output: 4896


@jaketheduque I've performed a comprehensive code review of the SpO2 feature addition. Here's my detailed analysis and recommendations:

Code Review Findings

What's Working Well

  • Clean integration with existing acquireData flags system
  • Proper use of static buffers to maintain state between function calls
  • Conditional processing based on acquireData.spo2 flag
  • Correct dependency addition in library.properties
  • Appropriate version bumping to 1.14.0

🔧 Code Quality Issues

1. Missing Documentation

// EmotiBit.h - Missing doxygen documentation
void processSpO2(); // ❌ No documentation

// Should be:
/**
 * @brief Processes SpO2 calculation from PPG data buffers
 * @details Accumulates IR and RED PPG data in static buffers and calculates 
 *          SpO2 when sufficient data is available using Brainflow algorithm
 */
void processSpO2();

2. Buffer Management Issues

// EmotiBit.cpp - Current implementation has potential issues
if (irDataIndex >= SPO2_PPG_BUFFER_SIZE-15 && redDataIndex >= SPO2_PPG_BUFFER_SIZE-15) {
    get_oxygen_level(irDataBuffer, redDataBuffer, min(irDataIndex, redDataIndex), &spo2);

Issues:

  • Magic number -15 without explanation
  • No bounds checking for array access
  • Static buffers not initialized to zero

Suggested improvement:

// Add constants for better maintainability
#define SPO2_MIN_SAMPLES_REQUIRED 49  // SPO2_PPG_BUFFER_SIZE - 15
#define SPO2_ALGORITHM_OVERLAP 15     // Buffer overlap for algorithm stability

// Improve buffer management
if (irDataIndex >= SPO2_MIN_SAMPLES_REQUIRED && redDataIndex >= SPO2_MIN_SAMPLES_REQUIRED) {
    // Add error handling for the algorithm call
    int result = get_oxygen_level(irDataBuffer, redDataBuffer, 
                                  min(irDataIndex, redDataIndex), &spo2);
    if (result == 0) {  // Assuming 0 indicates success
        addPacket(timestamp, EmotiBitPacket::TypeTag::SPO2, &spo2, APERIODIC_DATA_LEN);
    }
    // Reset indices after successful processing
    irDataIndex = 0;
    redDataIndex = 0;
}

3. Missing Error Handling

The get_oxygen_level() function call lacks error handling. The algorithm might fail or return invalid values.

4. Buffer Overflow Protection

// Current code has potential buffer overflow
if (irDataIndex + irDataSize < SPO2_PPG_BUFFER_SIZE) {
    // What happens if this condition fails? Data is silently dropped
}

📝 Missing PR Details

1. Performance Impact Documentation

  • What's the computational overhead of SpO2 processing?
  • Memory usage increase from static buffers (2 × 64 × sizeof(float) = 512 bytes)

2. Configuration Options

  • Buffer size rationale (why 64 samples?)
  • Sampling rate requirements for accurate SpO2
  • Algorithm tuning parameters

3. Error Handling Strategy

  • What happens when SpO2 calculation fails?
  • Invalid reading detection and handling

4. Testing Evidence

  • Validation against reference SpO2 measurements
  • Performance benchmarks
  • Memory usage analysis

🧪 Testing Recommendations

1. Unit Tests Needed

// Suggested test cases:
- Test buffer overflow conditions
- Test with insufficient data
- Test algorithm failure scenarios  
- Test flag enable/disable functionality
- Test memory usage and buffer resets

2. Integration Tests

  • Verify SpO2 packets are properly formatted
  • Test with different PPG data patterns
  • Validate against known SpO2 reference values

📋 Additional PR Details to Add

1. Algorithm Details

## SpO2 Algorithm Information
- **Source**: Brainflow SpO2 Algorithm v[version]
- **Method**: [Brief description of algorithm approach]
- **Accuracy**: ±[accuracy]% (specify test conditions)
- **Range**: [min-max]% SpO2 detection range
- **Sampling Requirements**: [requirements for reliable operation]

2. Configuration Section

## Configuration Options
- `SPO2_PPG_BUFFER_SIZE`: Buffer size for algorithm (default: 64)
- `acquireData.spo2`: Enable/disable SpO2 processing (default: true)
- Minimum PPG data quality requirements

3. Performance Impact

## Performance Impact
- **Memory**: +512 bytes static RAM for buffers
- **CPU**: ~[X]ms processing time per calculation
- **Output Rate**: SpO2 values every ~[X] seconds

4. Validation Results

## Validation
- [ ] Tested against clinical-grade pulse oximeter
- [ ] Accuracy: ±[X]% over [range]% SpO2
- [ ] Tested with different skin tones/conditions
- [ ] Motion artifact handling verified

🔒 Security/Robustness Concerns

  1. Input Validation: No validation of PPG data quality before processing
  2. Resource Management: Static buffers could cause issues in memory-constrained scenarios
  3. Algorithm Dependencies: External algorithm reliability and error propagation

📖 Documentation Updates Needed

  1. API Documentation: Add doxygen comments for new functions
  2. User Guide: SpO2 feature usage and interpretation
  3. Troubleshooting: Common issues and solutions
  4. Calibration: Any user calibration requirements

🚀 Recommendations for Future PRs

  1. Configurable Buffer Sizes: Allow tuning via configuration
  2. Quality Metrics: Add signal quality indicators
  3. Adaptive Processing: Adjust algorithm parameters based on signal quality
  4. Error Reporting: Structured error codes and logging

Would you like me to elaborate on any of these points or help you implement specific improvements?

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Aug 12, 2025

Walkthrough

Adds SpO2 processing: new processSpO2 method, buffering IR/Red PPG and emitting SPO2 packets in processData when enabled. Updates header (API, buffers, firmware version, acquireData.spo2), build configs (library dependency, PlatformIO partitions and script), and minor logging/include order adjustments.

Changes

Cohort / File(s) Summary of changes
Core SpO2 Integration
EmotiBit.cpp, EmotiBit.h
Added processSpO2(), buffers IR/Red PPG, computes SpO2 via get_oxygen_level, emits SPO2 packets; invoked from processData when AcquireData.spo2 is true. Added include for Emotibit_Brainflow_SpO2_Algorithm.h, macro SPO2_PPG_BUFFER_SIZE, new AcquireData.spo2 flag (default true), firmware_version updated to "1.14.0-feat-spo2.0", minor logging fix.
Firmware Sketch
EmotiBit_stock_firmware/EmotiBit_stock_firmware.ino
Reordered include of Arduino.h after EmotiBit.h; removed a comment on SERIAL_BAUD; whitespace tweak.
Build/Config
EmotiBit_stock_firmware/platformio.ini, library.properties, pio_scripts/removeBindingCPP.py
Added board_build.partitions=partitions.csv; appended “EmotiBit Brainflow SpO2 Algorithm” to library dependencies; introduced build middleware to skip compiling any bindings.cpp files.

Sequence Diagram(s)

sequenceDiagram
  participant Sensor as MAX30101 (PPG)
  participant EmotiBit as EmotiBit::processData
  participant SpO2 as processSpO2
  participant Algo as get_oxygen_level
  participant Packets as addPacket(SPO2)

  Sensor->>EmotiBit: Provide IR/Red PPG samples + timestamp
  EmotiBit->>SpO2: If AcquireData.spo2, pass samples
  SpO2->>SpO2: Buffer IR/Red until threshold
  SpO2->>Algo: Compute SpO2 when buffers ready
  Algo-->>SpO2: SpO2 value
  SpO2->>Packets: Emit SPO2 packet (APERIODIC_DATA_LEN, timestamp)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A heartbeat’s hush in crimson light,
I nibble bytes by lunar night—
IR, Red, I blend just so,
To whisper SPO2’s new glow.
Packets hop; I thump with glee,
Firmware fresh as clover tea.
Bun-approved telemetry! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-spo2

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (3)
EmotiBit.h (1)

59-59: Consider using semantic versioning for feature branches.

The version string "1.14.0-feat-spo2.0" deviates from standard semantic versioning. Consider using a pre-release identifier format like "1.14.0-alpha.1" or "1.14.0-spo2.1" for better compatibility with version parsing tools.

EmotiBit.cpp (2)

3399-3407: Replace unexplained magic number with a named constant or a clear condition

SPO2_PPG_BUFFER_SIZE - 15 is opaque. Either:

  • Require a full buffer (minLen >= SPO2_PPG_BUFFER_SIZE), or
  • Introduce a named margin constant with an inline rationale.

Minimal tweak within current design:

-  if (irDataIndex >= SPO2_PPG_BUFFER_SIZE-15 && redDataIndex >= SPO2_PPG_BUFFER_SIZE-15) {
+  constexpr size_t SPO2_TAIL_MARGIN = 15; // Margin required by algorithm; avoids partial-window bias
+  if (irDataIndex >= SPO2_PPG_BUFFER_SIZE - SPO2_TAIL_MARGIN &&
+      redDataIndex >= SPO2_PPG_BUFFER_SIZE - SPO2_TAIL_MARGIN) {

Please add a brief comment explaining why this margin is needed (e.g., filter group delay, algorithm warm-up).


3366-3409: Add doxygen-style docs to the new API for consistency

Add a brief doxygen block above processSpO2 detailing:

  • Purpose
  • Input streams used (PPG_INFRARED, PPG_RED)
  • Window length and timing assumptions
  • Output packet type and rate
    This keeps it aligned with the rest of the codebase’s documentation practices.

Would you like me to draft the doxygen block with parameter/return details?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f48eeaa and a221ce6.

⛔ Files ignored due to path filters (1)
  • EmotiBit_stock_firmware/partitions.csv is excluded by !**/*.csv
📒 Files selected for processing (6)
  • EmotiBit.cpp (3 hunks)
  • EmotiBit.h (5 hunks)
  • EmotiBit_stock_firmware/EmotiBit_stock_firmware.ino (2 hunks)
  • EmotiBit_stock_firmware/platformio.ini (1 hunks)
  • library.properties (1 hunks)
  • pio_scripts/removeBindingCPP.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
EmotiBit.h (1)
EmotiBit.cpp (2)
  • processSpO2 (3366-3408)
  • processSpO2 (3366-3366)
🪛 Ruff (0.12.2)
pio_scripts/removeBindingCPP.py

1-1: Undefined name Import

(F821)


6-6: Undefined name env

(F821)

🔇 Additional comments (7)
pio_scripts/removeBindingCPP.py (1)

1-6: Fix the PlatformIO-specific import syntax and add documentation.

The static analysis warnings about undefined Import and env are false positives - these are PlatformIO build system globals. However, the script lacks documentation explaining its purpose and the middleware pattern.

Consider adding a module docstring to clarify the script's purpose:

+"""
+PlatformIO build middleware to exclude bindings.cpp files from compilation.
+This prevents compilation of Brainflow binding files that are not needed
+for the EmotiBit firmware build.
+"""
 Import("env")
 
 def skip_bindings_cpp(env, node):
+    """Return None to skip building files matching the pattern."""
   return None
 
 env.AddBuildMiddleware(skip_bindings_cpp, "**/bindings.cpp")
EmotiBit.h (1)

38-38: Verify availability of Emotibit_Brainflow_SpO2_Algorithm.h

I wasn’t able to locate Emotibit_Brainflow_SpO2_Algorithm.h anywhere in the repository. Please confirm that:

  • The header file is included in your project (e.g., placed under src/ or include/, or provided by an external “Emotibit” library folder).
  • Your library.properties declares the dependency supplying this header.
  • The include path in your build setup actually points to the directory containing this file.

If the file is missing, add it to your repo or adjust the library/dependency configuration so the compiler can find it.

EmotiBit_stock_firmware/EmotiBit_stock_firmware.ino (2)

1-2: Header include order change has no functional impact.

The reordering of Arduino.h after EmotiBit.h doesn't affect functionality but deviates from the common Arduino convention of including Arduino.h first.


5-5: Removal of comment improves code cleanliness.

Removing the redundant //115200 comment that didn't match the actual baud rate value improves code clarity.

EmotiBit.cpp (3)

2437-2437: LGTM: debug log now prints the passed-in type

The change to print the function argument’s type is correct and improves the usefulness of the debug message.


3459-3462: LGTM: gating and placement of SpO2 processing is correct

SpO2 processing is enabled behind acquireData.spo2 and is invoked after buffer swaps, which ensures you read OUT buffers consistently and do not race the ISR. This aligns with HeartRate placement.


3366-3409: Improve processSpO2 buffer safety and index handling

EmotiBit.cpp → processSpO2 (≈lines 3366–3409):

• Change irDataIndex/redDataIndex from uint8_t to size_t to avoid truncation.
• Clamp each incoming chunk to the remaining capacity instead of skipping the copy and still advancing the index.
• Replace the magic -15 tail margin with a named constant, e.g.

constexpr size_t SPO2_TAIL_MARGIN = 15;
constexpr size_t MIN_WINDOW = SPO2_PPG_BUFFER_SIZE - SPO2_TAIL_MARGIN;

• Remove or actually use the unused timePeriod variable—ideally to compute an end-of-window timestamp.
• After calling get_oxygen_level(...), validate spo2 (must be finite and in [0,100]) and skip addPacket() if invalid.
• Use the later of the two channel timestamps plus (window_length–1) * timePeriodMs for the packet timestamp.
Verify get_oxygen_level’s declaration/definition and its return or error-status semantics—if it returns an error code, branch on it before emitting a packet.

@@ -331,6 +332,7 @@ class EmotiBit {
#define IMU_SAMPLING_DIV 2
#define BATTERY_SAMPLING_DIV 50
#define DUMMY_ISR_DIV 10
#define SPO2_PPG_BUFFER_SIZE 64
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Document the rationale for the SpO2 buffer size.

The buffer size of 64 samples appears to be arbitrary. Please add documentation explaining:

  • How this size relates to the SpO2 algorithm requirements
  • The relationship to PPG sampling rate and time window needed for accurate SpO2 calculation
  • Memory impact of these static buffers
+// SpO2 calculation requires a minimum window of PPG samples.
+// At 100Hz PPG rate, 64 samples = 640ms window
+// This size balances algorithm accuracy requirements with memory constraints
 #define SPO2_PPG_BUFFER_SIZE 64
🤖 Prompt for AI Agents
In EmotiBit.h around line 335, the macro defining SPO2_PPG_BUFFER_SIZE as 64
lacks documentation; add a concise comment above the define that explains why 64
was chosen by linking it to the SpO2 algorithm's required sample window (e.g.,
required number of PPG cycles or seconds), show the calculation using the PPG
sampling rate (samples/sec × time window = buffer length) so reviewers can
verify/adjust, note the memory footprint of the static buffer (bytes = buffer
length × bytes per sample × number of channels) and mention it can be tuned via
the macro if a different sampling rate or time window is used.

@@ -7,4 +7,4 @@ paragraph= Requires dependent libraries as shown in the getting started document
category=Sensors
url=https://github.com/EmotiBit/EmotiBit_FeatherWing
architectures=*
depends=EmotiBit BMI160, EmotiBit MAX30101, EmotiBit MLX90632, EmotiBit NCP5623, EmotiBit SI7013, EmotiBit XPlat Utils, EmotiBit ADS1X15, EmotiBit External EEPROM, EmotiBit EmojiLib, EmotiBit ArduinoFilters, EmotiBit SimpleFTPServer, EmotiBit KTD2026
depends=EmotiBit BMI160, EmotiBit MAX30101, EmotiBit MLX90632, EmotiBit NCP5623, EmotiBit SI7013, EmotiBit XPlat Utils, EmotiBit ADS1X15, EmotiBit External EEPROM, EmotiBit EmojiLib, EmotiBit ArduinoFilters, EmotiBit SimpleFTPServer, EmotiBit KTD2026, EmotiBit Brainflow SpO2 Algorithm
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify the availability of the EmotiBit Brainflow SpO2 Algorithm library.

The dependency on "EmotiBit Brainflow SpO2 Algorithm" needs to be available in the Arduino Library Registry. According to the PR description, this requires PR #1 in the EmotiBit_Brainflow_SpO2_Algorithm repository to be merged first.


🏁 Script executed:

#!/bin/bash
# Check if the library dependency is properly documented
echo "Checking for library documentation or references:"
rg -A 3 "EmotiBit.*Brainflow.*SpO2" --type-add 'doc:*.{md,txt,rst}' -t doc

# Check for any library.json or similar configuration files
echo -e "\nSearching for library configuration files:"
fd -e json -e properties | xargs grep -l "Brainflow\|SpO2" 2>/dev/null || true

Length of output: 366


🌐 Web query:

Is the "EmotiBit Brainflow SpO2 Algorithm" library available in the Arduino Library Registry?

💡 Result:

Short answer: No — I couldn't find a library named "EmotiBit Brainflow SpO2 Algorithm" in the Arduino Library Registry.

Details and sources:

  • The Arduino Library Registry does include several EmotiBit libraries (for example EmotiBit MAX30101, BMI160, FeatherWing), but there is no entry with the exact name "EmotiBit Brainflow SpO2 Algorithm". (arduino.cc)
  • EmotiBit’s MAX30101 library (which contains a spo2_algorithm.h implementation) is available on GitHub and is the place to look for SpO2 code for EmotiBit hardware; that library is also installable from the Arduino Library Manager. (github.com)
  • BrainFlow provides host-side support for EmotiBit (for streaming/processing on the PC), but I did not find a separately-registered Arduino library called “EmotiBit Brainflow SpO2 Algorithm.” (brainflow.org, github.com)

If you want, I can:

  • Re-run a live search in the Arduino Library Registry right now to double-check, or
  • Show how to install/use the EmotiBit_MAX30101 library (and its spo2 algorithm) from the Arduino Library Manager or from GitHub, or
  • Help integrate EmotiBit with BrainFlow on the host to compute SpO2 off-board. Which would you like?

Citations:


Dependency missing: “EmotiBit Brainflow SpO2 Algorithm” is not published

The library “EmotiBit Brainflow SpO2 Algorithm” referenced on line 10 of library.properties isn’t available in the Arduino Library Registry. You’ll need to:

  • Merge and publish PR Fix units of thermistor #1 in the EmotiBit_Brainflow_SpO2_Algorithm repo so it appears in the Library Manager, then update this dependency.
  • Or, if you just need the SpO₂ algorithm on-device today, replace it with the existing EmotiBit_MAX30101 library (which includes spo2_algorithm.h and is already on the Library Manager).

File and location:

  • library.properties — line 10 (depends)
🤖 Prompt for AI Agents
library.properties around line 10: the depends entry references "EmotiBit
Brainflow SpO2 Algorithm" which is not published to the Arduino Library Manager;
either merge and publish PR #1 in the EmotiBit_Brainflow_SpO2_Algorithm repo so
that the package name becomes available and then update this depends line to the
exact published library name, version and spelling, or replace that dependency
immediately with the existing published library "EmotiBit_MAX30101" (which
contains spo2_algorithm.h) by changing the depends entry to include
EmotiBit_MAX30101 instead; ensure the final depends line only lists libraries
available in the Arduino registry and matches their exact package names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant