diff options
author | CNLohr <charles@cnlohr.com> | 2018-02-24 12:26:32 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-24 12:26:32 -0500 |
commit | 3fbd36f71cfe168ada14b8f58f023bb05e4d322b (patch) | |
tree | 0d830ad923f207d74cc8493e35757f22fc02369a /src/survive_vive.c | |
parent | 4da907623f5ce8a71ab9f5ec60112df45060b2aa (diff) | |
parent | dabb0764a080ad219e1bb477e8cf7386a1a4dc7c (diff) | |
download | libsurvive-3fbd36f71cfe168ada14b8f58f023bb05e4d322b.tar.gz libsurvive-3fbd36f71cfe168ada14b8f58f023bb05e4d322b.tar.bz2 |
Merge pull request #99 from jdavidberger/misc-bugfix
Fixed two minor / potential bugs
Diffstat (limited to 'src/survive_vive.c')
-rwxr-xr-x | src/survive_vive.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/survive_vive.c b/src/survive_vive.c index 843482a..5be2d03 100755 --- a/src/survive_vive.c +++ b/src/survive_vive.c @@ -902,8 +902,16 @@ int survive_get_config( char ** config, SurviveViveData * sv, int devno, int ifa /////////////////////////////////////////////////////////////////////////////// #define POP1 (*(readdata++)) -#define POP2 (*(((uint16_t*)((readdata+=2)-2)))) -#define POP4 (*(((uint32_t*)((readdata+=4)-4)))) + + +struct __attribute__((__packed__)) unaligned_16_t { + uint16_t v; +}; +struct __attribute__((__packed__)) unaligned_32_t { + uint32_t v; +}; +#define POP2 ((((( struct unaligned_16_t*)((readdata+=2)-2))))->v) +#define POP4 ((((( struct unaligned_32_t*)((readdata+=4)-4))))->v) void calibrate_acc(SurviveObject* so, FLT* agm) { if (so->acc_bias != NULL) { @@ -1431,7 +1439,7 @@ void survive_data_cb( SurviveUSBInterface * si ) //printf( "%d -> ", size ); for( i = 0; i < 3; i++ ) { - int16_t * acceldata = (int16_t*)readdata; + struct unaligned_16_t * acceldata = (struct unaligned_16_t *)readdata; readdata += 12; uint32_t timecode = POP4; uint8_t code = POP1; @@ -1443,8 +1451,8 @@ void survive_data_cb( SurviveUSBInterface * si ) obj->oldcode = code; //XXX XXX BIG TODO!!! Actually recal gyro data. - FLT agm[9] = { acceldata[0], acceldata[1], acceldata[2], - acceldata[3], acceldata[4], acceldata[5], + FLT agm[9] = { acceldata[0].v, acceldata[1].v, acceldata[2].v, + acceldata[3].v, acceldata[4].v, acceldata[5].v, 0,0,0 }; agm[0]*=(float)(1./8192.0); |