lora sensnode

Dependencies:   libmDot mbed-rtos mbed

Fork of mDot_LoRa_Sensornode by Adrian Mitevski

Committer:
mitea1
Date:
Wed Jul 06 20:40:36 2016 +0000
Revision:
0:f2815503561f
initial commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mitea1 0:f2815503561f 1 /*
mitea1 0:f2815503561f 2 * TaskGyroscope.cpp
mitea1 0:f2815503561f 3 *
mitea1 0:f2815503561f 4 * Created on: May 30, 2016
mitea1 0:f2815503561f 5 * Author: Adrian
mitea1 0:f2815503561f 6 */
mitea1 0:f2815503561f 7
mitea1 0:f2815503561f 8 #include "TaskGyroscope.h"
mitea1 0:f2815503561f 9
mitea1 0:f2815503561f 10 TaskGyroscope::TaskGyroscope(MPU9250* mpu9250,Mutex* mutexI2C, Queue<MPU9250GyroscopeMessage,GYROSCOPE_QUEUE_LENGHT>* queue){
mitea1 0:f2815503561f 11 this->mpu9250 = mpu9250;
mitea1 0:f2815503561f 12 setMutex(mutexI2C);
mitea1 0:f2815503561f 13 setQueue(queue);
mitea1 0:f2815503561f 14 }
mitea1 0:f2815503561f 15
mitea1 0:f2815503561f 16 TaskGyroscope::TaskGyroscope(MPU9250* mpu9250,rtos::Mutex* mutexI2C,
mitea1 0:f2815503561f 17 rtos::Queue<MPU9250GyroscopeMessage,GYROSCOPE_QUEUE_LENGHT>* queue,
mitea1 0:f2815503561f 18 osPriority priority, uint32_t stackSize, unsigned char *stackPointer){
mitea1 0:f2815503561f 19 this->mpu9250 = mpu9250;
mitea1 0:f2815503561f 20 setMutex(mutexI2C);
mitea1 0:f2815503561f 21 setQueue(queue);
mitea1 0:f2815503561f 22 setPriority(priority);
mitea1 0:f2815503561f 23 setStackSize(stackSize);
mitea1 0:f2815503561f 24 setStackPointer(stackPointer);
mitea1 0:f2815503561f 25 setState(SLEEPING);
mitea1 0:f2815503561f 26 }
mitea1 0:f2815503561f 27
mitea1 0:f2815503561f 28 TaskGyroscope::~TaskGyroscope() {
mitea1 0:f2815503561f 29 // TODO Auto-generated destructor stub
mitea1 0:f2815503561f 30 }
mitea1 0:f2815503561f 31
mitea1 0:f2815503561f 32 osStatus TaskGyroscope::start(){
mitea1 0:f2815503561f 33 setState(RUNNING);
mitea1 0:f2815503561f 34 this->thread = new rtos::Thread(callBack,this);
mitea1 0:f2815503561f 35 }
mitea1 0:f2815503561f 36
mitea1 0:f2815503561f 37 osStatus TaskGyroscope::stop(){
mitea1 0:f2815503561f 38 thread->terminate();
mitea1 0:f2815503561f 39 setState(SLEEPING);
mitea1 0:f2815503561f 40 delete this->thread;
mitea1 0:f2815503561f 41 }
mitea1 0:f2815503561f 42
mitea1 0:f2815503561f 43 void TaskGyroscope::callBack(void const* data){
mitea1 0:f2815503561f 44 // WOODHAMMER METHOD of Casting!
mitea1 0:f2815503561f 45 const TaskGyroscope* constInstance = static_cast<const TaskGyroscope* >(data);
mitea1 0:f2815503561f 46 TaskGyroscope* instance = const_cast<TaskGyroscope*>(constInstance);
mitea1 0:f2815503561f 47
mitea1 0:f2815503561f 48 instance->measureGyroscope();
mitea1 0:f2815503561f 49 }
mitea1 0:f2815503561f 50
mitea1 0:f2815503561f 51 void TaskGyroscope::measureGyroscope(){
mitea1 0:f2815503561f 52 MPU9250GyroscopeMessage mpu9250GyroscopeMessage;
mitea1 0:f2815503561f 53
mitea1 0:f2815503561f 54 while(true){
mitea1 0:f2815503561f 55 mutexI2C->lock(osWaitForever);
mitea1 0:f2815503561f 56 mpu9250GyroscopeMessage.setXGyro(mpu9250->getXAxisGyro());
mitea1 0:f2815503561f 57 mpu9250GyroscopeMessage.setYGyro(mpu9250->getYAxisGyro());
mitea1 0:f2815503561f 58 mpu9250GyroscopeMessage.setZGyro(mpu9250->getZAxisGyro());
mitea1 0:f2815503561f 59 mutexI2C->unlock();
mitea1 0:f2815503561f 60
mitea1 0:f2815503561f 61 queue->put(&mpu9250GyroscopeMessage,osWaitForever);
mitea1 0:f2815503561f 62 osDelay(GYROSCOPE_TASK_DELAY_MS);
mitea1 0:f2815503561f 63 }
mitea1 0:f2815503561f 64
mitea1 0:f2815503561f 65
mitea1 0:f2815503561f 66 }
mitea1 0:f2815503561f 67
mitea1 0:f2815503561f 68 void TaskGyroscope::setQueue(Queue<MPU9250GyroscopeMessage,GYROSCOPE_QUEUE_LENGHT>* queue){
mitea1 0:f2815503561f 69 this->queue = queue;
mitea1 0:f2815503561f 70 }
mitea1 0:f2815503561f 71
mitea1 0:f2815503561f 72 void TaskGyroscope::setMutex(Mutex* mutex){
mitea1 0:f2815503561f 73 this->mutexI2C = mutex;
mitea1 0:f2815503561f 74 }
mitea1 0:f2815503561f 75
mitea1 0:f2815503561f 76 void TaskGyroscope::setPriority(osPriority priority){
mitea1 0:f2815503561f 77 this->priority = priority;
mitea1 0:f2815503561f 78 }
mitea1 0:f2815503561f 79
mitea1 0:f2815503561f 80 void TaskGyroscope::setStackSize(uint32_t stacksize){
mitea1 0:f2815503561f 81 this->stack_size = stacksize;
mitea1 0:f2815503561f 82 }
mitea1 0:f2815503561f 83
mitea1 0:f2815503561f 84 void TaskGyroscope::setStackPointer(unsigned char* stackPointer){
mitea1 0:f2815503561f 85 this->stack_pointer = stackPointer;
mitea1 0:f2815503561f 86 }
mitea1 0:f2815503561f 87
mitea1 0:f2815503561f 88 void TaskGyroscope::setState(TASK_STATE state){
mitea1 0:f2815503561f 89 this->state = state;
mitea1 0:f2815503561f 90 }
mitea1 0:f2815503561f 91
mitea1 0:f2815503561f 92 TASK_STATE TaskGyroscope::getState(){
mitea1 0:f2815503561f 93 return state;
mitea1 0:f2815503561f 94 }
mitea1 0:f2815503561f 95