5 years, 10 months ago.

EventLoop, EventQueue and Thread

AnalogIn ain(PA_0); Pin A0

EventQueue queue; Thread thread, thread1; Timer timer; int count = 0;

void outside_isr() {

count = count + 1;

pc.printf("%.3f seconds\n", timer.read()); pc.printf("%d pulse\n", count); }

void rise_handler() { timer.reset(); timer.start(); }

void fall_handler() {

timer.stop(); queue.call(outside_isr); }

void signal() {

bool flag = false;

while(1) { if (ain > 0.93f) { if (flag == false) { flag = true; rise_handler(); } } if (ain < 0.93f) { if (flag == true) { flag = false; fall_handler(); } } } }

int main () {

thread1.start(callback(signal)); thread.start(callback(&queue, &EventQueue::dispatch_forever));

while(1) {}

}

A new bird to Mbed OS 5 and confused about how to use event thread, event queue as well as the event loop. How can I make the EventThread run only one time and only when fall_handler() is executed?

1 Answer

5 years, 10 months ago.

There are some good example code references on the EventQueue doc page. One of the first examples describe handling rise and fall handlers which you may be able to adapt to your analog sampling need: https://os.mbed.com/docs/v5.8/reference/eventqueue.html

Chris Haster did an "Office Hours with an Engineer" on this topic yesterday. Some of the discussion might help shed light on your question: https://www.youtube.com/watch?v=jQ1aNz6Ras4&list=PLiVCejcvpsesfJNRfBHjzpM1AJXbCoqmx&t=0s&index=5

Accepted Answer