summaryrefslogtreecommitdiff
path: root/src/gyronardo.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-07 09:24:37 +0100
committerHampusM <hampus@hampusmat.com>2022-03-07 09:26:17 +0100
commit4b4605df15ce7061a08d7911069927bf49778d05 (patch)
tree5f853e2d7508e073bd12175a7d18ab9e6bf2ea82 /src/gyronardo.cpp
parentfaa501905e2fb554a2444b5e396d9e979ce0be0e (diff)
fix: prevent invalid UniquePtr usage
Diffstat (limited to 'src/gyronardo.cpp')
-rw-r--r--src/gyronardo.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/gyronardo.cpp b/src/gyronardo.cpp
index 148a21b..63b4bfc 100644
--- a/src/gyronardo.cpp
+++ b/src/gyronardo.cpp
@@ -16,17 +16,14 @@ constexpr unsigned int BAUD_RATE = 9600U;
constexpr unsigned int SENSOR_RETRY_TIME = 2000U;
SerialStream sout(Serial_(), BAUD_RATE);
-// SerialStream sout(Serial, BAUD_RATE);
-UniquePtr<Sensor> sensor;
+auto sensor = Sensor(SENSOR_ADDRESS, Wire, sout, SENSOR_THROTTLE_TIME);
void setup()
{
sout.waitReady();
- sensor = make_unique<Sensor>(SENSOR_ADDRESS, Wire, sout, SENSOR_THROTTLE_TIME);
-
- while (!sensor->begin())
+ while (!sensor.begin())
{
sout << "Error: Could not connect to the sensor. Retrying after 2000 "
"milliseconds..."
@@ -35,18 +32,18 @@ void setup()
delay(SENSOR_RETRY_TIME);
}
- if (!sensor->setAccelSensitivity(2)) // 8g
+ if (!sensor.setAccelSensitivity(2)) // 8g
{
sout << "Error: Failed to set the sensor's accelerometer sensitivity. Status: "
- << static_cast<int>(sensor->getStatus()) << endl;
+ << static_cast<int>(sensor.getStatus()) << endl;
stop();
}
- if (!sensor->setGyroSensitivity(1)) // 500 degrees/s
+ if (!sensor.setGyroSensitivity(1)) // 500 degrees/s
{
sout << "Error: Failed to set the sensor's gyro sensitivity. Status: "
- << static_cast<int>(sensor->getStatus()) << endl;
+ << static_cast<int>(sensor.getStatus()) << endl;
stop();
}
@@ -66,17 +63,17 @@ void setup()
sout << "Finished calibrating sensor\n";
sout << "Calibration values:\n"
- << "Accelerometer X: " << sensor->accel_cal_x << "\n"
- << "Accelerometer Y: " << sensor->accel_cal_y << "\n"
- << "Accelerometer Z: " << sensor->accel_cal_z << "\n"
- << "Gyro X: " << sensor->gyro_cal_x << "\n"
- << "Gyro Y: " << sensor->gyro_cal_y << "\n"
- << "Gyro Z: " << sensor->gyro_cal_z << "\n";
+ << "Accelerometer X: " << sensor.accel_cal_x << "\n"
+ << "Accelerometer Y: " << sensor.accel_cal_y << "\n"
+ << "Accelerometer Z: " << sensor.accel_cal_z << "\n"
+ << "Gyro X: " << sensor.gyro_cal_x << "\n"
+ << "Gyro Y: " << sensor.gyro_cal_y << "\n"
+ << "Gyro Z: " << sensor.gyro_cal_z << "\n";
sout << "Starting..." << endl;
- sout << "Pitch: " << sensor->getPitch() << " "
- << "Roll: " << sensor->getRoll() << endl;
+ sout << "Pitch: " << sensor.getPitch() << " "
+ << "Roll: " << sensor.getRoll() << endl;
}
void loop()