aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--accel.c12
-rw-r--r--common.h2
-rw-r--r--gyro.c7
3 files changed, 11 insertions, 10 deletions
diff --git a/accel.c b/accel.c
index e90f961..c6f9bdb 100644
--- a/accel.c
+++ b/accel.c
@@ -121,7 +121,7 @@ void accelProcess () {
static uint8_t data[] = {0b01000100};
if (twRequest (TWM_WRITE, LIS302DL, LIS302DL_CTRLREG1, data,
- sizeof (data)/sizeof (*data))) {
+ length (data))) {
state = STARTING_A;
}
break;
@@ -133,7 +133,7 @@ void accelProcess () {
disableWakeup (WAKE_I2C);
static uint8_t data[] = {HORIZON_THRESHOLD, HORIZON_DURATION};
if (twRequest (TWM_WRITE, LIS302DL, LIS302DL_FFWUTHS1, data,
- sizeof (data)/sizeof (*data))) {
+ length (data))) {
state = STARTING_B;
}
}
@@ -145,7 +145,7 @@ void accelProcess () {
/* enable interrupt on z high event */
static uint8_t data[] = {1 << ZHIE};
if (twRequest (TWM_WRITE, LIS302DL, LIS302DL_FFWUCFG1, data,
- sizeof (data)/sizeof (*data))) {
+ length (data))) {
state = STARTING_C;
}
}
@@ -157,7 +157,7 @@ void accelProcess () {
disableWakeup (WAKE_I2C);
static uint8_t data[] = {SHAKE_THRESHOLD};
if (twRequest (TWM_WRITE, LIS302DL, LIS302DL_FFWUTHS2, data,
- sizeof (data)/sizeof (*data))) {
+ length (data))) {
state = STARTING_D;
}
}
@@ -169,7 +169,7 @@ void accelProcess () {
/* or events, enable interrupt on z high event */
static uint8_t data[] = {1 << ZHIE};
if (twRequest (TWM_WRITE, LIS302DL, LIS302DL_FFWUCFG2, data,
- sizeof (data)/sizeof (*data))) {
+ length (data))) {
state = STARTING_E;
}
}
@@ -181,7 +181,7 @@ void accelProcess () {
/* push-pull, low-active, FF_WU_1 on int1, FF_WU_2 on int2 */
static uint8_t data[] = {0b10010001};
if (twRequest (TWM_WRITE, LIS302DL, LIS302DL_CTRLREG3, data,
- sizeof (data)/sizeof (*data))) {
+ length (data))) {
state = STARTING_F;
}
}
diff --git a/common.h b/common.h
index 7b699ca..58a253e 100644
--- a/common.h
+++ b/common.h
@@ -67,6 +67,8 @@ extern volatile uint8_t wakeup;
void shutdownError ();
#define sign(x) ((x < 0) ? -1 : 1)
+/* get an array’s size/length */
+#define length(x) (sizeof(x)/sizeof(*x))
#endif /* COMMON_H */
diff --git a/gyro.c b/gyro.c
index f7add5e..93f6edb 100644
--- a/gyro.c
+++ b/gyro.c
@@ -121,9 +121,8 @@ bool gyroProcess () {
* select 2000dps
*/
static uint8_t data[] = {0b00001100, 0b0, 0b00001000, 0b00110000};
- const bool ret = twRequest (TWM_WRITE, L3GD20, L3GD20_CTRLREG1, data,
- sizeof (data)/sizeof (*data));
- if (ret) {
+ if (twRequest (TWM_WRITE, L3GD20, L3GD20_CTRLREG1, data,
+ length (data))) {
state = STARTING;
}
break;
@@ -165,7 +164,7 @@ bool gyroProcess () {
static uint8_t data[] = {0b00000000};
if (twRequest (TWM_WRITE, L3GD20, L3GD20_CTRLREG1, data,
- sizeof (data)/sizeof (*data))) {
+ length (data))) {
state = STOPPING;
}
} else if (shouldWakeup (WAKE_GYRO) && twRequest (TWM_READ, L3GD20,