2014-12-02 00:49:50 -04:00
|
|
|
/*
|
|
|
|
simple test of RC input interface
|
|
|
|
*/
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
2015-10-20 09:34:10 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2014-12-02 00:49:50 -04:00
|
|
|
|
2017-04-13 08:31:16 -03:00
|
|
|
void setup();
|
|
|
|
void loop();
|
|
|
|
|
2015-10-16 17:22:11 -03:00
|
|
|
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
|
2014-12-02 00:49:50 -04:00
|
|
|
|
|
|
|
#define MAX_CHANNELS 16
|
|
|
|
|
2017-04-13 08:31:16 -03:00
|
|
|
static uint8_t max_channels_display = 8; // Set to 0 for display numbers of channels detected.
|
2014-12-02 00:49:50 -04:00
|
|
|
static uint16_t last_value[MAX_CHANNELS];
|
|
|
|
|
2017-04-13 08:31:16 -03:00
|
|
|
void setup(void)
|
2014-12-02 00:49:50 -04:00
|
|
|
{
|
|
|
|
hal.console->printf("Starting RCInput test\n");
|
|
|
|
}
|
|
|
|
|
2016-07-03 16:51:41 -03:00
|
|
|
void loop(void)
|
2014-12-02 00:49:50 -04:00
|
|
|
{
|
|
|
|
bool changed = false;
|
2017-04-13 08:31:16 -03:00
|
|
|
uint8_t nchannels = hal.rcin->num_channels(); // Get the numbers channels detected by RC_INPUT.
|
2014-12-02 00:49:50 -04:00
|
|
|
if (nchannels > MAX_CHANNELS) {
|
|
|
|
nchannels = MAX_CHANNELS;
|
|
|
|
}
|
2017-04-13 08:31:16 -03:00
|
|
|
if (nchannels != 0) { // If channels detected, process.
|
2016-07-03 16:51:41 -03:00
|
|
|
for (uint8_t i = 0; i < nchannels; i++) {
|
|
|
|
uint16_t v = hal.rcin->read(i);
|
|
|
|
if (last_value[i] != v) {
|
|
|
|
changed = true;
|
|
|
|
last_value[i] = v;
|
|
|
|
}
|
2014-12-02 00:49:50 -04:00
|
|
|
}
|
2016-07-03 16:51:41 -03:00
|
|
|
if (max_channels_display > nchannels) {
|
|
|
|
max_channels_display = nchannels;
|
2014-12-02 00:49:50 -04:00
|
|
|
}
|
2016-07-03 16:51:41 -03:00
|
|
|
if (max_channels_display > 0) {
|
|
|
|
if (changed) {
|
|
|
|
for (uint8_t i = 0; i < max_channels_display; i++) {
|
|
|
|
hal.console->printf("%2u:%04u ", (unsigned)i+1, (unsigned)last_value[i]);
|
|
|
|
}
|
2017-01-21 00:37:51 -04:00
|
|
|
hal.console->printf("\n");
|
2016-07-03 16:51:41 -03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hal.console->printf("Channels detected: %2u\n", nchannels);
|
|
|
|
hal.console->printf("Set max_channels_display > 0 to display channels values\n");
|
2014-12-02 00:49:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
hal.scheduler->delay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
AP_HAL_MAIN();
|