Program for the water play project for the course Software Testing Practical 2016 given at the VU University
Dependencies: mbed DRV88255 TextLCD Ping mbed-rtos
Controller.cpp@39:cb67926712d4, 2016-06-14 (annotated)
- Committer:
- sbouber1
- Date:
- Tue Jun 14 19:11:19 2016 +0000
- Revision:
- 39:cb67926712d4
- Parent:
- 38:930469a33001
- Child:
- 55:ee80f248919d
some documentation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sbouber1 | 10:fd4670ec0806 | 1 | |
sbouber1 | 10:fd4670ec0806 | 2 | #include "Controller.h" |
sbouber1 | 10:fd4670ec0806 | 3 | |
sbouber1 | 10:fd4670ec0806 | 4 | #include <iostream> |
sbouber1 | 10:fd4670ec0806 | 5 | |
sbouber1 | 10:fd4670ec0806 | 6 | Controller::Controller(bool threaded = false, int interval_ms = 0) { |
sbouber1 | 10:fd4670ec0806 | 7 | this->threaded = threaded; |
sbouber1 | 10:fd4670ec0806 | 8 | this->interval_ms = interval_ms; |
sbouber1 | 10:fd4670ec0806 | 9 | this->ctrl_thread = 0; |
sbouber1 | 10:fd4670ec0806 | 10 | this->prio = osPriorityNormal; |
sbouber1 | 38:930469a33001 | 11 | this->num_iters = 0; |
sbouber1 | 10:fd4670ec0806 | 12 | } |
sbouber1 | 10:fd4670ec0806 | 13 | |
sbouber1 | 10:fd4670ec0806 | 14 | bool Controller::is_threaded() { |
sbouber1 | 10:fd4670ec0806 | 15 | return this->threaded; |
sbouber1 | 10:fd4670ec0806 | 16 | } |
sbouber1 | 10:fd4670ec0806 | 17 | |
sbouber1 | 10:fd4670ec0806 | 18 | void Controller::run() { |
sbouber1 | 10:fd4670ec0806 | 19 | if(!this->threaded) { |
sbouber1 | 10:fd4670ec0806 | 20 | this->update(); |
sbouber1 | 10:fd4670ec0806 | 21 | } else if(!this->has_spawned) { |
sbouber1 | 10:fd4670ec0806 | 22 | has_spawned = true; |
sbouber1 | 10:fd4670ec0806 | 23 | Thread t (Controller::thread_stub, this); |
sbouber1 | 10:fd4670ec0806 | 24 | this->ctrl_thread = &t; |
sbouber1 | 10:fd4670ec0806 | 25 | } |
sbouber1 | 38:930469a33001 | 26 | |
sbouber1 | 38:930469a33001 | 27 | this->num_iters++; |
sbouber1 | 10:fd4670ec0806 | 28 | } |
sbouber1 | 10:fd4670ec0806 | 29 | |
sbouber1 | 10:fd4670ec0806 | 30 | int Controller::get_interval_ms() { |
sbouber1 | 10:fd4670ec0806 | 31 | return this->interval_ms; |
sbouber1 | 10:fd4670ec0806 | 32 | } |
sbouber1 | 10:fd4670ec0806 | 33 | |
sbouber1 | 10:fd4670ec0806 | 34 | void Controller::set_priority(osPriority priority) { |
sbouber1 | 10:fd4670ec0806 | 35 | this->prio = priority; |
sbouber1 | 10:fd4670ec0806 | 36 | if(this->has_spawned) |
sbouber1 | 10:fd4670ec0806 | 37 | this->ctrl_thread->set_priority(priority); |
sbouber1 | 10:fd4670ec0806 | 38 | } |
sbouber1 | 10:fd4670ec0806 | 39 | |
sbouber1 | 10:fd4670ec0806 | 40 | osPriority Controller::get_priority() { |
sbouber1 | 10:fd4670ec0806 | 41 | return this->prio; |
sbouber1 | 10:fd4670ec0806 | 42 | } |
sbouber1 | 10:fd4670ec0806 | 43 | |
sbouber1 | 10:fd4670ec0806 | 44 | void Controller::thread_stub(void const *args) { |
sbouber1 | 10:fd4670ec0806 | 45 | Controller *controller = (Controller*)args; |
sbouber1 | 10:fd4670ec0806 | 46 | |
sbouber1 | 10:fd4670ec0806 | 47 | while(1) { |
sbouber1 | 10:fd4670ec0806 | 48 | std::cout << "[THREAD] running " << controller->get_name() << "\r\n"; |
sbouber1 | 39:cb67926712d4 | 49 | controller->run(); |
sbouber1 | 10:fd4670ec0806 | 50 | Thread::wait(controller->get_interval_ms()); |
sbouber1 | 10:fd4670ec0806 | 51 | } |
sbouber1 | 10:fd4670ec0806 | 52 | |
sbouber1 | 10:fd4670ec0806 | 53 | } |