Changed alignSensors to use temporary variables

This commit is contained in:
Martin Budden 2016-11-16 17:15:48 +00:00
parent 8480570510
commit 2498c66cb2
1 changed files with 23 additions and 25 deletions

View File

@ -64,54 +64,52 @@ static void alignBoard(int32_t *vec)
void alignSensors(const int32_t *src, int32_t *dest, uint8_t rotation) void alignSensors(const int32_t *src, int32_t *dest, uint8_t rotation)
{ {
int32_t x; const int32_t x = src[X];
const int32_t y = src[Y];
const int32_t z = src[Z];
// note src and dest may point to the same address // note src and dest may point to the same address
switch (rotation) { switch (rotation) {
default: default:
case CW0_DEG: case CW0_DEG:
dest[X] = src[X]; dest[X] = x;
dest[Y] = src[Y]; dest[Y] = y;
dest[Z] = src[Z]; dest[Z] = z;
break; break;
case CW90_DEG: case CW90_DEG:
x = src[X]; dest[X] = y;
dest[X] = src[Y];
dest[Y] = -x; dest[Y] = -x;
dest[Z] = src[Z]; dest[Z] = z;
break; break;
case CW180_DEG: case CW180_DEG:
dest[X] = -src[X]; dest[X] = -x;
dest[Y] = -src[Y]; dest[Y] = -y;
dest[Z] = src[Z]; dest[Z] = z;
break; break;
case CW270_DEG: case CW270_DEG:
x = src[X]; dest[X] = -y;
dest[X] = -src[Y];
dest[Y] = x; dest[Y] = x;
dest[Z] = src[Z]; dest[Z] = z;
break; break;
case CW0_DEG_FLIP: case CW0_DEG_FLIP:
dest[X] = -src[X]; dest[X] = -x;
dest[Y] = src[Y]; dest[Y] = y;
dest[Z] = -src[Z]; dest[Z] = -z;
break; break;
case CW90_DEG_FLIP: case CW90_DEG_FLIP:
x = src[X]; dest[X] = y;
dest[X] = src[Y];
dest[Y] = x; dest[Y] = x;
dest[Z] = -src[Z]; dest[Z] = -z;
break; break;
case CW180_DEG_FLIP: case CW180_DEG_FLIP:
dest[X] = src[X]; dest[X] = x;
dest[Y] = -src[Y]; dest[Y] = -y;
dest[Z] = -src[Z]; dest[Z] = -z;
break; break;
case CW270_DEG_FLIP: case CW270_DEG_FLIP:
x = src[X]; dest[X] = -y;
dest[X] = -src[Y];
dest[Y] = -x; dest[Y] = -x;
dest[Z] = -src[Z]; dest[Z] = -z;
break; break;
} }