Los Putacos / Mbed OS WearableDevice_Nucleo_New

Dependencies:   MPU9250_SPI

Fork of WearableDevice_Nucleo by Los Putacos

main.cpp

Committer:
gusteibolt
Date:
2017-10-17
Revision:
13:837ea602def0
Parent:
12:c88478dfc622
Child:
17:f98597cd2efc

File content as of revision 13:837ea602def0:

/*
* Los Putacos
* Copyright (C) 2017, All rights reserved.
* ________________________________________ 
*
* Created by: Gustavo Campana, Michael Schmidt, Miguel Lopez
*       Date: 11-Oct-2017
*    Version: V0.1
*/

//-----------------------------------------------------------------
//     Board: NUCLEO - F401RE
//   Version: MR1136 rev C
//-----------------------------------------------------------------

//-----------------------------------------------------------------
// Includes
#include "mbed.h"
#include "rtos.h"
#include "mbed_events.h"

#include "configuration.h"
#include "event.h"
#include "pin.h"
#include "MPU9250.h"
//-----------------------------------------------------------------

//-----------------------------------------------------------------
// Declarations
Timer time_stamp; //Timer µS time-stamp

EventQueue queue(32 * EVENTS_EVENT_SIZE); //Event

Serial pc(USBTX, USBRX); // PC Serial (Debug)
Serial xbee(PA_2, PA_3); // Xbee

MPU9250 imu; // IMU MPU-9255 by Kris Winer 
//-----------------------------------------------------------------

//-----------------------------------------------------------------
// Global Variables
// Your code here!
//-----------------------------------------------------------------
/*
//-----------------------------------------------------------------
void print_event(void const *argv, int i) {
    pc.printf("%d ",i);
    pc.printf((const char*)argv);
    pc.printf("\r\n");
}
//-----------------------------------------------------------------
*/
//-----------------------------------------------------------------
void blink_event(DigitalOut pin){
    pin = !pin;
}
//-----------------------------------------------------------------

//-----------------------------------------------------------------
void println_event(){
    pc.printf("Arroz, feijao e batata\r\n");
}
//-----------------------------------------------------------------

//-----------------------------------------------------------------
void setup(){
    
    // PC Serial (Debug) baudrate
    pc.baud(9600);
    pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
    
    // Task queue
    int task1_id = queue.call_every(1000, printf, "called every 1 seconds\n");
    int task2_id = queue.call_every(2500, printf, "called every 2.5 seconds\n");
    //int task3_id = queue.call_every(3000, &print_event, (void *)"called every 3 seconds\n", (int) time_stamp.read());
    //int task4_id = queue.call_every(50, blink_event, led1);
    int task5_id = queue.call_every(500, println_event);
    int task6_id = queue.call_every(500, readIMU);
    int task7_id = queue.call_every(500, gayEvent);
}
//-----------------------------------------------------------------

//-----------------------------------------------------------------
void initMPU9250()
{  
 // Initialize MPU9250 device
 // wake up device
  imu.writeByte(MPU9250_ADDRESS, PWR_MGMT_1, 0x00); // Clear sleep mode bit (6), enable all sensors 
}
  
//-----------------------------------------------------------------

//-----------------------------------------------------------------
int main()
{
    setup(); // Initial setups
    
    //Reading the analog input (Microphone)  array = micro.read_u16();
    
    time_stamp.start(); // Start timer
    
    while (true) {
        queue.dispatch();
    }
}
//-----------------------------------------------------------------