Eurobot2012_Primary
Dependencies: mbed Eurobot_2012_Primary
Diff: system.h
- Revision:
- 0:f3bf6c7e2283
- Child:
- 1:bbabbd997d21
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/system.h Fri Apr 20 20:39:35 2012 +0000 @@ -0,0 +1,49 @@ + +#ifndef SYSTEM_H +#define SYSTEM_H + +#include "globals.h" + +//#include "rtos.h" + +// rectifies angle to range -PI to PI +template <typename T> +T rectifyAng (T ang_in) { + ang_in -= (floor(ang_in/(2*PI)))*2*PI; + if (ang_in < -PI) { + ang_in += 2*PI; + } + if (ang_in > PI) { + ang_in -= 2*PI; + } + + return ang_in; +} + +#define SIGTICKARGS(thread, signal) \ + (tfuncptr_t) (&Signalsetter::callback), osTimerPeriodic, (void*)(new Signalsetter(thread, signal)) + +typedef void (*tfuncptr_t)(void const *argument); + +class Signalsetter { +public: + Signalsetter(Thread& inthread, int insignal) : + thread(inthread) { + signal = insignal; + //pc.printf("ptr saved as %#x \r\n", (int)(&(inthread))); + } + + static void callback(void* thisin) { + + Signalsetter* fthis = (Signalsetter*)thisin; + //pc.printf("callback will signal thread object at %#x \r\n", (int)(&(fthis->thread))); + fthis->thread.signal_set(fthis->signal); + //delete fthis; //this is useful for single fire tickers! + } + +private: + Thread& thread; + int signal; +}; + +#endif