summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/accelerometer/hal-backend-sensor-accel.cpp9
-rw-r--r--src/gyroscope/hal-backend-sensor-gyro.cpp9
-rw-r--r--src/magnetometer/hal-backend-sensor-magnet.cpp9
3 files changed, 21 insertions, 6 deletions
diff --git a/src/accelerometer/hal-backend-sensor-accel.cpp b/src/accelerometer/hal-backend-sensor-accel.cpp
index 9d66893..a694ae6 100644
--- a/src/accelerometer/hal-backend-sensor-accel.cpp
+++ b/src/accelerometer/hal-backend-sensor-accel.cpp
@@ -7,8 +7,13 @@ static sensor_device_t accel_dev = NULL;
static int sensor_create(sensor_device_t **devices)
{
- if (!accel_dev)
- accel_dev = new accel_device;
+ if (!accel_dev) {
+ try {
+ accel_dev = new accel_device;
+ } catch (int error_ret) {
+ return 0;
+ }
+ }
*devices = &accel_dev;
return 1;
diff --git a/src/gyroscope/hal-backend-sensor-gyro.cpp b/src/gyroscope/hal-backend-sensor-gyro.cpp
index fc37fe7..61aaa9d 100644
--- a/src/gyroscope/hal-backend-sensor-gyro.cpp
+++ b/src/gyroscope/hal-backend-sensor-gyro.cpp
@@ -7,8 +7,13 @@ static sensor_device_t gyro_dev = NULL;
static int sensor_create(sensor_device_t **devices)
{
- if (!gyro_dev)
- gyro_dev = new gyro_device;
+ if (!gyro_dev) {
+ try {
+ gyro_dev = new gyro_device;
+ } catch (int error_ret) {
+ return 0;
+ }
+ }
*devices = &gyro_dev;
return 1;
diff --git a/src/magnetometer/hal-backend-sensor-magnet.cpp b/src/magnetometer/hal-backend-sensor-magnet.cpp
index 853c709..a7372d1 100644
--- a/src/magnetometer/hal-backend-sensor-magnet.cpp
+++ b/src/magnetometer/hal-backend-sensor-magnet.cpp
@@ -7,8 +7,13 @@ static sensor_device_t magnet_dev = NULL;
static int sensor_create(sensor_device_t **devices)
{
- if (!magnet_dev)
- magnet_dev = new magnet_device;
+ if (!magnet_dev) {
+ try {
+ magnet_dev = new magnet_device;
+ } catch (int error_ret) {
+ return 0;
+ }
+ }
*devices = &magnet_dev;
return 1;