SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
bma_universal_compatibility.ino File Reference

@license MIT License More...

Include dependency graph for bma_universal_compatibility.ino:

Go to the source code of this file.

Macros

#define SENSOR_SDA   21
 
#define SENSOR_SCL   22
 
#define SENSOR_IRQ   39
 

Enumerations

enum class  DetectedModel { NONE , BMA422 , BMA423 , BMA456H }
 

Functions

bool initSensor ()
 
void setupTapCallback ()
 
void setupStepCallbacks ()
 
void setupActivityCallback ()
 
void setupTiltCallback ()
 
void setupDataReadyCallback ()
 
void setupFeatures ()
 
void setup ()
 
void loop ()
 

Variables

SensorBMA422 bma422
 
SensorBMA423 bma423
 
SensorBMA456H bma456h
 
SensorBMA4XXsensor = nullptr
 
DetectedModel detectedModel = DetectedModel::NONE
 
volatile bool isInterruptTriggered = false
 

Detailed Description

@license MIT License

Copyright (c) 2026 lewis he

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Author
Lewis He (lewis.nosp@m.he@o.nosp@m.utloo.nosp@m.k.co.nosp@m.m)
Date
2026-04-25

Universal BMA4XX Compatibility Example

This example demonstrates how to write a single firmware that works with BMA422, BMA423, or BMA456H sensors without knowing which chip is on the board.

Design pattern:

  1. Auto-detect the sensor by trying each driver
  2. Operate through the SensorBMA4XX base class pointer for common APIs
  3. Query capabilities via getCapabilities() to enable features polymorphically
  4. For typed operations (callbacks), dispatch via DetectedModel enum

Definition in file bma_universal_compatibility.ino.

Macro Definition Documentation

◆ SENSOR_IRQ

#define SENSOR_IRQ   39

Definition at line 51 of file bma_universal_compatibility.ino.

◆ SENSOR_SCL

#define SENSOR_SCL   22

Definition at line 47 of file bma_universal_compatibility.ino.

◆ SENSOR_SDA

#define SENSOR_SDA   21

Definition at line 43 of file bma_universal_compatibility.ino.

Enumeration Type Documentation

◆ DetectedModel

enum class DetectedModel
strong
Enumerator
NONE 
BMA422 
BMA423 
BMA456H 

Definition at line 63 of file bma_universal_compatibility.ino.

Function Documentation

◆ initSensor()

bool initSensor ( )

◆ loop()

◆ setup()

◆ setupActivityCallback()

◆ setupDataReadyCallback()

◆ setupFeatures()

◆ setupStepCallbacks()

◆ setupTapCallback()

◆ setupTiltCallback()

void setupTiltCallback ( )

Variable Documentation

◆ bma422

SensorBMA422 bma422

Definition at line 56 of file bma_universal_compatibility.ino.

Referenced by initSensor(), and setupDataReadyCallback().

◆ bma423

◆ bma456h

◆ detectedModel

◆ isInterruptTriggered

volatile bool isInterruptTriggered = false

Definition at line 72 of file bma_universal_compatibility.ino.

Referenced by loop(), and setup().

◆ sensor

SensorBMA4XX* sensor = nullptr

Definition at line 61 of file bma_universal_compatibility.ino.

Referenced by initSensor(), loop(), setup(), and setupFeatures().