NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sonar.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Ninjaflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 #define SONAR_OUT_OF_RANGE (-1)
21 
22 #include "drivers/sonar_hcsr04.h"
23 
24 struct sonar_hardware;
25 struct sonar;
26 
27 struct sonar_ops {
28  void (*start_reading)(struct sonar *self);
29 };
30 
31 struct sonar {
32  struct hcsr04 dev;
33  int16_t altitude;
35  int16_t cf_alt_cm;
37  float max_tilt_cos;
39 };
40 
41 // TODO: remove after refactoring
42 extern struct sonar default_sonar;
43 /*
44 extern int16_t sonarMaxRangeCm;
45 extern int16_t sonarCfAltCm;
46 extern int16_t sonarMaxAltWithTiltCm;
47 */
48 
49 void sonar_init(struct sonar *self);
50 void sonar_update(struct sonar *self);
51 int32_t sonar_read(struct sonar *self);
52 int32_t sonar_calc_altitude(struct sonar *self, float cosTiltAngle);
53 int32_t sonar_get_altitude(struct sonar *self);
54 
void sonar_update(struct sonar *self)
int16_t cf_alt_cm
Definition: sonar.h:35
struct sonar default_sonar
Definition: sonar.h:31
int32_t sonar_calc_altitude(struct sonar *self, float cosTiltAngle)
int32_t sonar_read(struct sonar *self)
Definition: sonar_hcsr04.h:22
float max_tilt_cos
Definition: sonar.h:37
int32_t sonar_get_altitude(struct sonar *self)
int16_t altitude
Definition: sonar.h:33
int16_t max_alt_with_tilt_cm
Definition: sonar.h:34
struct hcsr04 dev
Definition: sonar.h:32
void(* start_reading)(struct sonar *self)
Definition: sonar.h:28
Definition: sonar.h:27
int16_t max_tilt_deci_degrees
Definition: sonar.h:36
void sonar_init(struct sonar *self)
int16_t max_alt_with_tilt
Definition: sonar.h:38