Loom 4 v4.5
Arduino library for Internet of Things Rapid Prototyping in environmental sensing
Loading...
Searching...
No Matches
Loom_MMA8451.h
1#pragma once
2
3#include <Wire.h>
4#include <Adafruit_MMA8451.h>
5
6#include "../I2CDevice.h"
7#include "Loom_Manager.h"
8
9// Consult the datasheet for MMA8451 to change these values
10#define CTRL_REG3 0b11000000
11#define CTRL_REG4 0b00100001
12#define CTRL_REG5 0b00100000
13#define REG_TRANS_CFG 0b00001110
14#define REG_TRANS_CT 0b00000000
15
16// Register Addresses
17#define MMA8451_REG_CTRL_REG3 0x2C
18#define MMA8451_REG_TRANSIENT_CFG 0x1D
19#define MMA8451_REG_TRANSIENT_THS 0x1F
20#define MMA8451_REG_TRANSIENT_CT 0x20
21#define MMA8451_REG_TRANSIENT_SRC 0x1E
22
23// Used to pass along the user defined interrupt callback
24using InterruptCallbackFunction = void (*)();
25
31class Loom_MMA8451 : public I2CDevice{
32 protected:
33 void power_down() override {};
34
35
36 // Manager controlled functions
37 void measure() override;
38 void initialize() override;
39 void package() override;
40 void power_up() override;
41
42 public:
50 Manager& man,
51 int addr = 0x1D,
52 bool useMux = false,
53 mma8451_range_t range = MMA8451_RANGE_2_G,
54 int interruptPin = -1,
55 uint8_t sensitivity = 0x10
56 );
57
61 float getAccelX() { return accel[0]; };
62
66 float getAccelY() { return accel[1]; };
67
71 float getAccelZ() { return accel[2]; };
72
76 uint8_t getOrientation() { return orientation; };
77
81 void setISR(InterruptCallbackFunction isr) { this->isr = isr; };
82
83 static void IMU_ISR();
84
85
86
87 private:
88 Manager* manInst; // Instance of the manager
89 Adafruit_MMA8451 mma; // Instance of the MMA sensor
90
91 mma8451_range_t range; // Range of the sensor
92 int address; // I2C address
93 uint8_t sensitivity = 0x10; // Sensitivity of detection
94
95 static uint8_t interruptPin; // Interrupt pin on movement
96 static InterruptCallbackFunction isr; // ISR to call when the interrupt is triggered
97
98 float accel[3]; // Acceleration values for each axis. Units: g
99 uint8_t orientation; // Orientation
100};
Definition: I2CDevice.h:6
Definition: Loom_MMA8451.h:31
void setISR(InterruptCallbackFunction isr)
Definition: Loom_MMA8451.h:81
float getAccelY()
Definition: Loom_MMA8451.h:66
float getAccelZ()
Definition: Loom_MMA8451.h:71
float getAccelX()
Definition: Loom_MMA8451.h:61
uint8_t getOrientation()
Definition: Loom_MMA8451.h:76
Definition: Loom_Manager.h:18