AP_TimerProcess: added simple example sketch

This commit is contained in:
rmackay9 2012-09-29 13:23:51 +09:00
parent 41fbb19cf5
commit 00e79e7915
2 changed files with 53 additions and 0 deletions

View File

@ -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 <FastSerial.h>
#include <Arduino_Mega_ISR_Registry.h>
#include <AP_PeriodicProcess.h>
#include <AP_Math.h>
#include <AP_Common.h>
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);
}
}

View File

@ -0,0 +1,4 @@
include ../../../AP_Common/Arduino.mk
sitl:
make -f ../../../../libraries/Desktop/Desktop.mk