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.
Dependencies: mbed DRV88255 TextLCD Ping mbed-rtos
Controller.cpp
00001 #include <iostream> 00002 00003 #include "Controller.h" 00004 00005 Controller::Controller(bool threaded = false, int interval_ms = 0) { 00006 this->threaded = threaded; 00007 this->interval_ms = interval_ms; 00008 this->ctrl_thread = 0; 00009 this->prio = osPriorityNormal; 00010 this->num_iters = 0; 00011 } 00012 00013 bool Controller::isThreaded() { 00014 return this->threaded; 00015 } 00016 00017 void Controller::run() { 00018 if(!this->threaded) { 00019 this->update(); 00020 } else if(!this->has_spawned) { 00021 has_spawned = true; 00022 Thread t (Controller::threadStub, this); 00023 this->ctrl_thread = &t; 00024 } 00025 00026 this->num_iters++; 00027 } 00028 00029 int Controller::getIntervalMs() { 00030 return this->interval_ms; 00031 } 00032 00033 void Controller::setPriority(osPriority priority) { 00034 this->prio = priority; 00035 if(this->has_spawned) 00036 this->ctrl_thread->set_priority(priority); 00037 } 00038 00039 osPriority Controller::getPriority() { 00040 return this->prio; 00041 } 00042 00043 // Called when a thread is spawned. 00044 void Controller::threadStub(void const *args) { 00045 Controller *controller = (Controller*)args; 00046 00047 // Run forever. 00048 while(1) { 00049 std::cout << "[THREAD] running " << controller->getName() << "\r\n"; 00050 controller->run(); 00051 Thread::wait(controller->getIntervalMs()); 00052 } 00053 00054 }
Generated on Tue Jul 12 2022 18:59:29 by
1.7.2