|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
@license MIT License More...
#include <AccelerometerDrv.hpp>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 |
| SensorBMA4XX * | sensor = nullptr |
| DetectedModel | detectedModel = DetectedModel::NONE |
| volatile bool | isInterruptTriggered = false |
@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.
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:
Definition in file bma_universal_compatibility.ino.
| #define SENSOR_IRQ 39 |
Definition at line 51 of file bma_universal_compatibility.ino.
| #define SENSOR_SCL 22 |
Definition at line 47 of file bma_universal_compatibility.ino.
| #define SENSOR_SDA 21 |
Definition at line 43 of file bma_universal_compatibility.ino.
|
strong |
| Enumerator | |
|---|---|
| NONE | |
| BMA422 | |
| BMA423 | |
| BMA456H | |
Definition at line 63 of file bma_universal_compatibility.ino.
| bool initSensor | ( | ) |
Definition at line 78 of file bma_universal_compatibility.ino.
References ComplexStaticDeviceWithHal::begin(), bma422, BMA422, bma423, BMA423, bma456h, BMA456H, detectedModel, sensor, SENSOR_SCL, and SENSOR_SDA.
Referenced by setup().
| void loop | ( | ) |
Definition at line 333 of file bma_universal_compatibility.ino.
References SensorBMA4XX::getTemperature(), isInterruptTriggered, sensor, and SensorBMA4XX::update().
| void setup | ( | ) |
Definition at line 281 of file bma_universal_compatibility.ino.
References CIC_AVG_MODE, SensorBMA4XX::configAccelerometer(), FS_2G, SensorBMA4XX::getModelName(), initSensor(), isInterruptTriggered, NORMAL, OSR2_AVG2, PIN1, sensor, SENSOR_IRQ, SensorBMA4XX::setInterruptPinConfig(), setupDataReadyCallback(), and setupFeatures().
| void setupActivityCallback | ( | ) |
Definition at line 167 of file bma_universal_compatibility.ino.
References bma423, BMA423, bma456h, BMA456H, detectedModel, RUNNING, SensorBMA423::setOnActivityCallback(), SensorBMA456H::setOnActivityCallback(), STATIONARY, and WALKING.
Referenced by setupFeatures().
| void setupDataReadyCallback | ( | ) |
Definition at line 200 of file bma_universal_compatibility.ino.
References bma422, BMA422, bma423, BMA423, bma456h, BMA456H, detectedModel, SensorBMA422::setOnDataReadyCallback(), SensorBMA423::setOnDataReadyCallback(), and SensorBMA456H::setOnDataReadyCallback().
Referenced by setup().
| void setupFeatures | ( | ) |
Definition at line 228 of file bma_universal_compatibility.ino.
References SensorBMA4XX::enableActivityRecognition(), SensorBMA4XX::enableAnyMotionDetection(), SensorBMA4XX::enableDataReady(), SensorBMA4XX::enableStepCounter(), SensorBMA4XX::enableStepDetector(), SensorBMA4XX::enableTapDetector(), SensorBMA4XX::enableTiltDetector(), SensorBMA4XX::getCapabilities(), SensorBMA4XX::getModelName(), sensor, SensorBMA4XX::setRemapAxes(), setupActivityCallback(), setupStepCallbacks(), setupTapCallback(), setupTiltCallback(), BMA4XXCapability::SupportActivity, BMA4XXCapability::SupportAnyMotion, BMA4XXCapability::SupportAxisRemap, BMA4XXCapability::SupportDataReady, BMA4XXCapability::SupportStepDetector, BMA4XXCapability::SupportTap, BMA4XXCapability::SupportTilt, and TOP_LAYER_RIGHT_CORNER.
Referenced by setup().
| void setupStepCallbacks | ( | ) |
Definition at line 141 of file bma_universal_compatibility.ino.
References bma423, BMA423, bma456h, BMA456H, detectedModel, SensorBMA423::setOnStepCountCallback(), SensorBMA456H::setOnStepCountCallback(), SensorBMA423::setOnStepDetectedCallback(), and SensorBMA456H::setOnStepDetectedCallback().
Referenced by setupFeatures().
| void setupTapCallback | ( | ) |
Definition at line 109 of file bma_universal_compatibility.ino.
References bma423, BMA423, bma456h, BMA456H, detectedModel, DOUBLE_TAP, SensorBMA423::setOnTapCallback(), SensorBMA456H::setOnTapCallback(), SINGLE_TAP, and TRIPLE_TAP.
Referenced by setupFeatures().
| void setupTiltCallback | ( | ) |
Definition at line 191 of file bma_universal_compatibility.ino.
References bma423, BMA423, detectedModel, and SensorBMA423::setOnTiltDetectedCallback().
Referenced by setupFeatures().
| SensorBMA422 bma422 |
Definition at line 56 of file bma_universal_compatibility.ino.
Referenced by initSensor(), and setupDataReadyCallback().
| SensorBMA423 bma423 |
Definition at line 57 of file bma_universal_compatibility.ino.
Referenced by initSensor(), setupActivityCallback(), setupDataReadyCallback(), setupStepCallbacks(), setupTapCallback(), and setupTiltCallback().
| SensorBMA456H bma456h |
Definition at line 58 of file bma_universal_compatibility.ino.
Referenced by initSensor(), setupActivityCallback(), setupDataReadyCallback(), setupStepCallbacks(), and setupTapCallback().
| DetectedModel detectedModel = DetectedModel::NONE |
Definition at line 70 of file bma_universal_compatibility.ino.
Referenced by initSensor(), setupActivityCallback(), setupDataReadyCallback(), setupStepCallbacks(), setupTapCallback(), and setupTiltCallback().
| volatile bool isInterruptTriggered = false |
Definition at line 72 of file bma_universal_compatibility.ino.
| SensorBMA4XX* sensor = nullptr |
Definition at line 61 of file bma_universal_compatibility.ino.
Referenced by initSensor(), loop(), setup(), and setupFeatures().