mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 01:11:10 +03:00
kxtj3: fixed requested issues
* Virtual destructor * Add header guards * Constructor default values * Remove methods with pointer parameters in C++ code Signed-off-by: Assam Boudjelthia <assam.boudjelthia@fi.rohmeurope.com> Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:

committed by
Noel Eck

parent
09e536b4ff
commit
01cc3a0734
@ -22,6 +22,8 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include "kxtj3.hpp"
|
||||
@ -38,17 +40,17 @@ void signal_int_handler(int signo)
|
||||
isStopped = true;
|
||||
}
|
||||
|
||||
void print_acceleration_data(upm::KXTJ3 *dev)
|
||||
void print_acceleration_data(upm::KXTJ3 &dev)
|
||||
{
|
||||
float wait_time = dev->GetAccelerationSamplePeriod() * SECOND_IN_MICRO_S;
|
||||
uint8_t sample_counter = 0;
|
||||
float wait_time = dev.GetAccelerationSamplePeriod() * SECOND_IN_MICRO_S;
|
||||
int sample_counter = SAMPLE_COUNT;
|
||||
std::vector<float> xyz;
|
||||
while (sample_counter < SAMPLE_COUNT && !isStopped)
|
||||
while ((sample_counter-- > 0) && !isStopped)
|
||||
{
|
||||
xyz = dev->GetAccelerationVector();
|
||||
printf("%.02f | %.02f | %.02f\n", xyz[0], xyz[1], xyz[2]);
|
||||
xyz = dev.GetAccelerationVector();
|
||||
std::cout << std::fixed << std::setprecision(3)
|
||||
<< xyz[0] << " | " << xyz[1] << " | " << xyz[2] << std::endl;
|
||||
usleep(wait_time);
|
||||
sample_counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,21 +58,15 @@ int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, signal_int_handler);
|
||||
|
||||
printf("Sensor init\n");
|
||||
upm::KXTJ3 *dev = new upm::KXTJ3(I2C_BUS, SENSOR_ADDR);
|
||||
if (!dev)
|
||||
{
|
||||
printf("kxtj3_init() failed.\n");
|
||||
return -1;
|
||||
}
|
||||
std::cout << "Sensor init" << std::endl;
|
||||
upm::KXTJ3 dev(I2C_BUS, SENSOR_ADDR);
|
||||
|
||||
printf("Setting settings:\nODR: 25 Hz\nResolution: High\nAcceleration range: 16g with 14bits");
|
||||
dev->SensorInit(KXTJ3_ODR_25, HIGH_RES, KXTJ3_RANGE_16G_14);
|
||||
printf("Showing acceleration data:\n");
|
||||
std::cout << "Setting settings:\nODR: 25 Hz\nResolution: "
|
||||
<< "High\nAcceleration range: 16g with 14bits" << std::endl;
|
||||
dev.SensorInit(KXTJ3_ODR_25, HIGH_RES, KXTJ3_RANGE_16G_14);
|
||||
std::cout << "Showing acceleration data:" << std::endl;
|
||||
print_acceleration_data(dev);
|
||||
|
||||
printf("Closing sensor\n");
|
||||
delete dev;
|
||||
dev = nullptr;
|
||||
std::cout << "Closing sensor" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user