diff options
-rw-r--r-- | accel.c | 12 | ||||
-rw-r--r-- | common.h | 2 | ||||
-rw-r--r-- | gyro.c | 7 |
3 files changed, 11 insertions, 10 deletions
@@ -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; } } @@ -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 */ @@ -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, |