Ian Hua / Quadcopter-mbedRTOS

main.cpp

Committer:
pHysiX
Date:
2014-04-29
Revision:
2:ab967d7b4346
Parent:
0:8c28fac22d27
Child:
3:605fbcb54e75

File content as of revision 2:ab967d7b4346:

#include "mbed.h"
#include "rtos.h"
#include "setup.h"
#include "tasks.h"

int main(void)
{
    imu.debugSerial.baud(115200);
    imu.debugSerial.printf("hello\n");
    bool error = false;

    /* Setup devices */
    if (setup_ESC())
        error = false;
    else {
        error = true;
        imu.debugSerial.printf("ESC FAILED!!!\n");
    }

    if (setup_led())
        error = false;
    else
        error = true;

    if (setup_bt()) {
        error = false;
        BT.printf("BT established!\n");
    } else
        error = true;

    if (setup_mpu6050()) {
        error = false;
        BT.printf("MPU6050 established!\n");
    } else error = true;

    if (!error) {
        imu.debugSerial.printf("Devices ready!\n");
        /* Create threads */
        RtosTimer thread1(Task1, osTimerPeriodic, NULL);
        RtosTimer thread2(Task2, osTimerPeriodic, NULL);
        RtosTimer thread3(Task3, osTimerPeriodic, (void *)0);
        RtosTimer thread4(Task4, osTimerPeriodic, (void *)0);

        /* Start threads */
        thread1.start(TASK1_PERIOD);
        thread2.start(TASK2_PERIOD);
        thread3.start(TASK3_PERIOD);
        thread4.start(TASK4_PERIOD);

        /* Execute state machine forever */
        Thread::wait(osWaitForever);
    } else {
        imu.debugSerial.printf("Setup failed!\n");
        return 0;
    }
}