Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- ryood
- Date:
- 2016-05-30
- Revision:
- 0:9bbbd58541be
- Child:
- 1:747445d49c3d
File content as of revision 0:9bbbd58541be:
#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();
}
}