Skip to content

Commit 5bae658

Browse files
committed
add guards to some defines
Should address #334 Make defines.h more powerfull
1 parent 9f20c12 commit 5bae658

File tree

6 files changed

+165
-53
lines changed

6 files changed

+165
-53
lines changed

src/debug.h

Lines changed: 118 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,74 +25,152 @@
2525
#include "consts.h"
2626
#include "logging/Level.h"
2727

28-
#define IMU_MPU6050_RUNTIME_CALIBRATION // Comment to revert to
29-
// startup/traditional-calibration
30-
#define BNO_USE_ARVR_STABILIZATION \
31-
true // Set to false to disable stabilization for BNO085+ IMUs
32-
#define USE_6_AXIS \
33-
true // uses 9 DoF (with mag) if false (only for ICM-20948 and BNO0xx currently)
34-
#define LOAD_BIAS true // Loads the bias values from NVS on start
35-
#define SAVE_BIAS true // Periodically saves bias calibration data to NVS
36-
#define BIAS_DEBUG false // Printing BIAS Variables to serial (ICM20948 only)
37-
#define ENABLE_TAP \
38-
false // monitor accel for (triple) tap events and send them. Uses more cpu,
39-
// disable if problems. Server does nothing with value so disabled atm
40-
#define SEND_ACCELERATION true // send linear acceleration to the server
41-
42-
// Debug information
43-
44-
#define LOG_LEVEL LOG_LEVEL_DEBUG
28+
#ifndef IMU_MPU6050_RUNTIME_CALIBRATION
29+
// Set to false to revert to startup/traditional-calibration
30+
#define IMU_MPU6050_RUNTIME_CALIBRATION true
31+
#endif
32+
33+
#ifndef BNO_USE_ARVR_STABILIZATION
34+
// Set to false to disable stabilization for BNO085+ IMUs
35+
#define BNO_USE_ARVR_STABILIZATION true
36+
#endif
37+
38+
#ifndef BNO_USE_MAGNETOMETER_CORRECTION
39+
// Set to true to enable magnetometer correction for BNO08x IMUs.
40+
// Only works with USE_6_AXIS set to true.
41+
#define BNO_USE_MAGNETOMETER_CORRECTION false
42+
#endif
43+
44+
#ifndef USE_6_AXIS
45+
// uses 9 DoF (with mag) if false (only for ICM-20948 and BNO0xx currently)
46+
#define USE_6_AXIS true
47+
#endif
48+
49+
#ifndef LOAD_BIAS
50+
// Loads the bias values from NVS on start
51+
#define LOAD_BIAS true
52+
#endif
53+
54+
#ifndef SAVE_BIAS
55+
// Periodically saves bias calibration data to NVS
56+
#define SAVE_BIAS true
57+
#endif
58+
59+
#ifndef BIAS_DEBUG
60+
// Printing BIAS Variables to serial (ICM20948 only)
61+
#define BIAS_DEBUG false
62+
#endif
63+
64+
#ifndef ENABLE_TAP
65+
// monitor accel for (triple) tap events and send them. Uses more cpu,
66+
// disable if problems. Server does nothing with value so disabled atm
67+
#define ENABLE_TAP false
68+
#endif
69+
70+
#ifndef SEND_ACCELERATION
71+
// send linear acceleration to the server
72+
#define SEND_ACCELERATION true
73+
#endif
74+
//Debug information
75+
76+
#ifndef LOG_LEVEL
77+
#define LOG_LEVEL LOG_LEVEL_DEBUG
78+
#endif
4579

4680
#if LOG_LEVEL == LOG_LEVEL_TRACE
47-
#define DEBUG_SENSOR
48-
#define DEBUG_NETWORK
49-
#define DEBUG_CONFIGURATION
81+
#define DEBUG_SENSOR
82+
#define DEBUG_NETWORK
83+
#define DEBUG_CONFIGURATION
5084
#endif
5185

52-
#define serialDebug false // Set to true to get Serial output for debugging
53-
#define serialBaudRate 115200
54-
#define LED_INTERVAL_STANDBY 10000
55-
#define PRINT_STATE_EVERY_MS 60000
86+
// Set to true to get Serial output for debugging
87+
#ifndef serialDebug
88+
#define serialDebug false
89+
#endif
90+
91+
#ifndef serialBaudRate
92+
#define serialBaudRate 115200
93+
#endif
94+
95+
#ifndef LED_INTERVAL_STANDBY
96+
#define LED_INTERVAL_STANDBY 10000
97+
#endif
98+
99+
#ifndef PRINT_STATE_EVERY_MS
100+
#define PRINT_STATE_EVERY_MS 60000
101+
#endif
56102

57103
// Determines how often we sample and send data
58-
#define samplingRateInMillis 10
104+
#ifndef samplingRateInMillis
105+
#define samplingRateInMillis 10
106+
#endif
59107

60108
// Sleeping options
61-
#define POWERSAVING_MODE POWER_SAVING_LEGACY // Minimum causes sporadic data pauses
109+
#ifndef POWERSAVING_MODE
110+
#define POWERSAVING_MODE POWER_SAVING_LEGACY // Minimum causes sporadic data pauses
111+
#endif
62112
#if POWERSAVING_MODE >= POWER_SAVING_MINIMUM
63-
#define TARGET_LOOPTIME_MICROS (samplingRateInMillis * 1000)
113+
#define TARGET_LOOPTIME_MICROS (samplingRateInMillis * 1000)
64114
#endif
65115

66116
// Packet bundling/aggregation
67-
#define PACKET_BUNDLING PACKET_BUNDLING_BUFFERED
117+
#ifndef PACKET_BUNDLING
118+
#define PACKET_BUNDLING PACKET_BUNDLING_BUFFERED
119+
#endif
120+
68121
// Extra tunable for PACKET_BUNDLING_BUFFERED (10000us = 10ms timeout, 100hz target)
69-
#define PACKET_BUNDLING_BUFFER_SIZE_MICROS 10000
122+
#ifndef PACKET_BUNDLING_BUFFER_SIZE_MICROS
123+
#define PACKET_BUNDLING_BUFFER_SIZE_MICROS 10000
124+
#endif
70125

71126
// Setup for the Magnetometer
72-
#define useFullCalibrationMatrix true
127+
#ifndef useFullCalibrationMatrix
128+
#define useFullCalibrationMatrix true
129+
#endif
73130

74131
// Battery configuration
75-
#define batterySampleRate 10000
76-
#define BATTERY_LOW_VOLTAGE_DEEP_SLEEP false
77-
#define BATTERY_LOW_POWER_VOLTAGE 3.3f // Voltage to raise error
132+
#ifndef batterySampleRate
133+
#define batterySampleRate 10000
134+
#endif
135+
#ifndef BATTERY_LOW_VOLTAGE_DEEP_SLEEP
136+
#define BATTERY_LOW_VOLTAGE_DEEP_SLEEP false
137+
#endif
138+
#ifndef BATTERY_LOW_POWER_VOLTAGE
139+
#define BATTERY_LOW_POWER_VOLTAGE 3.3f // Voltage to raise error
140+
#endif
78141

79142
// Send updates over network only when changes are substantial
80143
// If "false" updates are sent at the sensor update rate (usually 100 TPS)
81144
// If "true" updates will be less frequent in the time of little motion
82145
// Experimental
83-
#define OPTIMIZE_UPDATES true
146+
#ifndef OPTIMIZE_UPDATES
147+
#define OPTIMIZE_UPDATES true
148+
#endif
149+
150+
#ifndef I2C_SPEED
151+
#define I2C_SPEED 400000
152+
#endif
84153

85-
#define I2C_SPEED 400000
154+
#ifndef COMPLIANCE_MODE
155+
#define COMPLIANCE_MODE true
156+
#endif
86157

87-
#define COMPLIANCE_MODE true
88158
#define USE_ATTENUATION COMPLIANCE_MODE&& ESP8266
89-
#define ATTENUATION_N 10.0 / 4.0
90-
#define ATTENUATION_G 14.0 / 4.0
91-
#define ATTENUATION_B 40.0 / 4.0
159+
#ifndef ATTENUATION_N
160+
#define ATTENUATION_N 10.0 / 4.0
161+
#endif
162+
#ifndef ATTENUATION_G
163+
#define ATTENUATION_G 14.0 / 4.0
164+
#endif
165+
#ifndef ATTENUATION_B
166+
#define ATTENUATION_B 40.0 / 4.0
167+
#endif
92168

93169
// Send inspection packets over the network to a profiler
94170
// Not recommended for production
95-
#define ENABLE_INSPECTION false
171+
#ifndef ENABLE_INSPECTION
172+
#define ENABLE_INSPECTION false
173+
#endif
96174

97175
#define PROTOCOL_VERSION 18
98176

src/defines_bmi160.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,34 @@
2626
// BMI160 magnetometer type, applies to both main and aux trackers, mixed types are not
2727
// supported currently. If only 1 out of 2 trackers has a mag, tracker without a mag
2828
// should still function normally. NOT USED if USE_6_AXIS == true Pick one:
29+
#ifndef BMI160_MAG_TYPE
2930
#define BMI160_MAG_TYPE BMI160_MAG_TYPE_HMC
31+
#endif
3032
// #define BMI160_MAG_TYPE BMI160_MAG_TYPE_QMC
3133

3234
// Use VQF instead of mahony sensor fusion.
3335
// Features: rest bias estimation, magnetic distortion rejection.
36+
#ifndef BMI160_USE_VQF
3437
#define BMI160_USE_VQF true
38+
#endif
3539

3640
// Use BasicVQF instead of VQF (if BMI160_USE_VQF == true).
3741
// Disables the features above.
42+
#ifndef BMI160_USE_BASIC_VQF
3843
#define BMI160_USE_BASIC_VQF false
44+
#endif
3945

4046
// Use temperature calibration.
47+
#ifndef BMI160_USE_TEMPCAL
4148
#define BMI160_USE_TEMPCAL true
49+
#endif
4250

4351
// How long to run gyro calibration for.
4452
// Disables this calibration step if value is 0.
4553
// Default: 5
54+
#ifndef BMI160_CALIBRATION_GYRO_SECONDS
4655
#define BMI160_CALIBRATION_GYRO_SECONDS 5
56+
#endif
4757

4858
// Calibration method options:
4959
// - Skip: disable this calibration step;
@@ -52,22 +62,32 @@
5262
// Default: ACCEL_CALIBRATION_METHOD_6POINT
5363
// #define BMI160_ACCEL_CALIBRATION_METHOD ACCEL_CALIBRATION_METHOD_SKIP
5464
// #define BMI160_ACCEL_CALIBRATION_METHOD ACCEL_CALIBRATION_METHOD_ROTATION
65+
#ifndef BMI160_ACCEL_CALIBRATION_METHOD
5566
#define BMI160_ACCEL_CALIBRATION_METHOD ACCEL_CALIBRATION_METHOD_6POINT
67+
#endif
5668

5769
// How long to run magnetometer calibration for, if enabled and you have added a
5870
// magnetometer. Magnetometer not be used until you calibrate it. Disables this
5971
// calibration step if value is 0. NOT USED if USE_6_AXIS == true Default: 20
72+
#ifndef BMI160_CALIBRATION_MAG_SECONDS
6073
#define BMI160_CALIBRATION_MAG_SECONDS 20
74+
#endif
6175

6276
// Send temperature to the server as AXXYY,
6377
// where XX is calibration progress from 0 to 60, and YY is temperature,
6478
// A is 1: not in calibration mode or 2: calibration in progress.
79+
#ifndef BMI160_TEMPCAL_DEBUG
6580
#define BMI160_TEMPCAL_DEBUG false
81+
#endif
6682

6783
// Print debug info every second.
84+
#ifndef BMI160_DEBUG
6885
#define BMI160_DEBUG false
86+
#endif
6987

7088
// Use sensitivity calibration.
89+
#ifndef BMI160_USE_SENSCAL
7190
#define BMI160_USE_SENSCAL true
91+
#endif
7292

73-
#endif
93+
#endif

src/motionprocessing/GyroTemperatureCalibrator.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,34 @@
3434

3535
// Degrees C
3636
// default: 15.0f
37+
#ifndef TEMP_CALIBRATION_MIN
3738
#define TEMP_CALIBRATION_MIN 15.0f
39+
#endif
3840

3941
// Degrees C
4042
// default: 45.0f
43+
#ifndef TEMP_CALIBRATION_MAX
4144
#define TEMP_CALIBRATION_MAX 45.0f
45+
#endif
4246

4347
// Snap calibration to every 1/2 of degree: 20.00, 20.50, 21.00, etc
4448
// default: 0.5f
49+
#ifndef TEMP_CALIBRATION_STEP
4550
#define TEMP_CALIBRATION_STEP 0.5f
51+
#endif
4652

4753
// Record debug samples if current temperature is off by no more than this value;
4854
// if snapping point is 20.00 - samples will be recorded in range of 19.80 - 20.20
4955
// default: 0.2f
56+
#ifndef TEMP_CALIBRATION_MAX_DEVIATION_FROM_STEP
5057
#define TEMP_CALIBRATION_MAX_DEVIATION_FROM_STEP 0.2f
58+
#endif
5159

5260
// How long to average gyro samples for before saving a data point
5361
// default: 0.2f
62+
#ifndef TEMP_CALIBRATION_SECONDS_PER_STEP
5463
#define TEMP_CALIBRATION_SECONDS_PER_STEP 0.2f
64+
#endif
5565

5666
#if IMU == IMU_ICM20948
5767
// 16 bit 333 lsb/K, ~0.00508 degrees per bit

src/motionprocessing/RestDetection.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
#ifndef REST_DETECTION_H
99
#define REST_DETECTION_H
1010

11-
// #define REST_DETECTION_DISABLE_LPF
11+
#ifndef REST_DETECTION_DISABLE_LPF
12+
#define REST_DETECTION_DISABLE_LPF false
13+
#endif
1214

1315
#include <Arduino.h>
1416
#include <basicvqf.h>
@@ -54,7 +56,7 @@ class RestDetection {
5456
setup();
5557
}
5658

57-
#ifndef REST_DETECTION_DISABLE_LPF
59+
#if !REST_DETECTION_DISABLE_LPF
5860
void filterInitialState(
5961
sensor_real_t x0,
6062
const double b[3],
@@ -118,7 +120,7 @@ class RestDetection {
118120
#endif
119121

120122
void updateGyr(const sensor_real_t gyr[3]) {
121-
#ifdef REST_DETECTION_DISABLE_LPF
123+
#if REST_DETECTION_DISABLE_LPF
122124
gyrLastSquaredDeviation = square(gyr[0] - lastSample.gyr[0])
123125
+ square(gyr[1] - lastSample.gyr[1])
124126
+ square(gyr[2] - lastSample.gyr[2]);
@@ -168,7 +170,7 @@ class RestDetection {
168170
return;
169171
}
170172

171-
#ifdef REST_DETECTION_DISABLE_LPF
173+
#if REST_DETECTION_DISABLE_LPF
172174
accLastSquaredDeviation = square(acc[0] - lastSample.acc[0])
173175
+ square(acc[1] - lastSample.acc[1])
174176
+ square(acc[2] - lastSample.acc[2]);
@@ -216,7 +218,7 @@ class RestDetection {
216218

217219
bool getRestDetected() { return restDetected; }
218220

219-
#ifndef REST_DETECTION_DISABLE_LPF
221+
#if !REST_DETECTION_DISABLE_LPF
220222
void resetState() {
221223
restDetected = false;
222224

@@ -251,7 +253,7 @@ class RestDetection {
251253
#endif
252254

253255
void setup() {
254-
#ifndef REST_DETECTION_DISABLE_LPF
256+
#if !REST_DETECTION_DISABLE_LPF
255257
assert(gyrTs > 0);
256258
assert(accTs > 0);
257259

@@ -271,7 +273,7 @@ class RestDetection {
271273

272274
sensor_real_t gyrTs;
273275
sensor_real_t accTs;
274-
#ifndef REST_DETECTION_DISABLE_LPF
276+
#if !REST_DETECTION_DISABLE_LPF
275277
sensor_real_t restLastGyrLp[3];
276278
double restGyrLpState[3 * 2];
277279
double restGyrLpB[3];
@@ -288,4 +290,4 @@ class RestDetection {
288290
#endif
289291
};
290292

291-
#endif
293+
#endif

src/sensors/SensorFusion.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
#define SENSOR_DOUBLE_PRECISION 0
88

9+
#ifndef SENSOR_FUSION_TYPE
910
#define SENSOR_FUSION_TYPE SENSOR_FUSION_VQF
11+
#endif
1012

1113
#define SENSOR_FUSION_MAHONY 1
1214
#define SENSOR_FUSION_MADGWICK 2

0 commit comments

Comments
 (0)