From 71ea0fc75560e09cbeaf9ccfcb840fcf4f13c9a5 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Mon, 27 Aug 2012 17:34:37 -0700 Subject: [PATCH] AP_HAL_AVR example RCInputTest created * input works for APM2, but valid() isnt quite working yet --- .../AP_HAL_AVR/examples/RCInputTest/Arduino.h | 0 .../AP_HAL_AVR/examples/RCInputTest/Makefile | 1 + .../examples/RCInputTest/RCInputTest.pde | 67 +++++++++++++++++++ .../examples/RCInputTest/nocore.inoflag | 0 4 files changed, 68 insertions(+) create mode 100644 libraries/AP_HAL_AVR/examples/RCInputTest/Arduino.h create mode 100644 libraries/AP_HAL_AVR/examples/RCInputTest/Makefile create mode 100644 libraries/AP_HAL_AVR/examples/RCInputTest/RCInputTest.pde create mode 100644 libraries/AP_HAL_AVR/examples/RCInputTest/nocore.inoflag diff --git a/libraries/AP_HAL_AVR/examples/RCInputTest/Arduino.h b/libraries/AP_HAL_AVR/examples/RCInputTest/Arduino.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libraries/AP_HAL_AVR/examples/RCInputTest/Makefile b/libraries/AP_HAL_AVR/examples/RCInputTest/Makefile new file mode 100644 index 0000000000..d1f40fd90f --- /dev/null +++ b/libraries/AP_HAL_AVR/examples/RCInputTest/Makefile @@ -0,0 +1 @@ +include ../../../AP_Common/Arduino.mk diff --git a/libraries/AP_HAL_AVR/examples/RCInputTest/RCInputTest.pde b/libraries/AP_HAL_AVR/examples/RCInputTest/RCInputTest.pde new file mode 100644 index 0000000000..3cd17d8fa9 --- /dev/null +++ b/libraries/AP_HAL_AVR/examples/RCInputTest/RCInputTest.pde @@ -0,0 +1,67 @@ + +#include +#include +#include + +const AP_HAL::HAL& hal = AP_HAL_AVR_APM2; + +void multiread(AP_HAL::RCInput* in) { + /* Multi-channel read method: */ + uint16_t channels[8]; + uint8_t valid; + valid = in->read(channels, 8); + hal.uart0->printf_P(PSTR("multi read %d: %d %d %d %d %d %d %d %d\r\n"), + (int) valid, + channels[0], channels[1], channels[2], channels[3], + channels[4], channels[5], channels[6], channels[7]); +} + +void individualread(AP_HAL::RCInput* in) { + /* individual channel read method: */ + uint8_t valid; + uint16_t channels[8]; + valid = in->valid(); + for (int i = 0; i < 8; i++) { + channels[i] = in->read(i); + } + hal.uart0->printf_P(PSTR("individual read %d: %d %d %d %d %d %d %d %d\r\n"), + (int) valid, + channels[0], channels[1], channels[2], channels[3], + channels[4], channels[5], channels[6], channels[7]); +} + +void loop (void) { + static int ctr = 0; + + hal.gpio->write(27, 1); + + /* Cycle between using the individual read method + * and the multi read method*/ + if (ctr < 500) { + multiread(hal.rcin); + } else { + individualread(hal.rcin); + if (ctr > 1000) ctr = 0; + } + ctr++; + + hal.gpio->write(27, 0); + hal.scheduler->delay(2); +} + +void setup (void) { + hal.uart0->begin(115200); + hal.uart0->printf_P(PSTR("reading rc in:")); + hal.gpio->pinMode(27, GPIO_OUTPUT); + hal.gpio->write(27, 0); +} + + +extern "C" { +int main (void) { + hal.init(NULL); + setup(); + for(;;) loop(); + return 0; +} +} diff --git a/libraries/AP_HAL_AVR/examples/RCInputTest/nocore.inoflag b/libraries/AP_HAL_AVR/examples/RCInputTest/nocore.inoflag new file mode 100644 index 0000000000..e69de29bb2