Browse Source

fix bank selection when multiple sensors are used

Juraj Ďuďák 2 years ago
parent
commit
29ebf8c419
3 changed files with 14 additions and 5 deletions
  1. 8 3
      src/SpiManager.cpp
  2. 4 2
      src/icm20948.cpp
  3. 2 0
      src/icm_datatypes.h

+ 8 - 3
src/SpiManager.cpp

@@ -32,9 +32,14 @@ void SpiManager::cs_high(uint8_t index)
 
 void SpiManager::select_user_bank(uint8_t sensorNum, userbank ub)
 {
-	if(ub == _active_bank){
-		return;		// TODO: overit, ci je toto OK
-	}
+	// toto je v poriadku iba pri pouziti jedneho senzora
+	// treba osetrit situaciu, ked je viacero senzorov.
+	// zmena banky sa musi robit pre kazdy senzor
+
+//	if(ub == _active_bank){
+//		return;
+//	}
+
 	_active_bank = ub;
 
 	uint8_t write_reg[2];

+ 4 - 2
src/icm20948.cpp

@@ -131,14 +131,16 @@ bool Icm20948::IsReady(void)
 
 void Icm20948::Stop(void)
 {
+//	_spi->write_single_reg(_activeDevice, ub_0, B0_PWR_MGMT_2, 0x3F);	// vypne vsetky senzory
+	_spi->write_single_reg(_activeDevice, ub_0, B0_INT_ENABLE_1, 0x0);
 	_sensor_ready = false;
-	_spi->write_single_reg(_activeDevice, ub_0, B0_PWR_MGMT_2, 0x3F);
 }
 
 void Icm20948::Start(void)
 {
+//	_spi->write_single_reg(_activeDevice, ub_0, B0_PWR_MGMT_2, 0x0);
+	_spi->write_single_reg(_activeDevice, ub_0, B0_INT_ENABLE_1, 0x1);
 	_sensor_ready = true;
-	_spi->write_single_reg(_activeDevice, ub_0, B0_PWR_MGMT_2, 0x0);
 }
 
 void Icm20948::Sleep(void)

+ 2 - 0
src/icm_datatypes.h

@@ -21,6 +21,8 @@
 #define ICM20948_MAG					0x30
 #define ICM20948_TEMP					0x40
 
+#define GET2BYTES(ptr,offset) 		((((uint16_t)*(ptr+(offset)))<<8) + *(ptr+(offset)+1))
+
 typedef struct
 {
 	uint8_t type;