//-----------------------------------------------------------------// void sync() const noexcept { if(level_ > 0) { volatile uint32_t cnt = counter_; while(cnt == counter_) sleep_(); } else { auto ref = CMT::CMCNT(); while(ref <= CMT::CMCNT()) sleep_(); task_(); ++counter_; } }
int main() { // setup struct leap_event *event; struct leap_controller *controller = leap_controller(); struct leap_listener *listener = leap_listener(1000); leap_add_listener(controller, listener); // poll for events until we get 5000 int limit = 5000; int counter = 0; int i, j; while (counter < limit) { while ((event = leap_poll_listener(listener)) != NULL) { printf("New event (%d): Type: %d\n", counter, event->event_code); print_frame(&event->frame); print_bounds(&event->frame.bounds); for (i = 0; i < event->frame.hand_count; i++) { struct leap_hand *hand = &event->frame.hands[i]; print_hand(hand); for (j = 0; j < hand->finger_count; ++j) { struct leap_finger *finger = &hand->fingers[j]; print_finger(finger); } } ++counter; if (counter > limit) break; } sleep_(100); } // shutdown leap_remove_listener(controller, listener); leap_listener_dispose(listener); leap_controller_dispose(controller); }
//-----------------------------------------------------------------// void sync() const { while(ADCU::ADCSR.ADST() != 0) sleep_(); }
int main (void) { setup_test_environment (); void* timers = zmq_timers_new (); assert (timers); bool timer_invoked = false; int timer_id = zmq_timers_add (timers, 100, handler, &timer_invoked); assert (timer_id); // Timer should be invoked yet int rc = zmq_timers_execute (timers); assert (rc == 0); assert (!timer_invoked); // Wait half the time and check again sleep_ (zmq_timers_timeout (timers) / 2); rc = zmq_timers_execute (timers); assert (rc == 0); assert (!timer_invoked); // Wait until the end sleep_ (zmq_timers_timeout (timers)); rc = zmq_timers_execute (timers); assert (rc == 0); assert (timer_invoked); timer_invoked = false; // Wait half the time and check again long timeout = zmq_timers_timeout (timers); sleep_ (timeout / 2); rc = zmq_timers_execute (timers); assert (rc == 0); assert (!timer_invoked); // Reset timer and wait half of the time left rc = zmq_timers_reset (timers, timer_id); sleep_ (timeout / 2); rc = zmq_timers_execute (timers); assert (rc == 0); assert (!timer_invoked); // Wait until the end sleep_ (zmq_timers_timeout (timers)); rc = zmq_timers_execute (timers); assert (rc == 0); assert (timer_invoked); timer_invoked = false; // reschedule zmq_timers_set_interval (timers, timer_id, 50); sleep_ (51); rc = zmq_timers_execute (timers); assert (rc == 0); assert (timer_invoked); timer_invoked = false; // cancel timer timeout = zmq_timers_timeout (timers); zmq_timers_cancel (timers, timer_id); sleep_ (timeout * 2); rc = zmq_timers_execute (timers); assert (rc == 0); assert (!timer_invoked); rc = zmq_timers_destroy (&timers); assert (rc == 0); return 0; }