-
Notifications
You must be signed in to change notification settings - Fork 18.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AP_RCProtocol: move navio2 RC input into AP_RCProtocol
- Loading branch information
1 parent
261a804
commit 25f7eeb
Showing
5 changed files
with
118 additions
and
1 deletion.
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,68 @@ | ||
#include "AP_RCProtocol_config.h" | ||
|
||
#if AP_RCPROTOCOL_EMLID_RCIO_ENABLED | ||
|
||
#include "AP_RCProtocol_Emlid_RCIO.h" | ||
|
||
#include <cstdio> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <cstdlib> | ||
|
||
#include <AP_Common/AP_Common.h> | ||
|
||
#define RCIN_SYSFS_PATH "/sys/kernel/rcio/rcin" | ||
|
||
void AP_RCProtocol_Emlid_RCIO::init() | ||
{ | ||
for (size_t i = 0; i < ARRAY_SIZE(channels); i++) { | ||
channels[i] = open_channel(i); | ||
if (channels[i] < 0) { | ||
AP_HAL::panic("AP_RCProtocol_Emlid_RCIO: failed to open channels"); | ||
} | ||
} | ||
} | ||
|
||
void AP_RCProtocol_Emlid_RCIO::update(void) | ||
{ | ||
if (AP_HAL::micros() - _last_timestamp < 10000) { | ||
return; | ||
} | ||
|
||
if (!init_done) { | ||
init(); | ||
init_done = true; | ||
} | ||
|
||
uint16_t periods[CHANNEL_COUNT]{}; | ||
|
||
char buffer[12]; | ||
for (size_t i = 0; i < ARRAY_SIZE(channels); i++) { | ||
if (::pread(channels[i], buffer, sizeof(buffer) - 1, 0) <= 0) { | ||
/* We ignore error in order not to spam the console */ | ||
continue; | ||
} | ||
buffer[sizeof(buffer) - 1] = '\0'; | ||
periods[i] = atoi(buffer); | ||
} | ||
|
||
add_input(ARRAY_SIZE(periods), periods, false); | ||
|
||
_last_timestamp = AP_HAL::micros(); | ||
} | ||
|
||
int AP_RCProtocol_Emlid_RCIO::open_channel(int channel) | ||
{ | ||
char *channel_path; | ||
if (asprintf(&channel_path, "%s/ch%d", RCIN_SYSFS_PATH, channel) == -1) { | ||
AP_HAL::panic("AP_RCProtocol_Emlid_RCIO: not enough memory"); | ||
} | ||
|
||
int fd = ::open(channel_path, O_RDONLY|O_CLOEXEC); | ||
|
||
free(channel_path); | ||
|
||
return fd; | ||
} | ||
|
||
#endif // AP_RCPROTOCOL_EMLID_RCIO_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,28 @@ | ||
#pragma once | ||
|
||
#include "AP_RCProtocol_config.h" | ||
|
||
#if AP_RCPROTOCOL_EMLID_RCIO_ENABLED | ||
|
||
#include "AP_RCProtocol_Backend.h" | ||
|
||
class AP_RCProtocol_Emlid_RCIO : public AP_RCProtocol_Backend { | ||
public: | ||
|
||
using AP_RCProtocol_Backend::AP_RCProtocol_Backend; | ||
|
||
void update() override; | ||
|
||
private: | ||
int open_channel(int channel); | ||
|
||
bool init_done; | ||
void init(); | ||
|
||
uint32_t _last_timestamp; | ||
static const size_t CHANNEL_COUNT = 16; | ||
int channels[CHANNEL_COUNT]; | ||
|
||
}; | ||
|
||
#endif // AP_RCPROTOCOL_EMLID_RCIO_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