Browse Source

add Get methods

Juraj Ďuďák 2 years ago
parent
commit
fd7b0a5fb0
2 changed files with 52 additions and 4 deletions
  1. 41 2
      src/icm20948.cpp
  2. 11 2
      src/icm20948.h

+ 41 - 2
src/icm20948.cpp

@@ -79,7 +79,7 @@ void Icm20948::icm20948_device_reset()
 }
 
 
-void Icm20948::Wakeup()
+void Icm20948::Wakeup(void)
 {
 	uint8_t new_val = _spi->read_single_reg(_activeDevice, ub_0, B0_PWR_MGMT_1);
 	new_val &= 0xBF;
@@ -88,7 +88,13 @@ void Icm20948::Wakeup()
 	HAL_Delay(100);
 }
 
-void Icm20948::Sleep()
+uint8_t Icm20948::IsSleep(void)
+{
+	uint8_t new_val = _spi->read_single_reg(_activeDevice, ub_0, B0_PWR_MGMT_1);
+	return new_val & 0x40;
+}
+
+void Icm20948::Sleep(void)
 {
 	uint8_t new_val = _spi->read_single_reg(_activeDevice, ub_0, B0_PWR_MGMT_1);
 	new_val |= 0x40;
@@ -354,6 +360,16 @@ void Sensor::SetScaleFactor(float sf){
 	_scaleFactor = sf;
 }
 
+uint8_t Sensor::GetLowPassFilter(void){
+	return 0xFF;
+}
+
+uint8_t Sensor::GetSampleRate(void)
+{
+	return 0xFF;
+}
+
+
 bool SensorGyro::Read(axises* data)
 {
 
@@ -452,6 +468,7 @@ axises *SensorMag::GetData()
 	return &this->data;
 }
 
+
 void SensorAccel::SetRange(accel_full_scale full_scale)
 {
 	uint8_t new_val = _spi->read_single_reg(_activeDevice, ub_2, B2_ACCEL_CONFIG);
@@ -510,6 +527,12 @@ void SensorGyro::SetRange(gyro_full_scale full_scale)
 	_spi->write_single_reg(_activeDevice, ub_2, B2_GYRO_CONFIG_1, new_val);
 }
 
+uint8_t SensorGyro::GetLowPassFilter(void)
+{
+	uint8_t new_val = _spi->read_single_reg(_activeDevice, ub_2, B2_GYRO_CONFIG_1);
+	return (new_val>>1) & 0x03;
+}
+
 void SensorGyro::SetLowPassFilter(gyro_dlp_cfg config)
 {
 	uint8_t new_val = _spi->read_single_reg(_activeDevice, ub_2, B2_GYRO_CONFIG_1);
@@ -532,12 +555,22 @@ void SensorAccel::SetLowPassFilter(accel_dlp_cfg config)
 	_spi->write_single_reg(_activeDevice, ub_2, B2_GYRO_CONFIG_1, new_val);
 }
 
+uint8_t SensorAccel::GetLowPassFilter(void)
+{
+	uint8_t new_val = _spi->read_single_reg(_activeDevice, ub_2, B2_ACCEL_CONFIG);
+	return (new_val>>1) & 0x03 ;
+}
 
 void SensorGyro::SetSampleRate(gyro_samplerate divider)
 {
 	_spi->write_single_reg(_activeDevice, ub_2, B2_GYRO_SMPLRT_DIV, divider);
 }
 
+uint8_t SensorGyro::GetSampleRate(void)
+{
+	return _spi->read_single_reg(_activeDevice, ub_2, B2_GYRO_SMPLRT_DIV);
+}
+
 void SensorAccel::SetSampleRate(accel_samplerate smplrt)
 {
 	uint8_t divider_1 = (uint8_t)(smplrt >> 8);
@@ -547,4 +580,10 @@ void SensorAccel::SetSampleRate(accel_samplerate smplrt)
 	_spi->write_single_reg(_activeDevice, ub_2, B2_ACCEL_SMPLRT_DIV_2, divider_2);
 }
 
+uint8_t SensorAccel::GetSampleRate(void)
+{
+	uint8_t d1 =  _spi->read_single_reg(_activeDevice, ub_2, B2_ACCEL_SMPLRT_DIV_1);
+	uint8_t d2 =  _spi->read_single_reg(_activeDevice, ub_2, B2_ACCEL_SMPLRT_DIV_2);
+	return (d1<<8 | d2);
+}
 

+ 11 - 2
src/icm20948.h

@@ -30,6 +30,8 @@ public:
 	void SetRange();
 	void SetLowPassFilter();
 	void SetSampleRate();
+	uint8_t GetLowPassFilter(void);
+	uint8_t GetSampleRate(void);
 
 	virtual axises *GetData(void) = 0;
 	virtual bool Read(axises *) = 0;
@@ -47,6 +49,9 @@ public:
 	void SetRange(accel_full_scale r);
 	void SetLowPassFilter(accel_dlp_cfg config);
 	void SetSampleRate(accel_samplerate divider);
+
+	uint8_t GetLowPassFilter(void);
+	uint8_t GetSampleRate(void);
 };
 
 
@@ -60,6 +65,9 @@ public:
 	void SetRange(gyro_full_scale r);
 	void SetLowPassFilter(gyro_dlp_cfg config);
 	void SetSampleRate(gyro_samplerate divider);
+
+	uint8_t GetLowPassFilter(void);
+	uint8_t GetSampleRate(void);
 };
 
 class SensorMag: public Sensor {
@@ -107,8 +115,9 @@ public:
     void SetInterruptSource(interrupt_source_enum int_source);
     void Calibrate(void);
     void Read(void);
-	void Wakeup();
-	void Sleep();
+	void Wakeup(void);
+	void Sleep(void);
+	uint8_t IsSleep(void);
 	uint8_t GetDataStatus(void);
 };