From 2c29fd8ba4087d1fa3f13ee917ab1b59ecf9742e Mon Sep 17 00:00:00 2001 From: rmackay9 Date: Sat, 29 Sep 2012 13:23:51 +0900 Subject: [PATCH] AP_TimerProcess: added simple example sketch --- .../AP_TimerProcess_Test.pde | 49 +++++++++++++++++++ .../examples/AP_TimerProcess_Test/Makefile | 4 ++ 2 files changed, 53 insertions(+) create mode 100644 libraries/AP_PeriodicProcess/examples/AP_TimerProcess_Test/AP_TimerProcess_Test.pde create mode 100644 libraries/AP_PeriodicProcess/examples/AP_TimerProcess_Test/Makefile diff --git a/libraries/AP_PeriodicProcess/examples/AP_TimerProcess_Test/AP_TimerProcess_Test.pde b/libraries/AP_PeriodicProcess/examples/AP_TimerProcess_Test/AP_TimerProcess_Test.pde new file mode 100644 index 0000000000..2fc064cb76 --- /dev/null +++ b/libraries/AP_PeriodicProcess/examples/AP_TimerProcess_Test/AP_TimerProcess_Test.pde @@ -0,0 +1,49 @@ +// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*- + +// +// Simple test for the AP_TimerProcess library +// + +#include +#include +#include +#include +#include + +FastSerialPort0(Serial); +FastSerialPort1(Serial1); + +Arduino_Mega_ISR_Registry isr_registry; +AP_TimerProcess scheduler; + +uint32_t counter; + +void ping(uint32_t now) +{ + counter++; +} + +void setup(void) +{ + Serial.begin(115200); + Serial.println("AP_TimerProcess Test ver 0.1"); + + isr_registry.init(); + scheduler.init(&isr_registry); + + // register our ping function + scheduler.register_process(ping); +} + +void loop(void) +{ + static uint32_t secs = 0; + + // check if 1second has passed + if( counter >= 1000 ) { + counter -= 1000; + secs++; + Serial.print("Seconds: "); + Serial.println(secs); + } +} diff --git a/libraries/AP_PeriodicProcess/examples/AP_TimerProcess_Test/Makefile b/libraries/AP_PeriodicProcess/examples/AP_TimerProcess_Test/Makefile new file mode 100644 index 0000000000..fcdc8ff8fe --- /dev/null +++ b/libraries/AP_PeriodicProcess/examples/AP_TimerProcess_Test/Makefile @@ -0,0 +1,4 @@ +include ../../../AP_Common/Arduino.mk + +sitl: + make -f ../../../../libraries/Desktop/Desktop.mk