diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2014-06-17 15:29:50 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2014-06-17 15:29:50 +0200 |
commit | d664b474657eff9988c14b40e5d050dc5571f778 (patch) | |
tree | 268e7b0bd66b2434ad36161e8c47e736c54f7867 /gyro.c | |
parent | 3362013554bd40ce17894f67b3b8dcf568ccdb5c (diff) | |
download | hourglass-d664b474657eff9988c14b40e5d050dc5571f778.tar.gz hourglass-d664b474657eff9988c14b40e5d050dc5571f778.tar.bz2 hourglass-d664b474657eff9988c14b40e5d050dc5571f778.zip |
ui: Added
Seems to work mostly now.
Diffstat (limited to 'gyro.c')
-rw-r--r-- | gyro.c | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -24,7 +24,7 @@ static volatile int16_t zval = 0; /* accumulated z value */ static int32_t zaccum = 0; /* calculated zticks */ -static int8_t zticks = 0; +static int16_t zticks = 0; /* currently reading from i2c */ static bool reading = false; @@ -66,16 +66,18 @@ void gyroStart () { */ static void gyroProcessTicks () { const uint8_t shift = 14; + const uint32_t max = (1 << shift); + const uint32_t mask = ~(max-1); - if (zaccum > (1 << shift)) { + if (zaccum > (int32_t) max) { const uint32_t a = abs (zaccum); zticks += a >> shift; /* mask shift bits */ - zaccum -= a & (~0x3ff); - } else if (zaccum < -(1 << shift)) { + zaccum -= a & mask; + } else if (zaccum < -((int32_t) max)) { const uint32_t a = abs (zaccum); zticks -= a >> shift; - zaccum += a & (~0x3ff); + zaccum += a & mask; } } @@ -123,7 +125,11 @@ int16_t gyroGetZRaw () { return zval; } -int8_t gyroGetZTicks () { +int16_t gyroGetZTicks () { return zticks; } +void gyroResetZTicks () { + zticks = 0; +} + |