Saltware / Mbed 2 deprecated Water Play

Dependencies:   mbed DRV88255 TextLCD Ping mbed-rtos

Committer:
sbouber1
Date:
Tue Jun 14 19:11:19 2016 +0000
Revision:
39:cb67926712d4
Parent:
38:930469a33001
Child:
45:bb33913d4fd2
Child:
53:4e3ee54157ad
some documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sbouber1 9:b3674516729d 1 #ifndef __CONTROLLER_H__
sbouber1 9:b3674516729d 2 #define __CONTROLLER_H__
sbouber1 9:b3674516729d 3
sbouber1 10:fd4670ec0806 4 #include <string>
sbouber1 10:fd4670ec0806 5
sbouber1 10:fd4670ec0806 6 #include "rtos.h"
sbouber1 10:fd4670ec0806 7
sbouber1 39:cb67926712d4 8 /** The base class for everything which interfaces with sensors or actuators.
sbouber1 39:cb67926712d4 9 * Extending classes must implement \a std::string \a get_name() and \a void \a update()
sbouber1 39:cb67926712d4 10 */
sbouber1 9:b3674516729d 11 class Controller {
sbouber1 9:b3674516729d 12 public:
sbouber1 39:cb67926712d4 13
sbouber1 39:cb67926712d4 14 /**
sbouber1 39:cb67926712d4 15 * Initializes the Controller.
sbouber1 39:cb67926712d4 16 * @param threaded whether or not the controller should be threaded.
sbouber1 39:cb67926712d4 17 * @param interval_ms delay between each iteration, only if threaded is set to \a true.
sbouber1 39:cb67926712d4 18 */
sbouber1 10:fd4670ec0806 19 Controller(bool threaded, int interval_ms);
sbouber1 10:fd4670ec0806 20
sbouber1 39:cb67926712d4 21 /**
sbouber1 39:cb67926712d4 22 * Returns the name of this Controller. Must be implemented by extending classes.
sbouber1 39:cb67926712d4 23 * @return The name of this Controller.
sbouber1 39:cb67926712d4 24 */
sbouber1 10:fd4670ec0806 25 virtual std::string get_name() = 0;
sbouber1 10:fd4670ec0806 26
sbouber1 39:cb67926712d4 27 /**
sbouber1 39:cb67926712d4 28 * Returns whether or not this Controller is being threaded.
sbouber1 39:cb67926712d4 29 * @return \a true if this Controller is being threaded, \a false otherwise.
sbouber1 39:cb67926712d4 30 */
sbouber1 10:fd4670ec0806 31 bool is_threaded();
sbouber1 39:cb67926712d4 32
sbouber1 39:cb67926712d4 33 /**
sbouber1 39:cb67926712d4 34 * If this Controller is not threaded, \a update() is called. Otherwise, the first time a thread is spawned which repeatedly calls \a update().
sbouber1 39:cb67926712d4 35 * When the thread has already been spawned no action is taken.
sbouber1 39:cb67926712d4 36 */
sbouber1 10:fd4670ec0806 37 void run();
sbouber1 39:cb67926712d4 38
sbouber1 39:cb67926712d4 39 /**
sbouber1 39:cb67926712d4 40 * Returns the interval between each iteration if threaded.
sbouber1 39:cb67926712d4 41 * @return \a interval_ms as specified in the constructor.
sbouber1 39:cb67926712d4 42 */
sbouber1 10:fd4670ec0806 43 int get_interval_ms();
sbouber1 39:cb67926712d4 44
sbouber1 39:cb67926712d4 45 /**
sbouber1 39:cb67926712d4 46 * Sets the underlying RTOS thread priority.
sbouber1 39:cb67926712d4 47 * @see cmis_os.h
sbouber1 39:cb67926712d4 48 */
sbouber1 10:fd4670ec0806 49 void set_priority(osPriority priority);
sbouber1 39:cb67926712d4 50
sbouber1 39:cb67926712d4 51 /**
sbouber1 39:cb67926712d4 52 * Returns the thread priority.
sbouber1 39:cb67926712d4 53 * @return the thread priority.
sbouber1 39:cb67926712d4 54 */
sbouber1 10:fd4670ec0806 55 osPriority get_priority();
sbouber1 38:930469a33001 56
sbouber1 38:930469a33001 57 protected:
sbouber1 38:930469a33001 58 virtual void update() = 0;
sbouber1 38:930469a33001 59
sbouber1 39:cb67926712d4 60 /**
sbouber1 39:cb67926712d4 61 * The number of times \a run() is called.
sbouber1 39:cb67926712d4 62 */
sbouber1 38:930469a33001 63 unsigned long num_iters;
sbouber1 10:fd4670ec0806 64
sbouber1 10:fd4670ec0806 65 private:
sbouber1 39:cb67926712d4 66 /**
sbouber1 39:cb67926712d4 67 * Whether or not this Controller is threaded.
sbouber1 39:cb67926712d4 68 */
sbouber1 10:fd4670ec0806 69 bool threaded;
sbouber1 39:cb67926712d4 70
sbouber1 39:cb67926712d4 71 /**
sbouber1 39:cb67926712d4 72 * Whether or not a thread has been spawned for this Controller.
sbouber1 39:cb67926712d4 73 */
sbouber1 10:fd4670ec0806 74 bool has_spawned;
sbouber1 39:cb67926712d4 75
sbouber1 39:cb67926712d4 76 /**
sbouber1 39:cb67926712d4 77 * Pointer to the spawned thread if \a has_spawned is \a true, undefined otherwise.
sbouber1 39:cb67926712d4 78 */
sbouber1 10:fd4670ec0806 79 Thread *ctrl_thread;
sbouber1 39:cb67926712d4 80
sbouber1 39:cb67926712d4 81 /**
sbouber1 39:cb67926712d4 82 * Interval in ms between each iteration, only if \a threaded is set to \a true.
sbouber1 39:cb67926712d4 83 */
sbouber1 10:fd4670ec0806 84 int interval_ms;
sbouber1 39:cb67926712d4 85
sbouber1 39:cb67926712d4 86 /**
sbouber1 39:cb67926712d4 87 * Priority of the underlying thread.
sbouber1 39:cb67926712d4 88 */
sbouber1 10:fd4670ec0806 89 osPriority prio;
sbouber1 10:fd4670ec0806 90
sbouber1 39:cb67926712d4 91 /**
sbouber1 39:cb67926712d4 92 * This function is called when the thread is created, it repeatedly calls \a run() and waits for \a interval_ms milliseconds.
sbouber1 39:cb67926712d4 93 */
sbouber1 10:fd4670ec0806 94 static void thread_stub(void const *args);
sbouber1 9:b3674516729d 95 };
sbouber1 9:b3674516729d 96
sbouber1 9:b3674516729d 97 #endif