Skip to content

Commit edcf7d9

Browse files
committed
WIP: Acc+debug tweaks
1 parent 2b217fc commit edcf7d9

File tree

7 files changed

+64
-67
lines changed

7 files changed

+64
-67
lines changed

platformio.ini

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,14 +608,14 @@ build_flags =
608608
-DDEBUG_RP2040_CORE
609609
-DDEBUG_RP2040_WIFI
610610
-DLWIP_DEBUG
611-
-DDEBUG_RP2040_PORT=Serial1
612-
-DDEBUG_RP2040_UART_1
613-
-DDEBUG_RP2040_UART=1
611+
; -DDEBUG_RP2040_PORT=Serial1
612+
; -DDEBUG_RP2040_UART_1
613+
; -DDEBUG_RP2040_UART=1
614614
-Og
615615
; Enable debug stack protection
616616
-fstack-protector
617617
; Enable Exceptions
618-
-DPIO_FRAMEWORK_ARDUINO_ENABLE_EXCEPTIONS
618+
; -DPIO_FRAMEWORK_ARDUINO_ENABLE_EXCEPTIONS
619619
; Enable RTTI
620620
-DPIO_FRAMEWORK_ARDUINO_ENABLE_RTTI
621621
; ; Enable default USB Stack of Pico SDK USB Stack with none of below usb options
@@ -624,3 +624,4 @@ build_flags =
624624
; ; No USB stack
625625
; build_flags = -DPIO_FRAMEWORK_ARDUINO_NO_USB
626626
; -DPIO_FRAMEWORK_ARDUINO_ENABLE_IPV6
627+
-DBUILD_OFFLINE_ONLY

src/components/i2c/controller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,12 @@ static const std::unordered_map<uint16_t, std::vector<const char *>>
458458
{0x12, {"pmsa003i"}},
459459
{0x13, {"vncl4020"}},
460460
{0x18, {"ds2484", "mcp9808", "mprls", "lis3dh"}},
461-
{0x19, {"mcp9808", "lis3dh", "lsm303dlh", "lsm303agr"}},
461+
{0x19, {"mcp9808", "lsm303agr", "lsm303dlh", "lis3dh"}}, // LIS3DH last - seems to match LSM303AGR
462462
{0x1A, {"mcp9808"}},
463463
{0x1B, {"mcp9808"}},
464464
{0x1C, {"mcp9808", "lis3mdl"}},
465465
{0x1D, {"mcp9808"}},
466-
{0x1E, {"mcp9808", "lis2mdl", "lis3mdl"}},
466+
{0x1E, {"mcp9808", "lis3mdl", "lis2mdl"}}, // "lsm303dlh", "lsm303agr", but rely on first addr
467467
{0x1F, {"mcp9808"}},
468468
{0x23, {"bh1750"}},
469469
{0x28, {"pct2075"}},

src/components/i2c/drivers/drvLsm303agr.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <math.h>
1010

11-
#define LSM303AGR_ACCEL_DEFAULT_ADDR LSM303_ADDRESS_ACCEL
11+
#define LSM303AGR_ACCEL_DEFAULT_ADDR 0x19 ///< LSM303AGR default address
1212
#define LSM303AGR_MAG_DEFAULT_ADDR 0x1E ///< LIS2MDL default address
1313

1414
/******************************************************************************/
@@ -52,13 +52,11 @@ bool drvLsm303agr::begin() {
5252

5353
// TODO: if _address isn't default (or alt), shift mag by same offset.
5454
// to support adress translators. Alternatively compound components.
55-
const uint8_t accel_addr =
56-
_address == 0 ? LSM303AGR_ACCEL_DEFAULT_ADDR : (uint8_t)_address;
57-
55+
5856
WS_DEBUG_PRINT("[drvLsm303agr] Initialising accel @ 0x");
59-
WS_DEBUG_PRINTHEX(accel_addr);
57+
WS_DEBUG_PRINTHEX(LSM303AGR_ACCEL_DEFAULT_ADDR);
6058
WS_DEBUG_PRINTLN("...");
61-
if (!_accel->begin(accel_addr, _i2c)) {
59+
if (!_accel->begin(LSM303AGR_ACCEL_DEFAULT_ADDR, _i2c)) {
6260
WS_DEBUG_PRINTLN("[drvLsm303agr] Failed to initialise accelerometer");
6361
teardown();
6462
return false;

src/components/i2c/drivers/drvLsm303dlh.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,29 @@ void drvLsm303dlh::teardown() {
4141
*/
4242
/******************************************************************************/
4343
bool drvLsm303dlh::begin() {
44+
WS_DEBUG_PRINTLN("[drvLsm303dlh] Initializing LSM303DLH driver...");
45+
WS_PRINTER.flush();
46+
47+
WS_DEBUG_PRINTLN("[drvLsm303dlh] Tearing down any existing sensor instances...");
48+
WS_PRINTER.flush();
4449
teardown();
4550

51+
WS_DEBUG_PRINTLN("[drvLsm303dlh] Creating new sensor instances...");
52+
WS_PRINTER.flush();
4653
_accel = new Adafruit_LSM303_Accel_Unified();
54+
WS_DEBUG_PRINTLN("[drvLsm303dlh] Created accelerometer instance, DLH mag next");
55+
WS_PRINTER.flush();
4756
_mag = new Adafruit_LSM303DLH_Mag_Unified();
57+
WS_DEBUG_PRINTLN("[drvLsm303dlh] Created magnetometer instance");
58+
WS_PRINTER.flush();
4859
if (!_accel || !_mag) {
4960
teardown();
5061
return false;
5162
}
52-
53-
// TODO: if _address isn't default (or alt), shift mag by same offset.
54-
// to support adress translators. Alternatively compound components.
55-
const uint8_t accel_addr =
56-
_address == 0 ? LSM303DLH_ACCEL_DEFAULT_ADDR : (uint8_t)_address;
57-
58-
WS_DEBUG_PRINT("[drvLsm303dlh] Initialising accel @ 0x");
59-
WS_DEBUG_PRINTHEX(accel_addr);
63+
WS_DEBUG_PRINT("[drvLsm303dlh] Initialising accelerometer @ 0x");
64+
WS_DEBUG_PRINTHEX(LSM303DLH_ACCEL_DEFAULT_ADDR);
6065
WS_DEBUG_PRINTLN("...");
61-
if (!_accel->begin(accel_addr, _i2c)) {
66+
if (!_accel->begin(LSM303DLH_ACCEL_DEFAULT_ADDR, _i2c)) {
6267
WS_DEBUG_PRINTLN("[drvLsm303dlh] Failed to initialise accelerometer");
6368
teardown();
6469
return false;

src/components/i2c/drivers/drvLsm9ds1.cpp

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ bool drvLsm9ds1::begin() {
3737
}
3838

3939
// Mirror the configuration used by the reference example
40-
_lsm->setupAccel(_lsm->LSM9DS1_ACCELRANGE_2G,
41-
_lsm->LSM9DS1_ACCELDATARATE_10HZ);
40+
_lsm->setupAccel(_lsm->LSM9DS1_ACCELRANGE_4G,
41+
_lsm->LSM9DS1_ACCELDATARATE_119HZ);
4242
_lsm->setupMag(_lsm->LSM9DS1_MAGGAIN_4GAUSS);
4343
_lsm->setupGyro(_lsm->LSM9DS1_GYROSCALE_245DPS);
4444

@@ -50,6 +50,7 @@ bool drvLsm9ds1::readAllEvents(sensors_event_t *accel, sensors_event_t *mag,
5050
if (!_lsm) {
5151
return false;
5252
}
53+
5354
return _lsm->getEvent(accel, mag, gyro, temp);
5455
}
5556

@@ -81,47 +82,35 @@ bool drvLsm9ds1::getEventRaw(sensors_event_t *rawEvent) {
8182

8283
/******************************************************************************/
8384
/*!
84-
@brief Gets the LSM9DS1's boolean sensor event.
85-
@param booleanEvent
86-
Pointer to the sensor event.
85+
@brief Gets the LSM9DS1's accelerometer sensor event (x,y,z in m/s^2).
86+
@param accelEvent
87+
Pointer to the accelerometer sensor event.
8788
@returns True if the sensor event was obtained successfully, False
8889
otherwise.
8990
*/
9091
/******************************************************************************/
91-
bool drvLsm9ds1::getEventBoolean(sensors_event_t *booleanEvent) {
92-
WS_DEBUG_PRINTLN("[drvLsm9ds1] Checking for tap event...");
93-
sensors_event_t accel, mag, gyro, temp;
94-
if (!readAllEvents(&accel, &mag, &gyro, &temp)) {
92+
bool drvLsm9ds1::getEventAccelerometer(sensors_event_t *accelEvent) {
93+
WS_DEBUG_PRINTLN("[drvLsm9ds1] Getting accelerometer event...");
94+
sensors_event_t mag, gyro, temp;
95+
if (!readAllEvents(accelEvent, &mag, &gyro, &temp)) {
9596
return false;
9697
}
97-
98-
float mag_accel = sqrtf(accel.acceleration.x * accel.acceleration.x +
99-
accel.acceleration.y * accel.acceleration.y +
100-
accel.acceleration.z * accel.acceleration.z);
101-
102-
bool tap_detected = (mag_accel > LSM9DS1_TAP_THRESHOLD_MSS);
103-
booleanEvent->data[0] = tap_detected ? 1.0f : 0.0f;
104-
105-
if (tap_detected) {
106-
WS_DEBUG_PRINTLN("[drvLsm9ds1] Tap event detected!");
107-
}
108-
10998
return true;
11099
}
111100

112101
/******************************************************************************/
113102
/*!
114-
@brief Gets the LSM9DS1's accelerometer sensor event (x,y,z in m/s^2).
115-
@param accelEvent
116-
Pointer to the accelerometer sensor event.
103+
@brief Gets the LSM9DS1's temperature sensor event (not necessarily *C).
104+
@param tempEvent
105+
Pointer to the temperature sensor event.
117106
@returns True if the sensor event was obtained successfully, False
118107
otherwise.
119108
*/
120109
/******************************************************************************/
121-
bool drvLsm9ds1::getEventAccelerometer(sensors_event_t *accelEvent) {
122-
WS_DEBUG_PRINTLN("[drvLsm9ds1] Getting accelerometer event...");
123-
sensors_event_t mag, gyro, temp;
124-
if (!readAllEvents(accelEvent, &mag, &gyro, &temp)) {
110+
bool drvLsm9ds1::getEventAmbientTemp(sensors_event_t *tempEvent) {
111+
WS_DEBUG_PRINTLN("[drvLsm9ds1] Getting temperature event...");
112+
sensors_event_t accel, mag, gyro;
113+
if (!readAllEvents(&accel, &mag, &gyro, tempEvent)) {
125114
return false;
126115
}
127116
return true;
@@ -164,7 +153,13 @@ bool drvLsm9ds1::getEventMagneticField(sensors_event_t *magEvent) {
164153
}
165154

166155
void drvLsm9ds1::ConfigureDefaultSensorTypes() {
167-
_default_sensor_types_count = 1;
156+
_default_sensor_types_count = 4;
168157
_default_sensor_types[0] =
169158
wippersnapper_sensor_SensorType_SENSOR_TYPE_ACCELEROMETER;
159+
_default_sensor_types[1] =
160+
wippersnapper_sensor_SensorType_SENSOR_TYPE_MAGNETIC_FIELD;
161+
_default_sensor_types[2] =
162+
wippersnapper_sensor_SensorType_SENSOR_TYPE_GYROSCOPE;
163+
_default_sensor_types[3] =
164+
wippersnapper_sensor_SensorType_SENSOR_TYPE_AMBIENT_TEMPERATURE;
170165
}

src/components/i2c/drivers/drvLsm9ds1.h

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
class Adafruit_LSM9DS1; // forward
2323

24-
// Approximate acceleration magnitude (m/s^2) that triggers a tap event
25-
#define LSM9DS1_TAP_THRESHOLD_MSS 15.0f
26-
2724
/**************************************************************************/
2825
/*!
2926
@brief Class that provides a driver interface for a LSM9DS1 IMU.
@@ -63,17 +60,6 @@ class drvLsm9ds1 : public drvBase {
6360
/*******************************************************************************/
6461
bool begin() override;
6562

66-
/******************************************************************************/
67-
/*!
68-
@brief Gets the LSM9DS1's boolean sensor event.
69-
@param booleanEvent
70-
Pointer to the sensor event.
71-
@returns True if the sensor event was obtained successfully, False
72-
otherwise.
73-
*/
74-
/******************************************************************************/
75-
bool getEventBoolean(sensors_event_t *booleanEvent) override;
76-
7763
/*******************************************************************************/
7864
/*!
7965
@brief Gets the LSM9DS1's raw sensor event (magnitude stored in
@@ -96,6 +82,17 @@ class drvLsm9ds1 : public drvBase {
9682
/*******************************************************************************/
9783
bool getEventAccelerometer(sensors_event_t *accelEvent) override;
9884

85+
/*******************************************************************************/
86+
/*!
87+
@brief Gets the LSM9DS1's temperature sensor event (not necessarily *C).
88+
@param tempEvent
89+
Pointer to the temperature sensor event.
90+
@returns True if the sensor event was obtained successfully, False
91+
otherwise.
92+
*/
93+
/*******************************************************************************/
94+
bool getEventAmbientTemp(sensors_event_t *tempEvent) override;
95+
9996
/*******************************************************************************/
10097
/*!
10198
@brief Gets the LSM9DS1's gyroscope sensor event (x,y,z in rad/s).
@@ -125,6 +122,7 @@ class drvLsm9ds1 : public drvBase {
125122

126123
bool readAllEvents(sensors_event_t *accel, sensors_event_t *mag,
127124
sensors_event_t *gyro, sensors_event_t *temp);
125+
128126
};
129127

130128
#endif // DRV_LSM9DS1_H

src/helpers/ws_helper_macros.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
// Define actual debug output functions when necessary.
88
#ifdef WS_DEBUG
99
#define WS_DEBUG_PRINT(...) \
10-
{ WS_PRINTER.print(__VA_ARGS__); } ///< Prints debug output.
10+
{ WS_PRINTER.print(__VA_ARGS__);WS_PRINTER.flush();delay(5); } ///< Prints debug output.
1111
#define WS_DEBUG_PRINTLN(...) \
12-
{ WS_PRINTER.println(__VA_ARGS__); } ///< Prints line from debug output.
12+
{ WS_PRINTER.println(__VA_ARGS__);WS_PRINTER.flush();delay(5); } ///< Prints line from debug output.
1313
#define WS_DEBUG_PRINTHEX(...) \
14-
{ WS_PRINTER.print(__VA_ARGS__, HEX); } ///< Prints debug output.
14+
{ WS_PRINTER.print(__VA_ARGS__, HEX);WS_PRINTER.flush();delay(5); } ///< Prints debug output.
1515
#else
1616
#define WS_DEBUG_PRINT(...) \
1717
{} ///< Prints debug output

0 commit comments

Comments
 (0)