PES4 / Mbed OS Queue_02
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "mbed_events.h"
00003 #include "MPU9250.h"
00004 
00005 #define SAMPLE_TIME 100
00006 
00007 DigitalOut led1(LED1);
00008 InterruptIn sw(USER_BUTTON);
00009 
00010 Thread eventthread;
00011 Thread imuthread;
00012 bool read_imu_isrunning;
00013 
00014 
00015 // Pin defines
00016 DigitalOut led_green(D4);
00017 
00018 //-----------------------------------------------------
00019 //IMU
00020 //-----------------------------------------------------
00021 
00022 void rise_handler(void)
00023 {
00024     printf("rise_handler in context %p\r\n", Thread::gettid());
00025     // Toggle LED
00026     led1 = !led1;
00027     for (int i = 0; i<10; i++) {
00028         led_green = !led_green;
00029         wait(0.5);
00030     }
00031 }
00032 
00033 void fall_handler(void)
00034 {
00035     printf("fall_handler in context %p\r\n", Thread::gettid());
00036     // Toggle LED
00037     led1 = !led1;
00038 }
00039 
00040 
00041 
00042 
00043 
00044 
00045 int main()
00046 {
00047     //pc.baud(9600);
00048     //imuSetup();
00049     //imuthread.start(readIMU);
00050 
00051     // Request the shared queue
00052     EventQueue *queue = mbed_event_queue();
00053     //printf("Starting in context %p\r\n", Thread::gettid());
00054 
00055     // The 'rise' handler will execute in IRQ context
00056     sw.rise(queue->event(rise_handler));
00057     // The 'fall' handler will execute in the context of the shared queue (actually the main thread)
00058     sw.fall(queue->event(fall_handler));
00059     // Setup complete, so we now dispatch the shared queue from main
00060     queue->dispatch_forever();
00061 }