mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 09:20:39 +03:00
bma250e,bmc150,bmg160,bmi055,bmm150,bmx055: C++ examples: use instance rather than allocation
Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
parent
a594036778
commit
e765dcf57b
@ -44,7 +44,7 @@ int main(int argc, char **argv)
|
|||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
// Instantiate an BMA250E using default I2C parameters
|
// Instantiate an BMA250E using default I2C parameters
|
||||||
upm::BMA250E *sensor = new upm::BMA250E();
|
upm::BMA250E sensor;
|
||||||
|
|
||||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||||
// for CS: BMA250E(0, -1, 10);
|
// for CS: BMA250E(0, -1, 10);
|
||||||
@ -54,9 +54,9 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
sensor->update();
|
sensor.update();
|
||||||
|
|
||||||
sensor->getAccelerometer(&x, &y, &z);
|
sensor.getAccelerometer(&x, &y, &z);
|
||||||
cout << "Accelerometer x: " << x
|
cout << "Accelerometer x: " << x
|
||||||
<< " y: " << y
|
<< " y: " << y
|
||||||
<< " z: " << z
|
<< " z: " << z
|
||||||
@ -64,8 +64,8 @@ int main(int argc, char **argv)
|
|||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
// we show both C and F for temperature
|
// we show both C and F for temperature
|
||||||
cout << "Compensation Temperature: " << sensor->getTemperature()
|
cout << "Compensation Temperature: " << sensor.getTemperature()
|
||||||
<< " C / " << sensor->getTemperature(true) << " F"
|
<< " C / " << sensor.getTemperature(true) << " F"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
@ -77,7 +77,5 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -44,23 +44,23 @@ int main(int argc, char **argv)
|
|||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
// Instantiate an BMC150 using default I2C parameters
|
// Instantiate an BMC150 using default I2C parameters
|
||||||
upm::BMC150 *sensor = new upm::BMC150();
|
upm::BMC150 sensor;
|
||||||
|
|
||||||
// now output data every 250 milliseconds
|
// now output data every 250 milliseconds
|
||||||
while (shouldRun)
|
while (shouldRun)
|
||||||
{
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
sensor->update();
|
sensor.update();
|
||||||
|
|
||||||
sensor->getAccelerometer(&x, &y, &z);
|
sensor.getAccelerometer(&x, &y, &z);
|
||||||
cout << "Accelerometer x: " << x
|
cout << "Accelerometer x: " << x
|
||||||
<< " y: " << y
|
<< " y: " << y
|
||||||
<< " z: " << z
|
<< " z: " << z
|
||||||
<< " g"
|
<< " g"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
sensor->getMagnetometer(&x, &y, &z);
|
sensor.getMagnetometer(&x, &y, &z);
|
||||||
cout << "Magnetometer x: " << x
|
cout << "Magnetometer x: " << x
|
||||||
<< " y: " << y
|
<< " y: " << y
|
||||||
<< " z: " << z
|
<< " z: " << z
|
||||||
@ -76,7 +76,5 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ int main(int argc, char **argv)
|
|||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
// Instantiate an BMG160 using default I2C parameters
|
// Instantiate an BMG160 using default I2C parameters
|
||||||
upm::BMG160 *sensor = new upm::BMG160();
|
upm::BMG160 sensor;
|
||||||
|
|
||||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||||
// for CS: BMG160(0, -1, 10);
|
// for CS: BMG160(0, -1, 10);
|
||||||
@ -54,9 +54,9 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
sensor->update();
|
sensor.update();
|
||||||
|
|
||||||
sensor->getGyroscope(&x, &y, &z);
|
sensor.getGyroscope(&x, &y, &z);
|
||||||
cout << "Gyroscope x: " << x
|
cout << "Gyroscope x: " << x
|
||||||
<< " y: " << y
|
<< " y: " << y
|
||||||
<< " z: " << z
|
<< " z: " << z
|
||||||
@ -64,8 +64,8 @@ int main(int argc, char **argv)
|
|||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
// we show both C and F for temperature
|
// we show both C and F for temperature
|
||||||
cout << "Compensation Temperature: " << sensor->getTemperature()
|
cout << "Compensation Temperature: " << sensor.getTemperature()
|
||||||
<< " C / " << sensor->getTemperature(true) << " F"
|
<< " C / " << sensor.getTemperature(true) << " F"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
@ -77,7 +77,5 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -44,23 +44,23 @@ int main(int argc, char **argv)
|
|||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
// Instantiate an BMI055 using default I2C parameters
|
// Instantiate an BMI055 using default I2C parameters
|
||||||
upm::BMI055 *sensor = new upm::BMI055();
|
upm::BMI055 sensor;
|
||||||
|
|
||||||
// now output data every 250 milliseconds
|
// now output data every 250 milliseconds
|
||||||
while (shouldRun)
|
while (shouldRun)
|
||||||
{
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
sensor->update();
|
sensor.update();
|
||||||
|
|
||||||
sensor->getAccelerometer(&x, &y, &z);
|
sensor.getAccelerometer(&x, &y, &z);
|
||||||
cout << "Accelerometer x: " << x
|
cout << "Accelerometer x: " << x
|
||||||
<< " y: " << y
|
<< " y: " << y
|
||||||
<< " z: " << z
|
<< " z: " << z
|
||||||
<< " g"
|
<< " g"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
sensor->getGyroscope(&x, &y, &z);
|
sensor.getGyroscope(&x, &y, &z);
|
||||||
cout << "Gyroscope x: " << x
|
cout << "Gyroscope x: " << x
|
||||||
<< " y: " << y
|
<< " y: " << y
|
||||||
<< " z: " << z
|
<< " z: " << z
|
||||||
@ -76,7 +76,5 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ int main(int argc, char **argv)
|
|||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
// Instantiate an BMM150 using default I2C parameters
|
// Instantiate an BMM150 using default I2C parameters
|
||||||
upm::BMM150 *sensor = new upm::BMM150();
|
upm::BMM150 sensor;
|
||||||
|
|
||||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||||
// for CS: BMM150(0, -1, 10);
|
// for CS: BMM150(0, -1, 10);
|
||||||
@ -54,9 +54,9 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
sensor->update();
|
sensor.update();
|
||||||
|
|
||||||
sensor->getMagnetometer(&x, &y, &z);
|
sensor.getMagnetometer(&x, &y, &z);
|
||||||
cout << "Magnetometer x: " << x
|
cout << "Magnetometer x: " << x
|
||||||
<< " y: " << y
|
<< " y: " << y
|
||||||
<< " z: " << z
|
<< " z: " << z
|
||||||
@ -72,7 +72,5 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -44,30 +44,30 @@ int main(int argc, char **argv)
|
|||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
// Instantiate an BMX055 using default I2C parameters
|
// Instantiate an BMX055 using default I2C parameters
|
||||||
upm::BMX055 *sensor = new upm::BMX055();
|
upm::BMX055 sensor;
|
||||||
|
|
||||||
// now output data every 250 milliseconds
|
// now output data every 250 milliseconds
|
||||||
while (shouldRun)
|
while (shouldRun)
|
||||||
{
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
sensor->update();
|
sensor.update();
|
||||||
|
|
||||||
sensor->getAccelerometer(&x, &y, &z);
|
sensor.getAccelerometer(&x, &y, &z);
|
||||||
cout << "Accelerometer x: " << x
|
cout << "Accelerometer x: " << x
|
||||||
<< " y: " << y
|
<< " y: " << y
|
||||||
<< " z: " << z
|
<< " z: " << z
|
||||||
<< " g"
|
<< " g"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
sensor->getGyroscope(&x, &y, &z);
|
sensor.getGyroscope(&x, &y, &z);
|
||||||
cout << "Gyroscope x: " << x
|
cout << "Gyroscope x: " << x
|
||||||
<< " y: " << y
|
<< " y: " << y
|
||||||
<< " z: " << z
|
<< " z: " << z
|
||||||
<< " degrees/s"
|
<< " degrees/s"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
sensor->getMagnetometer(&x, &y, &z);
|
sensor.getMagnetometer(&x, &y, &z);
|
||||||
cout << "Magnetometer x: " << x
|
cout << "Magnetometer x: " << x
|
||||||
<< " y: " << y
|
<< " y: " << y
|
||||||
<< " z: " << z
|
<< " z: " << z
|
||||||
@ -83,7 +83,5 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user