Skeleton of mgos_imu_{mag,acc,gyro}.c; restructure header files
This commit is contained in:
@ -32,6 +32,7 @@ struct mgos_imu *mgos_imu_create(struct mgos_i2c *i2c, uint8_t i2caddr) {
|
||||
if (!sensor) {
|
||||
return NULL;
|
||||
}
|
||||
memset(sensor, 0, sizeof(struct mgos_imu));
|
||||
return sensor;
|
||||
}
|
||||
|
||||
@ -39,6 +40,10 @@ void mgos_imu_destroy(struct mgos_imu **sensor) {
|
||||
if (!*sensor) {
|
||||
return;
|
||||
}
|
||||
if ((*sensor)->gyro) mgos_imu_gyro_destroy(&((*sensor)->gyro));
|
||||
if ((*sensor)->acc) mgos_imu_acc_destroy(&((*sensor)->acc));
|
||||
if ((*sensor)->mag) mgos_imu_mag_destroy(&((*sensor)->mag));
|
||||
|
||||
free(*sensor);
|
||||
*sensor = NULL;
|
||||
return;
|
||||
|
35
src/mgos_imu_acc.c
Normal file
35
src/mgos_imu_acc.c
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2018 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mgos.h"
|
||||
#include "mgos_imu_internal.h"
|
||||
|
||||
struct mgos_imu_acc *mgos_imu_acc_create(void) {
|
||||
struct mgos_imu_acc *acc;
|
||||
acc = calloc(1, sizeof(struct mgos_imu_acc));
|
||||
if (!acc) return NULL;
|
||||
memset(acc, 0, sizeof(struct mgos_imu_acc));
|
||||
|
||||
acc->type=ACC_NONE;
|
||||
return acc;
|
||||
}
|
||||
|
||||
bool mgos_imu_acc_destroy(struct mgos_imu_acc **acc) {
|
||||
if (!*acc) return false;
|
||||
free(*acc);
|
||||
*acc=NULL;
|
||||
return true;
|
||||
}
|
35
src/mgos_imu_gyro.c
Normal file
35
src/mgos_imu_gyro.c
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2018 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mgos.h"
|
||||
#include "mgos_imu_internal.h"
|
||||
|
||||
struct mgos_imu_gyro *mgos_imu_gyro_create(void) {
|
||||
struct mgos_imu_gyro *gyro;
|
||||
gyro = calloc(1, sizeof(struct mgos_imu_gyro));
|
||||
if (!gyro) return NULL;
|
||||
memset(gyro, 0, sizeof(struct mgos_imu_gyro));
|
||||
|
||||
gyro->type=GYRO_NONE;
|
||||
return gyro;
|
||||
}
|
||||
|
||||
bool mgos_imu_gyro_destroy(struct mgos_imu_gyro **gyro) {
|
||||
if (!*gyro) return false;
|
||||
free(*gyro);
|
||||
*gyro=NULL;
|
||||
return true;
|
||||
}
|
@ -27,21 +27,17 @@ struct mgos_imu_mag;
|
||||
struct mgos_imu_acc;
|
||||
struct mgos_imu_gyro;
|
||||
|
||||
typedef bool (*mgos_imu_mag_detect_fn)(struct mgos_imu_mag *dev);
|
||||
typedef bool (*mgos_imu_mag_start_fn)(struct mgos_imu_mag *dev);
|
||||
typedef bool (*mgos_imu_mag_read_fn)(struct mgos_imu_mag *dev);
|
||||
typedef bool (*mgos_imu_acc_detect_fn)(struct mgos_imu_acc *dev);
|
||||
typedef bool (*mgos_imu_acc_start_fn)(struct mgos_imu_acc *dev);
|
||||
typedef bool (*mgos_imu_acc_read_fn)(struct mgos_imu_acc *dev);
|
||||
typedef bool (*mgos_imu_gyro_detect_fn)(struct mgos_imu_gyro *dev);
|
||||
typedef bool (*mgos_imu_gyro_start_fn)(struct mgos_imu_gyro *dev);
|
||||
typedef bool (*mgos_imu_gyro_read_fn)(struct mgos_imu_gyro *dev);
|
||||
struct mgos_imu {
|
||||
struct mgos_imu_mag * mag;
|
||||
struct mgos_imu_acc * acc;
|
||||
struct mgos_imu_gyro *gyro;
|
||||
};
|
||||
|
||||
// Magnetometer
|
||||
typedef bool (*mgos_imu_mag_detect_fn)(struct mgos_imu_mag *dev);
|
||||
typedef bool (*mgos_imu_mag_start_fn)(struct mgos_imu_mag *dev);
|
||||
typedef bool (*mgos_imu_mag_read_fn)(struct mgos_imu_mag *dev);
|
||||
|
||||
struct mgos_imu_mag {
|
||||
mgos_imu_mag_detect_fn detect;
|
||||
mgos_imu_mag_start_fn start;
|
||||
@ -55,6 +51,14 @@ struct mgos_imu_mag {
|
||||
int16_t data[3];
|
||||
};
|
||||
|
||||
struct mgos_imu_mag *mgos_imu_mag_create(void);
|
||||
bool mgos_imu_mag_destroy(struct mgos_imu_mag **mag);
|
||||
|
||||
// Accelerometer
|
||||
typedef bool (*mgos_imu_acc_detect_fn)(struct mgos_imu_acc *dev);
|
||||
typedef bool (*mgos_imu_acc_start_fn)(struct mgos_imu_acc *dev);
|
||||
typedef bool (*mgos_imu_acc_read_fn)(struct mgos_imu_acc *dev);
|
||||
|
||||
struct mgos_imu_acc {
|
||||
mgos_imu_acc_detect_fn detect;
|
||||
mgos_imu_acc_start_fn start;
|
||||
@ -68,6 +72,14 @@ struct mgos_imu_acc {
|
||||
int16_t data[3];
|
||||
};
|
||||
|
||||
struct mgos_imu_acc *mgos_imu_acc_create(void);
|
||||
bool mgos_imu_acc_destroy(struct mgos_imu_acc **acc);
|
||||
|
||||
// Gyroscope
|
||||
typedef bool (*mgos_imu_gyro_detect_fn)(struct mgos_imu_gyro *dev);
|
||||
typedef bool (*mgos_imu_gyro_start_fn)(struct mgos_imu_gyro *dev);
|
||||
typedef bool (*mgos_imu_gyro_read_fn)(struct mgos_imu_gyro *dev);
|
||||
|
||||
struct mgos_imu_gyro {
|
||||
mgos_imu_gyro_detect_fn detect;
|
||||
mgos_imu_gyro_start_fn start;
|
||||
@ -83,6 +95,9 @@ struct mgos_imu_gyro {
|
||||
int16_t temperature;
|
||||
};
|
||||
|
||||
struct mgos_imu_gyro *mgos_imu_gyro_create(void);
|
||||
bool mgos_imu_gyro_destroy(struct mgos_imu_gyro **gyro);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
35
src/mgos_imu_mag.c
Normal file
35
src/mgos_imu_mag.c
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2018 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mgos.h"
|
||||
#include "mgos_imu_internal.h"
|
||||
|
||||
struct mgos_imu_mag *mgos_imu_mag_create(void) {
|
||||
struct mgos_imu_mag *mag;
|
||||
mag = calloc(1, sizeof(struct mgos_imu_mag));
|
||||
if (!mag) return NULL;
|
||||
memset(mag, 0, sizeof(struct mgos_imu_mag));
|
||||
|
||||
mag->type=MAG_NONE;
|
||||
return mag;
|
||||
}
|
||||
|
||||
bool mgos_imu_mag_destroy(struct mgos_imu_mag **mag) {
|
||||
if (!*mag) return false;
|
||||
free(*mag);
|
||||
*mag=NULL;
|
||||
return true;
|
||||
}
|
Reference in New Issue
Block a user