-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AP_WindVane: Add Support for AbsoluteEncoder Backend
This adds a backend for AP_Windvane using the new AP_AbsoluteEncoder driver. The "DIR_PIN" param is overloaded to select the absolute encoder backend.
- Loading branch information
1 parent
8fdba98
commit ca68fd9
Showing
5 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "AP_WindVane_config.h" | ||
|
||
#if AP_WINDVANE_ABSOLUTEENCODER_ENABLED | ||
|
||
#include "AP_WindVane_AbsoluteEncoder.h" | ||
|
||
// constructor | ||
AP_WindVane_AbsoluteEncoder::AP_WindVane_AbsoluteEncoder(AP_WindVane &frontend) : | ||
AP_WindVane_Backend(frontend) | ||
{ | ||
_encoder_instance = _frontend._dir_analog_pin; | ||
} | ||
|
||
void AP_WindVane_AbsoluteEncoder::update_direction() | ||
{ | ||
_encoder_instance = _frontend._dir_analog_pin; // Allow Runtime parameter update | ||
|
||
const AP_AbsoluteEncoder* encoder_driver = AP_AbsoluteEncoder::get_singleton(); | ||
if (encoder_driver != nullptr) { | ||
if (encoder_driver->healthy(_encoder_instance)) { | ||
_frontend._direction_apparent_raw = encoder_driver->get_angle_radians(_encoder_instance); | ||
} | ||
} | ||
} | ||
|
||
#endif //AP_WINDVANE_ABSOLUTEENCODER_ENABLED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#pragma once | ||
|
||
#if AP_WINDVANE_ABSOLUTEENCODER_ENABLED | ||
|
||
#include "AP_WindVane_Backend.h" | ||
|
||
#include <AP_AbsoluteEncoder/AP_AbsoluteEncoder.h> | ||
|
||
class AP_WindVane_AbsoluteEncoder : public AP_WindVane_Backend | ||
{ | ||
public: | ||
// constructor | ||
AP_WindVane_AbsoluteEncoder(AP_WindVane &frontend); | ||
|
||
// update state | ||
void update_direction() override; | ||
|
||
private: | ||
uint8_t _encoder_instance = 0; | ||
}; | ||
|
||
#endif //AP_WINDVANE_ABSOLUTEENCODER_ENABLED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters