Skip to content

Commit af28e53

Browse files
committed
Use int for accelerometer and gyro API's instead of short
1 parent c84af94 commit af28e53

File tree

6 files changed

+47
-26
lines changed

6 files changed

+47
-26
lines changed

libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void setup() {
5050
}
5151

5252
void loop() {
53-
short int axRaw, ayRaw, azRaw; // raw accelerometer values
53+
int axRaw, ayRaw, azRaw; // raw accelerometer values
5454
float ax, ay, az;
5555

5656
// read raw accelerometer measurements from device
@@ -74,7 +74,7 @@ void loop() {
7474
delay(5000);
7575
}
7676

77-
float convertRawAcceleration(short aRaw) {
77+
float convertRawAcceleration(int aRaw) {
7878
// since we are using 2G range
7979
// -2g maps to a raw value of -32768
8080
// +2g maps to a raw value of 32767

libraries/CurieIMU/examples/AccelerometerOrientation/AccelerometerOrientation.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ int orientation = - 1; // the board's orientation
5252
5: portrait, USB connector down
5353
*/
5454
// read accelerometer:
55-
short x = CurieIMU.readAccelerometer(X_AXIS);
56-
short y = CurieIMU.readAccelerometer(Y_AXIS);
57-
short z = CurieIMU.readAccelerometer(Z_AXIS);
55+
int x = CurieIMU.readAccelerometer(X_AXIS);
56+
int y = CurieIMU.readAccelerometer(Y_AXIS);
57+
int z = CurieIMU.readAccelerometer(Z_AXIS);
5858

5959
// calculate the absolute values, to determine the largest
6060
int absX = abs(x);
@@ -85,8 +85,8 @@ int orientation = - 1; // the board's orientation
8585
orientationString = "connector up";
8686
orientation = 4;
8787
} else {
88-
orientationString = "connector up";
89-
orientation = 4;
88+
orientationString = "connector down";
89+
orientation = 5;
9090
}
9191
}
9292

libraries/CurieIMU/examples/Gyro/Gyro.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void setup() {
4848
}
4949

5050
void loop() {
51-
short int gxRaw, gyRaw, gzRaw; // raw gyro values
51+
int gxRaw, gyRaw, gzRaw; // raw gyro values
5252
float gx, gy, gz;
5353

5454
// read raw gyro measurements from device
@@ -72,7 +72,7 @@ void loop() {
7272
delay(5000);
7373
}
7474

75-
float convertRawGyro(short gRaw) {
75+
float convertRawGyro(int gRaw) {
7676
// since we are using 250 degrees/seconds range
7777
// -250 maps to a raw value of -32768
7878
// +250 maps to a raw value of 32767

libraries/CurieIMU/examples/RawImuDataSerial/RawImuDataSerial.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
*/
3232

3333
#include "CurieIMU.h"
34-
short int ax, ay, az; // accelerometer values
35-
short int gx, gy, gz; // gyrometer values
34+
int ax, ay, az; // accelerometer values
35+
int gx, gy, gz; // gyrometer values
3636

3737
const int ledPin = 13; // activity LED pin
3838
boolean blinkState = false; // state of the LED

libraries/CurieIMU/src/CurieIMU.cpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -456,22 +456,43 @@ void CurieIMUClass::setStepDetectionMode(int mode)
456456
BMI160Class::setStepDetectionMode((BMI160StepMode)mode);
457457
}
458458

459-
void CurieIMUClass::readMotionSensor(short& ax, short& ay, short& az, short& gx, short& gy, short& gz)
459+
void CurieIMUClass::readMotionSensor(int& ax, int& ay, int& az, int& gx, int& gy, int& gz)
460460
{
461-
getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
461+
short sax, say, saz, sgx, sgy, sgz;
462+
463+
getMotion6(&sax, &say, &saz, &sgx, &sgy, &sgz);
464+
465+
ax = sax;
466+
ay = say;
467+
az = saz;
468+
gx = sgx;
469+
gy = sgy;
470+
gz = sgz;
462471
}
463472

464-
void CurieIMUClass::readAccelerometer(short& x, short& y, short& z)
473+
void CurieIMUClass::readAccelerometer(int& x, int& y, int& z)
465474
{
466-
getAcceleration(&x, &y, &z);
475+
short sx, sy, sz;
476+
477+
getAcceleration(&sx, &sy, &sz);
478+
479+
x = sx;
480+
y = sy;
481+
z = sz;
467482
}
468483

469-
void CurieIMUClass::readGyro(short& x, short& y, short& z)
484+
void CurieIMUClass::readGyro(int& x, int& y, int& z)
470485
{
471-
getRotation(&x, &y, &z);
486+
short sx, sy, sz;
487+
488+
getRotation(&sx, &sy, &sz);
489+
490+
x = sx;
491+
y = sy;
492+
z = sz;
472493
}
473494

474-
short CurieIMUClass::readAccelerometer(int axis)
495+
int CurieIMUClass::readAccelerometer(int axis)
475496
{
476497
if (axis == X_AXIS) {
477498
return getAccelerationX();
@@ -484,7 +505,7 @@ short CurieIMUClass::readAccelerometer(int axis)
484505
return 0;
485506
}
486507

487-
short CurieIMUClass::readGyro(int axis)
508+
int CurieIMUClass::readGyro(int axis)
488509
{
489510
if (axis == X_AXIS) {
490511
return getRotationX();
@@ -497,7 +518,7 @@ short CurieIMUClass::readGyro(int axis)
497518
return 0;
498519
}
499520

500-
short CurieIMUClass::readTemperature()
521+
int CurieIMUClass::readTemperature()
501522
{
502523
return getTemperature();
503524
}

libraries/CurieIMU/src/CurieIMU.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,13 @@ class CurieIMUClass : public BMI160Class {
292292
CurieIMUStepMode getStepDetectionMode();
293293
void setStepDetectionMode(int mode);
294294

295-
void readMotionSensor(short& ax, short& ay, short& az, short& gx, short& gy, short& gz);
296-
void readAccelerometer(short& x, short& y, short& z);
297-
void readGyro(short& x, short& y, short& z);
295+
void readMotionSensor(int& ax, int& ay, int& az, int& gx, int& gy, int& gz);
296+
void readAccelerometer(int& x, int& y, int& z);
297+
void readGyro(int& x, int& y, int& z);
298298

299-
short readAccelerometer(int axis);
300-
short readGyro(int axis);
301-
short readTemperature();
299+
int readAccelerometer(int axis);
300+
int readGyro(int axis);
301+
int readTemperature();
302302

303303
bool shockDetected(int axis, int direction);
304304
bool motionDetected(int axis, int direction);

0 commit comments

Comments
 (0)