diff include/VirtualClock.h @ 141:44d07fa9bd03 ClockSync

Ultra-basic feedback for clock sync works^CIssues: response time of the IIR filter is too slow, requires PID and better filtering algorithm.
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 14 Sep 2015 15:42:11 +0100
parents e77e2e712fbc
children 134bff10e561
line wrap: on
line diff
--- a/include/VirtualClock.h	Mon Sep 14 14:57:54 2015 +0100
+++ b/include/VirtualClock.h	Mon Sep 14 15:42:11 2015 +0100
@@ -1,14 +1,22 @@
 #ifndef VIRTUAL_CLOCK_H_INCLUDED
 #define VIRTUAL_CLOCK_H_INCLUDED
 
+#include "math.h"
 #include "stats.hpp"
 #include "Clock.h"
+#ifdef USE_JUCE
+#else
+#include <BeagleRT.h>
+#endif /* USE_JUCE */
 
 class VirtualClock{
 private:
 	myClock_t startTime;
+	myClock_t startTimeOffset;
 	myClock_t lastSync;
 	bool firstRun;
+	double elapsedPeriods;
+	double elapsedPeriodsOffset;
 	double period;
 	MovingAverage<double> movingAverage;
 public:
@@ -21,7 +29,7 @@
 /**
 	Call this method asynchronously, passing a number of equally spaced events that have elapsed since the last call.
 */
-	void sync(double count);
+	void sync(double numPeriods);
 /**
 	Get the current time according to the VirtualClock.
 	
@@ -34,6 +42,12 @@
 	Get the length of the period (difference between calls to sync() after various filtering operations)
 */
 	double getPeriod();
+/**
+ * Add an offset to the number of elapsed periods.
+ *
+ * Add an offset to the number of elapsed periods. It also compensates for the corresponding time offset.
+ */
+	void addOffset(double periodOffset);
 };
 
 #endif /* VIRTUAL_CLOCK_H_INCLUDED */