mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
Make sensors return data as int16 array instead of struct
This commit is contained in:
parent
20775e806c
commit
74b9c58f39
@ -149,11 +149,12 @@ void PIOS_BMA180_Init()
|
||||
|
||||
/**
|
||||
* @brief Read a single set of values from the x y z channels
|
||||
* @param[out] data Int16 array of (x,y,z) sensor values
|
||||
* @returns 0 if successful
|
||||
* @retval -1 unable to claim bus
|
||||
* @retval -2 unable to transfer data
|
||||
*/
|
||||
int32_t PIOS_BMA180_Read(struct pios_bma180_data * data)
|
||||
int32_t PIOS_BMA180_ReadAccels(int16_t * data)
|
||||
{
|
||||
// To save memory use same buffer for in and out but offset by
|
||||
// a byte
|
||||
@ -167,9 +168,12 @@ int32_t PIOS_BMA180_Read(struct pios_bma180_data * data)
|
||||
PIOS_BMA180_ReleaseBus();
|
||||
|
||||
// | MSB | LSB | 0 | new_data |
|
||||
data->x = ( (rec[2] << 8) | rec[1] ) / 4;
|
||||
data->y = ( (rec[4] << 8) | rec[3] ) / 4;
|
||||
data->z = ( (rec[6] << 8) | rec[5] ) / 4;
|
||||
data[0] = (rec[2] << 8) | rec[1];
|
||||
data[1] = (rec[4] << 8) | rec[3];
|
||||
data[2] = (rec[6] << 8) | rec[5];
|
||||
data[0] /= 4;
|
||||
data[1] /= 4;
|
||||
data[2] /= 4;
|
||||
|
||||
return 0; // return number of remaining entries
|
||||
}
|
||||
@ -200,8 +204,8 @@ int32_t PIOS_BMA180_Test()
|
||||
return -2;
|
||||
PIOS_BMA180_ReleaseBus();
|
||||
|
||||
struct pios_bma180_data data;
|
||||
if(PIOS_BMA180_Read(&data) != 0)
|
||||
int16_t data[3];
|
||||
if(PIOS_BMA180_ReadAccels(data) != 0)
|
||||
return -3;
|
||||
|
||||
if(rec[1] != 0x3)
|
||||
|
@ -132,8 +132,14 @@ static void PIOS_IMU3000_Config(PIOS_IMU3000_ConfigTypeDef * IMU3000_Config_Stru
|
||||
* \param[out] int16_t array of size 3 to store X, Z, and Y magnetometer readings
|
||||
* \returns The number of samples remaining in the fifo
|
||||
*/
|
||||
uint8_t PIOS_IMU3000_ReadGyros(struct pios_imu3000_data * data)
|
||||
int32_t PIOS_IMU3000_ReadGyros(int16_t * data)
|
||||
{
|
||||
uint8_t buf[6];
|
||||
if(PIOS_IMU3000_Read(PIOS_IMU3000_GYRO_X_OUT_MSB, (uint8_t *) buf, sizeof(buf)) < 0)
|
||||
return -1;
|
||||
data[0] = buf[0] << 8 | buf[1];
|
||||
data[1] = buf[2] << 8 | buf[3];
|
||||
data[2] = buf[4] << 8 | buf[5];
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ struct pios_bma180_data {
|
||||
/* Public Functions */
|
||||
void PIOS_BMA180_Attach(uint32_t spi_id);
|
||||
void PIOS_BMA180_Init();
|
||||
int32_t PIOS_BMA180_Read(struct pios_bma180_data * data);
|
||||
int32_t PIOS_BMA180_ReadAccels(int16_t * data);
|
||||
int32_t PIOS_BMA180_Test();
|
||||
|
||||
#endif /* PIOS_BMA180_H */
|
||||
|
@ -119,7 +119,7 @@ struct pios_imu3000_data {
|
||||
/* Public Functions */
|
||||
extern void PIOS_IMU3000_Init(void);
|
||||
extern bool PIOS_IMU3000_NewDataAvailable(void);
|
||||
extern uint8_t PIOS_IMU3000_ReadGyros(struct pios_imu3000_data * data);
|
||||
extern int32_t PIOS_IMU3000_ReadGyros(int16_t * data);
|
||||
extern int32_t PIOS_IMU3000_ReadID();
|
||||
extern uint8_t PIOS_IMU3000_Test();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user