mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-26 17:55:28 +03:00
Cleanup sonar driver
* spend less time in interrupt handler. * avoid pointer usage to prevent the inclination adjusted reading being replaced by the interrupt handler's calculation. * only calculate the actual distance based on the measurement when required.
This commit is contained in:
parent
bd29298197
commit
db14bd80cb
5 changed files with 38 additions and 32 deletions
|
@ -33,7 +33,7 @@
|
|||
#include "sensors/sensors.h"
|
||||
#include "sensors/sonar.h"
|
||||
|
||||
int32_t sonarAlt = -1; // in cm , -1 indicate sonar is not in range
|
||||
int32_t sonarAlt = -1; // in cm , -1 indicate sonar is not in range - inclination adjusted by imu
|
||||
|
||||
#ifdef SONAR
|
||||
|
||||
|
@ -79,7 +79,7 @@ void Sonar_init(void)
|
|||
|
||||
void Sonar_update(void)
|
||||
{
|
||||
hcsr04_get_distance(&sonarAlt);
|
||||
hcsr04_start_reading();
|
||||
}
|
||||
|
||||
int32_t sonarCalculateAltitude(int32_t sonarAlt, int16_t tiltAngle)
|
||||
|
@ -91,4 +91,8 @@ int32_t sonarCalculateAltitude(int32_t sonarAlt, int16_t tiltAngle)
|
|||
return sonarAlt * (900.0f - tiltAngle) / 900.0f;
|
||||
}
|
||||
|
||||
int32_t sonarRead(void) {
|
||||
return hcsr04_get_distance();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue