clanged!
This commit is contained in:
parent
ba2c197f67
commit
21397ecb16
3 changed files with 201 additions and 206 deletions
|
|
@ -20,6 +20,7 @@ addons:
|
|||
|
||||
before_install:
|
||||
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh)
|
||||
- curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/run-clang-format.py > run-clang-format.py
|
||||
|
||||
install:
|
||||
- arduino --install-library "Adafruit BusIO"
|
||||
|
|
|
|||
|
|
@ -15,14 +15,13 @@
|
|||
/**************************************************************************/
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_MSA301.h>
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
|
|
@ -31,7 +30,6 @@
|
|||
/**************************************************************************/
|
||||
Adafruit_MSA301::Adafruit_MSA301() {}
|
||||
|
||||
|
||||
/*!
|
||||
* @brief Sets up the hardware and initializes I2C
|
||||
* @param i2c_address
|
||||
|
|
@ -49,9 +47,8 @@ bool Adafruit_MSA301::begin(uint8_t i2c_address, TwoWire *wire) {
|
|||
}
|
||||
|
||||
// Check connection
|
||||
Adafruit_BusIO_Register chip_id =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_PARTID, 1);
|
||||
|
||||
Adafruit_BusIO_Register chip_id =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_PARTID, 1);
|
||||
|
||||
// make sure we're talking to the right chip
|
||||
if (chip_id.read() != 0x13) {
|
||||
|
|
@ -89,19 +86,16 @@ bool Adafruit_MSA301::begin(uint8_t i2c_address, TwoWire *wire) {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets the data rate for the MSA301 (controls power consumption)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_MSA301::setDataRate(msa301_dataRate_t dataRate)
|
||||
{
|
||||
Adafruit_BusIO_Register ODR =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_ODR, 1);
|
||||
Adafruit_BusIO_RegisterBits dataratebits = Adafruit_BusIO_RegisterBits(&ODR, 4, 0);
|
||||
void Adafruit_MSA301::setDataRate(msa301_dataRate_t dataRate) {
|
||||
Adafruit_BusIO_Register ODR =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_ODR, 1);
|
||||
Adafruit_BusIO_RegisterBits dataratebits =
|
||||
Adafruit_BusIO_RegisterBits(&ODR, 4, 0);
|
||||
dataratebits.write((uint8_t)dataRate);
|
||||
}
|
||||
|
||||
|
|
@ -110,17 +104,17 @@ void Adafruit_MSA301::setDataRate(msa301_dataRate_t dataRate)
|
|||
@brief Sets the data rate for the MSA301 (controls power consumption)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
msa301_dataRate_t Adafruit_MSA301::getDataRate(void)
|
||||
{
|
||||
Adafruit_BusIO_Register ODR =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_ODR, 1);
|
||||
Adafruit_BusIO_RegisterBits dataratebits = Adafruit_BusIO_RegisterBits(&ODR, 4, 0);
|
||||
msa301_dataRate_t Adafruit_MSA301::getDataRate(void) {
|
||||
Adafruit_BusIO_Register ODR =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_ODR, 1);
|
||||
Adafruit_BusIO_RegisterBits dataratebits =
|
||||
Adafruit_BusIO_RegisterBits(&ODR, 4, 0);
|
||||
return (msa301_dataRate_t)dataratebits.read();
|
||||
}
|
||||
|
||||
void Adafruit_MSA301::enableAxes(bool enableX, bool enableY, bool enableZ) {
|
||||
Adafruit_BusIO_Register ODR =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_ODR, 1);
|
||||
Adafruit_BusIO_Register ODR =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_ODR, 1);
|
||||
|
||||
Adafruit_BusIO_RegisterBits x = Adafruit_BusIO_RegisterBits(&ODR, 1, 7);
|
||||
Adafruit_BusIO_RegisterBits y = Adafruit_BusIO_RegisterBits(&ODR, 1, 6);
|
||||
|
|
@ -130,53 +124,48 @@ void Adafruit_MSA301::enableAxes(bool enableX, bool enableY, bool enableZ) {
|
|||
z.write(!enableZ);
|
||||
}
|
||||
|
||||
void Adafruit_MSA301::setPowerMode(msa301_powermode_t mode)
|
||||
{
|
||||
Adafruit_BusIO_Register PowerMode =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_POWERMODE, 1);
|
||||
Adafruit_BusIO_RegisterBits powermodebits = Adafruit_BusIO_RegisterBits(&PowerMode, 2, 6);
|
||||
void Adafruit_MSA301::setPowerMode(msa301_powermode_t mode) {
|
||||
Adafruit_BusIO_Register PowerMode =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_POWERMODE, 1);
|
||||
Adafruit_BusIO_RegisterBits powermodebits =
|
||||
Adafruit_BusIO_RegisterBits(&PowerMode, 2, 6);
|
||||
powermodebits.write((uint8_t)mode);
|
||||
}
|
||||
|
||||
|
||||
msa301_powermode_t Adafruit_MSA301::getPowerMode(void)
|
||||
{
|
||||
Adafruit_BusIO_Register PowerMode =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_POWERMODE, 1);
|
||||
Adafruit_BusIO_RegisterBits powermodebits = Adafruit_BusIO_RegisterBits(&PowerMode, 2, 6);
|
||||
msa301_powermode_t Adafruit_MSA301::getPowerMode(void) {
|
||||
Adafruit_BusIO_Register PowerMode =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_POWERMODE, 1);
|
||||
Adafruit_BusIO_RegisterBits powermodebits =
|
||||
Adafruit_BusIO_RegisterBits(&PowerMode, 2, 6);
|
||||
return (msa301_powermode_t)powermodebits.read();
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_MSA301::setBandwidth(msa301_bandwidth_t bandwidth)
|
||||
{
|
||||
Adafruit_BusIO_Register PowerMode =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_POWERMODE, 1);
|
||||
Adafruit_BusIO_RegisterBits bandwidthbits = Adafruit_BusIO_RegisterBits(&PowerMode, 4, 1);
|
||||
void Adafruit_MSA301::setBandwidth(msa301_bandwidth_t bandwidth) {
|
||||
Adafruit_BusIO_Register PowerMode =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_POWERMODE, 1);
|
||||
Adafruit_BusIO_RegisterBits bandwidthbits =
|
||||
Adafruit_BusIO_RegisterBits(&PowerMode, 4, 1);
|
||||
bandwidthbits.write((uint8_t)bandwidth);
|
||||
}
|
||||
|
||||
|
||||
msa301_bandwidth_t Adafruit_MSA301::getBandwidth(void)
|
||||
{
|
||||
Adafruit_BusIO_Register PowerMode =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_POWERMODE, 1);
|
||||
Adafruit_BusIO_RegisterBits bandwidthbits = Adafruit_BusIO_RegisterBits(&PowerMode, 4, 1);
|
||||
msa301_bandwidth_t Adafruit_MSA301::getBandwidth(void) {
|
||||
Adafruit_BusIO_Register PowerMode =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_POWERMODE, 1);
|
||||
Adafruit_BusIO_RegisterBits bandwidthbits =
|
||||
Adafruit_BusIO_RegisterBits(&PowerMode, 4, 1);
|
||||
return (msa301_bandwidth_t)bandwidthbits.read();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets the g range for the accelerometer
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_MSA301::setRange(msa301_range_t range)
|
||||
{
|
||||
Adafruit_BusIO_Register ResRange =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_RESRANGE, 1);
|
||||
Adafruit_BusIO_RegisterBits rangebits = Adafruit_BusIO_RegisterBits(&ResRange, 2, 0);
|
||||
void Adafruit_MSA301::setRange(msa301_range_t range) {
|
||||
Adafruit_BusIO_Register ResRange =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_RESRANGE, 1);
|
||||
Adafruit_BusIO_RegisterBits rangebits =
|
||||
Adafruit_BusIO_RegisterBits(&ResRange, 2, 0);
|
||||
rangebits.write((uint8_t)range);
|
||||
}
|
||||
|
||||
|
|
@ -185,52 +174,52 @@ void Adafruit_MSA301::setRange(msa301_range_t range)
|
|||
@brief Gets the g range for the accelerometer
|
||||
*/
|
||||
/**************************************************************************/
|
||||
msa301_range_t Adafruit_MSA301::getRange(void)
|
||||
{
|
||||
Adafruit_BusIO_Register ResRange =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_RESRANGE, 1);
|
||||
Adafruit_BusIO_RegisterBits rangebits = Adafruit_BusIO_RegisterBits(&ResRange, 2, 0);
|
||||
msa301_range_t Adafruit_MSA301::getRange(void) {
|
||||
Adafruit_BusIO_Register ResRange =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_RESRANGE, 1);
|
||||
Adafruit_BusIO_RegisterBits rangebits =
|
||||
Adafruit_BusIO_RegisterBits(&ResRange, 2, 0);
|
||||
return (msa301_range_t)rangebits.read();
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief
|
||||
@brief
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_MSA301::setResolution(msa301_resolution_t resolution)
|
||||
{
|
||||
Adafruit_BusIO_Register ResRange =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_RESRANGE, 1);
|
||||
Adafruit_BusIO_RegisterBits resbits = Adafruit_BusIO_RegisterBits(&ResRange, 2, 2);
|
||||
void Adafruit_MSA301::setResolution(msa301_resolution_t resolution) {
|
||||
Adafruit_BusIO_Register ResRange =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_RESRANGE, 1);
|
||||
Adafruit_BusIO_RegisterBits resbits =
|
||||
Adafruit_BusIO_RegisterBits(&ResRange, 2, 2);
|
||||
resbits.write((uint8_t)resolution);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief
|
||||
@brief
|
||||
*/
|
||||
/**************************************************************************/
|
||||
msa301_resolution_t Adafruit_MSA301::getResolution(void)
|
||||
{
|
||||
Adafruit_BusIO_Register ResRange =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_RESRANGE, 1);
|
||||
Adafruit_BusIO_RegisterBits resbits = Adafruit_BusIO_RegisterBits(&ResRange, 2, 2);
|
||||
msa301_resolution_t Adafruit_MSA301::getResolution(void) {
|
||||
Adafruit_BusIO_Register ResRange =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_RESRANGE, 1);
|
||||
Adafruit_BusIO_RegisterBits resbits =
|
||||
Adafruit_BusIO_RegisterBits(&ResRange, 2, 2);
|
||||
return (msa301_resolution_t)resbits.read();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Adafruit_MSA301::read(void) {
|
||||
uint8_t buffer[6];
|
||||
|
||||
Adafruit_BusIO_Register XYZDataReg =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_OUT_X_L, 6);
|
||||
Adafruit_BusIO_Register XYZDataReg =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_OUT_X_L, 6);
|
||||
XYZDataReg.read(buffer, 6);
|
||||
x = buffer[0]; x |= buffer[1] << 8;
|
||||
y = buffer[2]; y |= buffer[3] << 8;
|
||||
z = buffer[4]; z |= buffer[5] << 8;
|
||||
x = buffer[0];
|
||||
x |= buffer[1] << 8;
|
||||
y = buffer[2];
|
||||
y |= buffer[3] << 8;
|
||||
z = buffer[4];
|
||||
z |= buffer[5] << 8;
|
||||
|
||||
// 14 bits of data in 16 bit range
|
||||
x >>= 2;
|
||||
|
|
@ -239,55 +228,63 @@ void Adafruit_MSA301::read(void) {
|
|||
|
||||
msa301_range_t range = getRange();
|
||||
float scale = 1;
|
||||
if (range == MSA301_RANGE_16_G) scale = 512;
|
||||
if (range == MSA301_RANGE_8_G) scale = 1024;
|
||||
if (range == MSA301_RANGE_4_G) scale = 2048;
|
||||
if (range == MSA301_RANGE_2_G) scale = 4096;
|
||||
if (range == MSA301_RANGE_16_G)
|
||||
scale = 512;
|
||||
if (range == MSA301_RANGE_8_G)
|
||||
scale = 1024;
|
||||
if (range == MSA301_RANGE_4_G)
|
||||
scale = 2048;
|
||||
if (range == MSA301_RANGE_2_G)
|
||||
scale = 4096;
|
||||
|
||||
x_g = (float)x / scale;
|
||||
y_g = (float)y / scale;
|
||||
z_g = (float)z / scale;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Set INT to output for single or double click
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
void Adafruit_MSA301::setClick(bool tap_quiet, bool tap_shock, msa301_tapduration_t tapduration, uint8_t tapthresh) {
|
||||
Adafruit_BusIO_Register TapDur =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_TAPDUR, 1);
|
||||
Adafruit_BusIO_RegisterBits quietbit = Adafruit_BusIO_RegisterBits(&TapDur, 1, 7);
|
||||
void Adafruit_MSA301::setClick(bool tap_quiet, bool tap_shock,
|
||||
msa301_tapduration_t tapduration,
|
||||
uint8_t tapthresh) {
|
||||
Adafruit_BusIO_Register TapDur =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_TAPDUR, 1);
|
||||
Adafruit_BusIO_RegisterBits quietbit =
|
||||
Adafruit_BusIO_RegisterBits(&TapDur, 1, 7);
|
||||
quietbit.write(tap_quiet);
|
||||
Adafruit_BusIO_RegisterBits shockbit = Adafruit_BusIO_RegisterBits(&TapDur, 1, 6);
|
||||
Adafruit_BusIO_RegisterBits shockbit =
|
||||
Adafruit_BusIO_RegisterBits(&TapDur, 1, 6);
|
||||
shockbit.write(tap_shock);
|
||||
Adafruit_BusIO_RegisterBits durationbits = Adafruit_BusIO_RegisterBits(&TapDur, 3, 0);
|
||||
Adafruit_BusIO_RegisterBits durationbits =
|
||||
Adafruit_BusIO_RegisterBits(&TapDur, 3, 0);
|
||||
durationbits.write(tapduration);
|
||||
|
||||
Adafruit_BusIO_Register TapTh =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_TAPTH, 1);
|
||||
Adafruit_BusIO_RegisterBits threshbits = Adafruit_BusIO_RegisterBits(&TapTh, 5, 0);
|
||||
Adafruit_BusIO_Register TapTh =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_TAPTH, 1);
|
||||
Adafruit_BusIO_RegisterBits threshbits =
|
||||
Adafruit_BusIO_RegisterBits(&TapTh, 5, 0);
|
||||
threshbits.write(tapthresh);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t Adafruit_MSA301::getClick(void) {
|
||||
Adafruit_BusIO_Register ClickStatus =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_CLICKSTATUS, 1);
|
||||
Adafruit_BusIO_Register ClickStatus =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_CLICKSTATUS, 1);
|
||||
|
||||
return ClickStatus.read();
|
||||
}
|
||||
|
||||
void Adafruit_MSA301::enableInterrupts(bool singletap, bool doubletap,
|
||||
bool activeX, bool activeY, bool activeZ,
|
||||
bool newData, bool freefall, bool orient) {
|
||||
Adafruit_BusIO_Register IntSet0 =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_INTSET0, 1);
|
||||
Adafruit_BusIO_Register IntSet1 =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_INTSET1, 1);
|
||||
bool activeX, bool activeY, bool activeZ,
|
||||
bool newData, bool freefall,
|
||||
bool orient) {
|
||||
Adafruit_BusIO_Register IntSet0 =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_INTSET0, 1);
|
||||
Adafruit_BusIO_Register IntSet1 =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_INTSET1, 1);
|
||||
uint8_t irqs = 0;
|
||||
irqs |= orient << 6;
|
||||
irqs |= singletap << 5;
|
||||
|
|
@ -302,12 +299,13 @@ void Adafruit_MSA301::enableInterrupts(bool singletap, bool doubletap,
|
|||
IntSet1.write(irqs);
|
||||
}
|
||||
|
||||
void Adafruit_MSA301::mapInterruptPin(bool singletap, bool doubletap, bool activity,
|
||||
bool newData, bool freefall, bool orient) {
|
||||
Adafruit_BusIO_Register IntMap0 =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_INTMAP0, 1);
|
||||
Adafruit_BusIO_Register IntMap1 =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_INTMAP1, 1);
|
||||
void Adafruit_MSA301::mapInterruptPin(bool singletap, bool doubletap,
|
||||
bool activity, bool newData,
|
||||
bool freefall, bool orient) {
|
||||
Adafruit_BusIO_Register IntMap0 =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_INTMAP0, 1);
|
||||
Adafruit_BusIO_Register IntMap1 =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_INTMAP1, 1);
|
||||
uint8_t irqs = 0;
|
||||
irqs |= orient << 6;
|
||||
irqs |= singletap << 5;
|
||||
|
|
@ -320,20 +318,19 @@ void Adafruit_MSA301::mapInterruptPin(bool singletap, bool doubletap, bool activ
|
|||
}
|
||||
|
||||
uint8_t Adafruit_MSA301::getMotionInterruptStatus(void) {
|
||||
Adafruit_BusIO_Register IntStatus =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_MOTIONINT, 1);
|
||||
Adafruit_BusIO_Register IntStatus =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_MOTIONINT, 1);
|
||||
|
||||
return IntStatus.read();
|
||||
}
|
||||
|
||||
uint8_t Adafruit_MSA301::getDataInterruptStatus(void) {
|
||||
Adafruit_BusIO_Register IntStatus =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_DATAINT, 1);
|
||||
Adafruit_BusIO_Register IntStatus =
|
||||
Adafruit_BusIO_Register(i2c_dev, MSA301_REG_DATAINT, 1);
|
||||
|
||||
return IntStatus.read();
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Gets the most recent sensor event
|
||||
|
|
@ -343,9 +340,9 @@ bool Adafruit_MSA301::getEvent(sensors_event_t *event) {
|
|||
/* Clear the event */
|
||||
memset(event, 0, sizeof(sensors_event_t));
|
||||
|
||||
event->version = sizeof(sensors_event_t);
|
||||
event->version = sizeof(sensors_event_t);
|
||||
event->sensor_id = _sensorID;
|
||||
event->type = SENSOR_TYPE_ACCELEROMETER;
|
||||
event->type = SENSOR_TYPE_ACCELEROMETER;
|
||||
event->timestamp = 0;
|
||||
|
||||
read();
|
||||
|
|
@ -353,7 +350,7 @@ bool Adafruit_MSA301::getEvent(sensors_event_t *event) {
|
|||
event->acceleration.x = x_g * SENSORS_GRAVITY_STANDARD;
|
||||
event->acceleration.y = y_g * SENSORS_GRAVITY_STANDARD;
|
||||
event->acceleration.z = z_g * SENSORS_GRAVITY_STANDARD;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -367,14 +364,13 @@ void Adafruit_MSA301::getSensor(sensor_t *sensor) {
|
|||
memset(sensor, 0, sizeof(sensor_t));
|
||||
|
||||
/* Insert the sensor name in the fixed length char array */
|
||||
strncpy (sensor->name, "MSA301", sizeof(sensor->name) - 1);
|
||||
sensor->name[sizeof(sensor->name)- 1] = 0;
|
||||
sensor->version = 1;
|
||||
sensor->sensor_id = _sensorID;
|
||||
sensor->type = SENSOR_TYPE_ACCELEROMETER;
|
||||
sensor->min_delay = 0;
|
||||
sensor->max_value = 0;
|
||||
sensor->min_value = 0;
|
||||
sensor->resolution = 0;
|
||||
strncpy(sensor->name, "MSA301", sizeof(sensor->name) - 1);
|
||||
sensor->name[sizeof(sensor->name) - 1] = 0;
|
||||
sensor->version = 1;
|
||||
sensor->sensor_id = _sensorID;
|
||||
sensor->type = SENSOR_TYPE_ACCELEROMETER;
|
||||
sensor->min_delay = 0;
|
||||
sensor->max_value = 0;
|
||||
sensor->min_value = 0;
|
||||
sensor->resolution = 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,108 +14,104 @@
|
|||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
#ifndef ADAFRUIT_MSA301_H
|
||||
#define ADAFRUIT_MSA301_H
|
||||
|
||||
#include <Adafruit_BusIO_Register.h>
|
||||
#include <Adafruit_I2CDevice.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_I2CDevice.h>
|
||||
#include <Adafruit_BusIO_Register.h>
|
||||
|
||||
/*=========================================================================
|
||||
I2C ADDRESS/BITS
|
||||
-----------------------------------------------------------------------*/
|
||||
#define MSA301_I2CADDR_DEFAULT (0x26)
|
||||
#define MSA301_I2CADDR_DEFAULT (0x26)
|
||||
/*=========================================================================*/
|
||||
|
||||
#define MSA301_REG_PARTID 0x01
|
||||
#define MSA301_REG_OUT_X_L 0x02
|
||||
#define MSA301_REG_OUT_X_H 0x03
|
||||
#define MSA301_REG_OUT_Y_L 0x04
|
||||
#define MSA301_REG_OUT_Y_H 0x05
|
||||
#define MSA301_REG_OUT_Z_L 0x06
|
||||
#define MSA301_REG_OUT_Z_H 0x07
|
||||
#define MSA301_REG_MOTIONINT 0x09
|
||||
#define MSA301_REG_DATAINT 0x0A
|
||||
#define MSA301_REG_CLICKSTATUS 0x0B
|
||||
#define MSA301_REG_RESRANGE 0x0F
|
||||
#define MSA301_REG_ODR 0x10
|
||||
#define MSA301_REG_POWERMODE 0x11
|
||||
#define MSA301_REG_INTSET0 0x16
|
||||
#define MSA301_REG_INTSET1 0x17
|
||||
#define MSA301_REG_INTMAP0 0x19
|
||||
#define MSA301_REG_INTMAP1 0x1A
|
||||
#define MSA301_REG_TAPDUR 0x2A
|
||||
#define MSA301_REG_TAPTH 0x2B
|
||||
#define MSA301_REG_PARTID 0x01
|
||||
#define MSA301_REG_OUT_X_L 0x02
|
||||
#define MSA301_REG_OUT_X_H 0x03
|
||||
#define MSA301_REG_OUT_Y_L 0x04
|
||||
#define MSA301_REG_OUT_Y_H 0x05
|
||||
#define MSA301_REG_OUT_Z_L 0x06
|
||||
#define MSA301_REG_OUT_Z_H 0x07
|
||||
#define MSA301_REG_MOTIONINT 0x09
|
||||
#define MSA301_REG_DATAINT 0x0A
|
||||
#define MSA301_REG_CLICKSTATUS 0x0B
|
||||
#define MSA301_REG_RESRANGE 0x0F
|
||||
#define MSA301_REG_ODR 0x10
|
||||
#define MSA301_REG_POWERMODE 0x11
|
||||
#define MSA301_REG_INTSET0 0x16
|
||||
#define MSA301_REG_INTSET1 0x17
|
||||
#define MSA301_REG_INTMAP0 0x19
|
||||
#define MSA301_REG_INTMAP1 0x1A
|
||||
#define MSA301_REG_TAPDUR 0x2A
|
||||
#define MSA301_REG_TAPTH 0x2B
|
||||
|
||||
typedef enum {
|
||||
MSA301_RANGE_2_G = 0b00, // +/- 2g (default value)
|
||||
MSA301_RANGE_4_G = 0b01, // +/- 4g
|
||||
MSA301_RANGE_8_G = 0b10, // +/- 8g
|
||||
MSA301_RANGE_16_G = 0b11, // +/- 16g
|
||||
MSA301_RANGE_2_G = 0b00, // +/- 2g (default value)
|
||||
MSA301_RANGE_4_G = 0b01, // +/- 4g
|
||||
MSA301_RANGE_8_G = 0b10, // +/- 8g
|
||||
MSA301_RANGE_16_G = 0b11, // +/- 16g
|
||||
} msa301_range_t;
|
||||
|
||||
typedef enum {
|
||||
MSA301_AXIS_X = 0x0,
|
||||
MSA301_AXIS_Y = 0x1,
|
||||
MSA301_AXIS_Z = 0x2,
|
||||
MSA301_AXIS_X = 0x0,
|
||||
MSA301_AXIS_Y = 0x1,
|
||||
MSA301_AXIS_Z = 0x2,
|
||||
} msa301_axis_t;
|
||||
|
||||
|
||||
/* Used with register 0x10 (MSA301_REG_ODR) to set datarate */
|
||||
typedef enum {
|
||||
MSA301_DATARATE_1_HZ = 0b0000, // 1 Hz
|
||||
MSA301_DATARATE_1_95_HZ = 0b0001, // 1.95 Hz
|
||||
MSA301_DATARATE_3_9_HZ = 0b0010, // 3.9 Hz
|
||||
MSA301_DATARATE_7_81_HZ = 0b0011, // 7.81 Hz
|
||||
MSA301_DATARATE_15_63_HZ = 0b0100, // 15.63 Hz
|
||||
MSA301_DATARATE_31_25_HZ = 0b0101, // 31.25 Hz
|
||||
MSA301_DATARATE_62_5_HZ = 0b0110, // 62.5 Hz
|
||||
MSA301_DATARATE_125_HZ = 0b0111, // 125 Hz
|
||||
MSA301_DATARATE_250_HZ = 0b1000, // 250 Hz
|
||||
MSA301_DATARATE_500_HZ = 0b1001, // 500 Hz
|
||||
MSA301_DATARATE_1000_HZ = 0b1010, // 1000 Hz
|
||||
MSA301_DATARATE_1_HZ = 0b0000, // 1 Hz
|
||||
MSA301_DATARATE_1_95_HZ = 0b0001, // 1.95 Hz
|
||||
MSA301_DATARATE_3_9_HZ = 0b0010, // 3.9 Hz
|
||||
MSA301_DATARATE_7_81_HZ = 0b0011, // 7.81 Hz
|
||||
MSA301_DATARATE_15_63_HZ = 0b0100, // 15.63 Hz
|
||||
MSA301_DATARATE_31_25_HZ = 0b0101, // 31.25 Hz
|
||||
MSA301_DATARATE_62_5_HZ = 0b0110, // 62.5 Hz
|
||||
MSA301_DATARATE_125_HZ = 0b0111, // 125 Hz
|
||||
MSA301_DATARATE_250_HZ = 0b1000, // 250 Hz
|
||||
MSA301_DATARATE_500_HZ = 0b1001, // 500 Hz
|
||||
MSA301_DATARATE_1000_HZ = 0b1010, // 1000 Hz
|
||||
} msa301_dataRate_t;
|
||||
|
||||
typedef enum {
|
||||
MSA301_BANDWIDTH_1_95_HZ = 0b0000, // 1.95 Hz
|
||||
MSA301_BANDWIDTH_3_9_HZ = 0b0011, // 3.9 Hz
|
||||
MSA301_BANDWIDTH_7_81_HZ = 0b0100, // 7.81 Hz
|
||||
MSA301_BANDWIDTH_15_63_HZ = 0b0101, // 15.63 Hz
|
||||
MSA301_BANDWIDTH_31_25_HZ = 0b0110, // 31.25 Hz
|
||||
MSA301_BANDWIDTH_62_5_HZ = 0b0111, // 62.5 Hz
|
||||
MSA301_BANDWIDTH_125_HZ = 0b1000, // 125 Hz
|
||||
MSA301_BANDWIDTH_250_HZ = 0b1001, // 250 Hz
|
||||
MSA301_BANDWIDTH_500_HZ = 0b1010, // 500 Hz
|
||||
MSA301_BANDWIDTH_1_95_HZ = 0b0000, // 1.95 Hz
|
||||
MSA301_BANDWIDTH_3_9_HZ = 0b0011, // 3.9 Hz
|
||||
MSA301_BANDWIDTH_7_81_HZ = 0b0100, // 7.81 Hz
|
||||
MSA301_BANDWIDTH_15_63_HZ = 0b0101, // 15.63 Hz
|
||||
MSA301_BANDWIDTH_31_25_HZ = 0b0110, // 31.25 Hz
|
||||
MSA301_BANDWIDTH_62_5_HZ = 0b0111, // 62.5 Hz
|
||||
MSA301_BANDWIDTH_125_HZ = 0b1000, // 125 Hz
|
||||
MSA301_BANDWIDTH_250_HZ = 0b1001, // 250 Hz
|
||||
MSA301_BANDWIDTH_500_HZ = 0b1010, // 500 Hz
|
||||
} msa301_bandwidth_t;
|
||||
|
||||
typedef enum {
|
||||
MSA301_NORMALMODE = 0b00,
|
||||
MSA301_LOWPOWERMODE = 0b01,
|
||||
MSA301_SUSPENDMODE = 0b010,
|
||||
MSA301_NORMALMODE = 0b00,
|
||||
MSA301_LOWPOWERMODE = 0b01,
|
||||
MSA301_SUSPENDMODE = 0b010,
|
||||
} msa301_powermode_t;
|
||||
|
||||
typedef enum {
|
||||
MSA301_RESOLUTION_14 = 0b00,
|
||||
MSA301_RESOLUTION_12 = 0b01,
|
||||
MSA301_RESOLUTION_10 = 0b10,
|
||||
MSA301_RESOLUTION_8 = 0b11,
|
||||
MSA301_RESOLUTION_14 = 0b00,
|
||||
MSA301_RESOLUTION_12 = 0b01,
|
||||
MSA301_RESOLUTION_10 = 0b10,
|
||||
MSA301_RESOLUTION_8 = 0b11,
|
||||
} msa301_resolution_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
MSA301_TAPDUR_50_MS = 0b000,
|
||||
MSA301_TAPDUR_100_MS = 0b001,
|
||||
MSA301_TAPDUR_150_MS = 0b010,
|
||||
MSA301_TAPDUR_200_MS = 0b011,
|
||||
MSA301_TAPDUR_250_MS = 0b100,
|
||||
MSA301_TAPDUR_375_MS = 0b101,
|
||||
MSA301_TAPDUR_500_MS = 0b110,
|
||||
MSA301_TAPDUR_700_MS = 0b111,
|
||||
MSA301_TAPDUR_50_MS = 0b000,
|
||||
MSA301_TAPDUR_100_MS = 0b001,
|
||||
MSA301_TAPDUR_150_MS = 0b010,
|
||||
MSA301_TAPDUR_200_MS = 0b011,
|
||||
MSA301_TAPDUR_250_MS = 0b100,
|
||||
MSA301_TAPDUR_375_MS = 0b101,
|
||||
MSA301_TAPDUR_500_MS = 0b110,
|
||||
MSA301_TAPDUR_700_MS = 0b111,
|
||||
} msa301_tapduration_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
MSA301_INT_ORIENT = 0b100000,
|
||||
MSA301_INT_SINGLETAP,
|
||||
|
|
@ -125,9 +121,9 @@ typedef enum {
|
|||
} msa301_interrupt_t;
|
||||
|
||||
class Adafruit_MSA301 : public Adafruit_Sensor {
|
||||
public:
|
||||
public:
|
||||
Adafruit_MSA301(void);
|
||||
bool begin(uint8_t i2c_addr=MSA301_I2CADDR_DEFAULT, TwoWire *wire = &Wire);
|
||||
bool begin(uint8_t i2c_addr = MSA301_I2CADDR_DEFAULT, TwoWire *wire = &Wire);
|
||||
|
||||
void setDataRate(msa301_dataRate_t dataRate);
|
||||
msa301_dataRate_t getDataRate(void);
|
||||
|
|
@ -146,17 +142,20 @@ class Adafruit_MSA301 : public Adafruit_Sensor {
|
|||
bool getEvent(sensors_event_t *event);
|
||||
void getSensor(sensor_t *sensor);
|
||||
|
||||
void enableInterrupts(bool singletap=false, bool doubletap=false,
|
||||
bool activeX=false, bool activeY=false, bool activeZ=false,
|
||||
bool newData=false, bool freefall=false, bool orient=false);
|
||||
void mapInterruptPin(bool singletap=false, bool doubletap=false, bool activity=false,
|
||||
bool newData=false, bool freefall=false, bool orient=false);
|
||||
|
||||
void enableInterrupts(bool singletap = false, bool doubletap = false,
|
||||
bool activeX = false, bool activeY = false,
|
||||
bool activeZ = false, bool newData = false,
|
||||
bool freefall = false, bool orient = false);
|
||||
void mapInterruptPin(bool singletap = false, bool doubletap = false,
|
||||
bool activity = false, bool newData = false,
|
||||
bool freefall = false, bool orient = false);
|
||||
|
||||
uint8_t getClick(void);
|
||||
uint8_t getMotionInterruptStatus(void) ;
|
||||
uint8_t getMotionInterruptStatus(void);
|
||||
uint8_t getDataInterruptStatus(void);
|
||||
|
||||
void setClick(bool tap_quiet, bool tap_shock, msa301_tapduration_t tapduration, uint8_t tapthresh);
|
||||
void setClick(bool tap_quiet, bool tap_shock,
|
||||
msa301_tapduration_t tapduration, uint8_t tapthresh);
|
||||
|
||||
/*
|
||||
|
||||
|
|
@ -164,11 +163,10 @@ class Adafruit_MSA301 : public Adafruit_Sensor {
|
|||
|
||||
*/
|
||||
|
||||
|
||||
int16_t x, y, z;
|
||||
float x_g, y_g, z_g;
|
||||
|
||||
private:
|
||||
private:
|
||||
Adafruit_I2CDevice *i2c_dev;
|
||||
|
||||
int32_t _sensorID;
|
||||
|
|
|
|||
Loading…
Reference in a new issue