SRK Version of mDot LoRa_Sensormode_SRK

Dependencies:   libmDot mbed-rtos mbed

Fork of mDot_LoRa_Sensornode by Adrian Mitevski

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TaskGyroscope.cpp Source File

TaskGyroscope.cpp

00001 /*
00002  * TaskGyroscope.cpp
00003  *
00004  *  Created on: May 30, 2016
00005  *      Author: Adrian
00006  */
00007 
00008 #include "TaskGyroscope.h "
00009 
00010 TaskGyroscope::TaskGyroscope(MPU9250* mpu9250,Mutex* mutexI2C, Queue<MPU9250GyroscopeMessage,GYROSCOPE_QUEUE_LENGHT>* queue){
00011     this->mpu9250 = mpu9250;
00012     setMutex(mutexI2C);
00013     setQueue(queue);
00014 }
00015 
00016 TaskGyroscope::TaskGyroscope(MPU9250* mpu9250,rtos::Mutex* mutexI2C,
00017     rtos::Queue<MPU9250GyroscopeMessage,GYROSCOPE_QUEUE_LENGHT>* queue,
00018     osPriority priority, uint32_t stackSize, unsigned char *stackPointer){
00019     this->mpu9250 = mpu9250;
00020     setMutex(mutexI2C);
00021     setQueue(queue);
00022     setPriority(priority);
00023     setStackSize(stackSize);
00024     setStackPointer(stackPointer);
00025     setState(SLEEPING);
00026 }
00027 
00028 TaskGyroscope::~TaskGyroscope() {
00029     // TODO Auto-generated destructor stub
00030 }
00031 
00032 osStatus TaskGyroscope::start(){
00033     setState(RUNNING);
00034     this->thread = new rtos::Thread(callBack,this);
00035 }
00036 
00037 osStatus TaskGyroscope::stop(){
00038     thread->terminate();
00039     setState(SLEEPING);
00040     delete this->thread;
00041 }
00042 
00043 void TaskGyroscope::callBack(void const* data){
00044     // WOODHAMMER METHOD of Casting!
00045     const TaskGyroscope* constInstance = static_cast<const TaskGyroscope* >(data);
00046     TaskGyroscope* instance = const_cast<TaskGyroscope*>(constInstance);
00047 
00048     instance->measureGyroscope();
00049 }
00050 
00051 void TaskGyroscope::measureGyroscope(){
00052     MPU9250GyroscopeMessage mpu9250GyroscopeMessage;
00053 
00054     while(true){
00055         mutexI2C->lock(osWaitForever);
00056         mpu9250GyroscopeMessage.setXGyro(mpu9250->getXAxisGyro());
00057         mpu9250GyroscopeMessage.setYGyro(mpu9250->getYAxisGyro());
00058         mpu9250GyroscopeMessage.setZGyro(mpu9250->getZAxisGyro());
00059         mutexI2C->unlock();
00060 
00061         queue->put(&mpu9250GyroscopeMessage,osWaitForever);
00062         osDelay(GYROSCOPE_TASK_DELAY_MS);
00063     }
00064 
00065 
00066 }
00067 
00068 void TaskGyroscope::setQueue(Queue<MPU9250GyroscopeMessage,GYROSCOPE_QUEUE_LENGHT>* queue){
00069     this->queue = queue;
00070 }
00071 
00072 void TaskGyroscope::setMutex(Mutex* mutex){
00073     this->mutexI2C = mutex;
00074 }
00075 
00076 void TaskGyroscope::setPriority(osPriority priority){
00077     this->priority = priority;
00078 }
00079 
00080 void TaskGyroscope::setStackSize(uint32_t stacksize){
00081     this->stack_size = stacksize;
00082 }
00083 
00084 void TaskGyroscope::setStackPointer(unsigned char* stackPointer){
00085     this->stack_pointer = stackPointer;
00086 }
00087 
00088 void TaskGyroscope::setState(TASK_STATE state){
00089     this->state = state;
00090 }
00091 
00092 TASK_STATE TaskGyroscope::getState(){
00093     return state;
00094 }
00095