From b83b9040f944ffbbd33bad9f77a21438fc49f8d2 Mon Sep 17 00:00:00 2001 From: Per Magnus Auby Date: Tue, 31 Mar 2015 13:35:45 +0200 Subject: [PATCH] Updates sonar so that it can be used together with ADC current meter Check if ADC current meter is enabled in sonarInit() and change sonar pins to pwm 5 and 6 if it is. Same as when RX_PARALLEL is enabled. --- docs/Sonar.md | 8 ++++---- src/main/main.c | 2 +- src/main/sensors/sonar.c | 6 +++--- src/main/sensors/sonar.h | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/Sonar.md b/docs/Sonar.md index 38f02da18..6def6928f 100644 --- a/docs/Sonar.md +++ b/docs/Sonar.md @@ -14,10 +14,10 @@ Currently the only supported sensor is the HCSR04 sensor. ### Naze/Flip32+ -| Mode | Trigger | Echo | Inline 1k resistors | -| ------------- | ------------- | ------------- | ------------------- | -| Parallel PWM | PB8 / Motor 5 | PB9 / Motor 6 | NO (5v tolerant) | -| PPM/Serial RX | PB0 / RC7 | PB1 / RC8 | YES (3.3v input) | +| Mode | Trigger | Echo | Inline 1k resistors | +| ------------------------------- | ------------- | ------------- | ------------------- | +| Parallel PWM/ADC current sensor | PB8 / Motor 5 | PB9 / Motor 6 | NO (5v tolerant) | +| PPM/Serial RX | PB0 / RC7 | PB1 / RC8 | YES (3.3v input) | Current meter cannot be used in conjunction with Parallel PWM and Sonar. diff --git a/src/main/main.c b/src/main/main.c index 5a3126724..128d41518 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -367,7 +367,7 @@ void init(void) #ifdef SONAR if (feature(FEATURE_SONAR)) { - sonarInit(); + sonarInit(&masterConfig.batteryConfig); } #endif diff --git a/src/main/sensors/sonar.c b/src/main/sensors/sonar.c index 4c89c819c..53b84e7fe 100644 --- a/src/main/sensors/sonar.c +++ b/src/main/sensors/sonar.c @@ -37,7 +37,7 @@ static int32_t calculatedAltitude; -void sonarInit(void) +void sonarInit(batteryConfig_t *batteryConfig) { #if defined(NAZE) || defined(EUSTM32F103RC) || defined(PORT103R) static const sonarHardware_t const sonarPWM56 = { @@ -54,8 +54,8 @@ void sonarInit(void) .exti_pin_source = GPIO_PinSource1, .exti_irqn = EXTI1_IRQn }; - // If we are using parallel PWM for our receiver, then use motor pins 5 and 6 for sonar, otherwise use rc pins 7 and 8 - if (feature(FEATURE_RX_PARALLEL_PWM)) { + // If we are using parallel PWM for our receiver or ADC current sensor, then use motor pins 5 and 6 for sonar, otherwise use rc pins 7 and 8 + if (feature(FEATURE_RX_PARALLEL_PWM ) || (feature(FEATURE_CURRENT_METER) && batteryConfig->currentMeterType == CURRENT_SENSOR_ADC) ) { hcsr04_init(&sonarPWM56); } else { hcsr04_init(&sonarRC78); diff --git a/src/main/sensors/sonar.h b/src/main/sensors/sonar.h index 3b8674e42..695ca8442 100644 --- a/src/main/sensors/sonar.h +++ b/src/main/sensors/sonar.h @@ -16,8 +16,9 @@ */ #pragma once +#include "sensors/battery.h" -void sonarInit(void); +void sonarInit(batteryConfig_t *batteryConfig); void sonarUpdate(void); int32_t sonarRead(void);