lora sensnode
Dependencies: libmDot mbed-rtos mbed
Fork of mDot_LoRa_Sensornode by
app/TaskLight.h@0:f2815503561f, 2016-07-06 (annotated)
- Committer:
- mitea1
- Date:
- Wed Jul 06 20:40:36 2016 +0000
- Revision:
- 0:f2815503561f
initial commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mitea1 | 0:f2815503561f | 1 | /** |
mitea1 | 0:f2815503561f | 2 | * @file TaskLight.h |
mitea1 | 0:f2815503561f | 3 | * |
mitea1 | 0:f2815503561f | 4 | * @author Adrian |
mitea1 | 0:f2815503561f | 5 | * @date 27.05.2016 |
mitea1 | 0:f2815503561f | 6 | * |
mitea1 | 0:f2815503561f | 7 | */ |
mitea1 | 0:f2815503561f | 8 | |
mitea1 | 0:f2815503561f | 9 | #include <Thread.h> |
mitea1 | 0:f2815503561f | 10 | #include <Queue.h> |
mitea1 | 0:f2815503561f | 11 | #include <Mutex.h> |
mitea1 | 0:f2815503561f | 12 | #include "MAX44009.h" |
mitea1 | 0:f2815503561f | 13 | #include "MAX44009Message.h" |
mitea1 | 0:f2815503561f | 14 | #include "main.h" |
mitea1 | 0:f2815503561f | 15 | |
mitea1 | 0:f2815503561f | 16 | #ifndef TASKLIGHT_H_ |
mitea1 | 0:f2815503561f | 17 | #define TASKLIGHT_H_ |
mitea1 | 0:f2815503561f | 18 | |
mitea1 | 0:f2815503561f | 19 | /** |
mitea1 | 0:f2815503561f | 20 | * @class TaskLight |
mitea1 | 0:f2815503561f | 21 | * @brief This TaskLight Class handles the light measurement using the MAX44009. |
mitea1 | 0:f2815503561f | 22 | * Starting the task using the start() starts the measurement. |
mitea1 | 0:f2815503561f | 23 | * It can be used alongside with other measurement Tasks inside the mbed::rtos |
mitea1 | 0:f2815503561f | 24 | * environment. The Task Class basically wraps mbeds Thread functionality. |
mitea1 | 0:f2815503561f | 25 | */ |
mitea1 | 0:f2815503561f | 26 | class TaskLight{ |
mitea1 | 0:f2815503561f | 27 | public: |
mitea1 | 0:f2815503561f | 28 | TaskLight(MAX44009*,Mutex*, Queue<MAX44009Message,LIGHT_QUEUE_LENGHT>*); |
mitea1 | 0:f2815503561f | 29 | TaskLight(MAX44009*,Mutex*,Queue<MAX44009Message,LIGHT_QUEUE_LENGHT>*, |
mitea1 | 0:f2815503561f | 30 | osPriority, uint32_t, unsigned char*); |
mitea1 | 0:f2815503561f | 31 | virtual ~TaskLight(); |
mitea1 | 0:f2815503561f | 32 | |
mitea1 | 0:f2815503561f | 33 | /** |
mitea1 | 0:f2815503561f | 34 | * Starts the task by building and its measurement |
mitea1 | 0:f2815503561f | 35 | * @return |
mitea1 | 0:f2815503561f | 36 | */ |
mitea1 | 0:f2815503561f | 37 | osStatus start(); |
mitea1 | 0:f2815503561f | 38 | |
mitea1 | 0:f2815503561f | 39 | /** |
mitea1 | 0:f2815503561f | 40 | * Stops the task. Should only be used after start() was used |
mitea1 | 0:f2815503561f | 41 | * @return |
mitea1 | 0:f2815503561f | 42 | */ |
mitea1 | 0:f2815503561f | 43 | osStatus stop(); |
mitea1 | 0:f2815503561f | 44 | |
mitea1 | 0:f2815503561f | 45 | |
mitea1 | 0:f2815503561f | 46 | /** |
mitea1 | 0:f2815503561f | 47 | * Gets the actual state of the Task either RUNNING or SLEEPING |
mitea1 | 0:f2815503561f | 48 | * @return |
mitea1 | 0:f2815503561f | 49 | */ |
mitea1 | 0:f2815503561f | 50 | TASK_STATE getState(); |
mitea1 | 0:f2815503561f | 51 | |
mitea1 | 0:f2815503561f | 52 | private: |
mitea1 | 0:f2815503561f | 53 | rtos::Thread* thread; |
mitea1 | 0:f2815503561f | 54 | rtos::Queue<MAX44009Message,LIGHT_QUEUE_LENGHT>* queue; |
mitea1 | 0:f2815503561f | 55 | rtos::Mutex* mutexI2C ; |
mitea1 | 0:f2815503561f | 56 | osPriority priority; |
mitea1 | 0:f2815503561f | 57 | uint32_t stack_size; |
mitea1 | 0:f2815503561f | 58 | unsigned char *stack_pointer; |
mitea1 | 0:f2815503561f | 59 | |
mitea1 | 0:f2815503561f | 60 | TASK_STATE state; |
mitea1 | 0:f2815503561f | 61 | |
mitea1 | 0:f2815503561f | 62 | MAX44009* max44009; |
mitea1 | 0:f2815503561f | 63 | |
mitea1 | 0:f2815503561f | 64 | /** |
mitea1 | 0:f2815503561f | 65 | * @brief A Callback function thats called by the mbed::Thread of this TaskClass |
mitea1 | 0:f2815503561f | 66 | * @param |
mitea1 | 0:f2815503561f | 67 | */ |
mitea1 | 0:f2815503561f | 68 | static void callBack(void const *); |
mitea1 | 0:f2815503561f | 69 | |
mitea1 | 0:f2815503561f | 70 | /** |
mitea1 | 0:f2815503561f | 71 | * @brief A thread safe method that measures the light. After measuring the light |
mitea1 | 0:f2815503561f | 72 | * it stores the value inside a MAX44009Message |
mitea1 | 0:f2815503561f | 73 | */ |
mitea1 | 0:f2815503561f | 74 | void measureLight(); |
mitea1 | 0:f2815503561f | 75 | |
mitea1 | 0:f2815503561f | 76 | |
mitea1 | 0:f2815503561f | 77 | /** |
mitea1 | 0:f2815503561f | 78 | * @brief Sets the message Queue of the Task where the measured values will be stored |
mitea1 | 0:f2815503561f | 79 | * after the measurement |
mitea1 | 0:f2815503561f | 80 | * @param queueLight the queue where the MAX44009Message will be stored |
mitea1 | 0:f2815503561f | 81 | */ |
mitea1 | 0:f2815503561f | 82 | void setQueue(Queue<MAX44009Message,LIGHT_QUEUE_LENGHT>* queueLight); |
mitea1 | 0:f2815503561f | 83 | |
mitea1 | 0:f2815503561f | 84 | /** |
mitea1 | 0:f2815503561f | 85 | * @brief Sets the mutex thats used for a thread safe measurement |
mitea1 | 0:f2815503561f | 86 | * @param mutexI2C the I2C mutex |
mitea1 | 0:f2815503561f | 87 | */ |
mitea1 | 0:f2815503561f | 88 | void setMutex(Mutex* mutexI2C); |
mitea1 | 0:f2815503561f | 89 | |
mitea1 | 0:f2815503561f | 90 | /** |
mitea1 | 0:f2815503561f | 91 | * @brief Sets the priority of the Task |
mitea1 | 0:f2815503561f | 92 | * @param priority priority of the Task |
mitea1 | 0:f2815503561f | 93 | */ |
mitea1 | 0:f2815503561f | 94 | void setPriority(osPriority priority); |
mitea1 | 0:f2815503561f | 95 | |
mitea1 | 0:f2815503561f | 96 | /** |
mitea1 | 0:f2815503561f | 97 | * @brief Sets the size of the Task |
mitea1 | 0:f2815503561f | 98 | * @param stackSize the stack size in Bytes |
mitea1 | 0:f2815503561f | 99 | */ |
mitea1 | 0:f2815503561f | 100 | void setStackSize(uint32_t stackSize); |
mitea1 | 0:f2815503561f | 101 | |
mitea1 | 0:f2815503561f | 102 | /** |
mitea1 | 0:f2815503561f | 103 | * @brief Sets the stack pointer of for the task stack |
mitea1 | 0:f2815503561f | 104 | * @param stackPointer |
mitea1 | 0:f2815503561f | 105 | */ |
mitea1 | 0:f2815503561f | 106 | void setStackPointer(unsigned char* stackPointer); |
mitea1 | 0:f2815503561f | 107 | |
mitea1 | 0:f2815503561f | 108 | /** |
mitea1 | 0:f2815503561f | 109 | * @brief Sets the actual state of the Task. |
mitea1 | 0:f2815503561f | 110 | * @param taskState either RUNNING or SLEEPING |
mitea1 | 0:f2815503561f | 111 | */ |
mitea1 | 0:f2815503561f | 112 | void setState(TASK_STATE taskState); |
mitea1 | 0:f2815503561f | 113 | |
mitea1 | 0:f2815503561f | 114 | }; |
mitea1 | 0:f2815503561f | 115 | #endif /* TASKLIGHT_H_ */ |