demostration for TimeoutAbs

Dependencies:   TimeoutAbs

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "LowPowerTimeoutAbs.h"
00003 
00004 volatile bool ev;
00005 Timer t;
00006 
00007 LowPowerTimeoutAbs tabs;
00008 
00009 void my_callback()
00010 {
00011     ev = true;
00012 }
00013 
00014 us_timestamp_t tabs_started_at;
00015 
00016 int main()
00017 {
00018     unsigned prev;
00019     t.start();
00020     tabs_started_at = tabs.read_us();
00021     tabs.attach_us(my_callback, tabs_started_at + 100000);
00022     prev = t.read_us();
00023     printf("tabs_started_at:%llu prev:%u\r\n", tabs_started_at, prev);
00024     for (;;) {
00025         unsigned now;
00026         if (ev) {
00027             unsigned late;
00028             now = t.read_us();
00029             tabs_started_at += 1000000;
00030             late = rand() % 200000;
00031             printf("time %u\t", now - prev);
00032             fflush(stdout);
00033             wait_us(late);
00034             printf("late:%u\r\n", late);
00035             tabs.attach_us(my_callback, tabs_started_at);
00036             prev = now;
00037             ev = false;
00038         }
00039     }
00040 }