RtosTimerをクラス内で使うテスト

Dependencies:   mbed-rtos mbed

Revision:
0:9bbbd58541be
Child:
1:747445d49c3d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 30 10:54:59 2016 +0000
@@ -0,0 +1,52 @@
+#include "mbed.h"
+#include "rtos.h"
+
+class TestClass
+{
+public:
+    TestClass(uint32_t _updateTime) :  updateTime(_updateTime)
+    {
+        //NOTE: The RTOS hasn't started yet, so we can't create the internal thread here
+    }
+
+    void run() {
+        timer = new RtosTimer(&TestClass::threadHelper, osTimerPeriodic, (void *)this) ;
+        timer->start(updateTime);
+    }
+
+    void stop() {
+        timer->stop();
+        delete timer;
+    }
+
+private:
+    uint32_t updateTime;
+    RtosTimer* timer;
+
+    static void threadHelper(const void* arg) {
+        printf("In threadHelper()\r\n");
+
+        //Cast the argument to a TestClass instance pointer
+        TestClass* instance = (TestClass*)arg;
+
+        //Call the thread method for the TestClass instance
+        instance ->threadMethod();
+    }
+
+    void threadMethod() {
+        printf("In threadMethod()\r\n");
+    }
+};
+
+int main()
+{
+    printf("\n\n\r** Using An RtosTimer inside a class test **\r\n");
+    
+    while (true) {
+        printf("In main loop\r\n");
+        TestClass test(1000);
+        test.run();
+        Thread::wait(10000);
+        test.stop();
+    }
+}