Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
You are viewing an older revision! See the latest version
Timeout Event Klasse
ToEvent.h
#ifndef TOEVENT_H #define TOEVENT_H // ---------------- Event Klasse -------------------------- class ToEvent { Timeout _to; bool _timeout; void _flip(); int _to_time; public: ToEvent() { _to_time = 3; } ToEvent(int t) { _to_time = t; } bool CheckTimeOut(); void InitTimeout(); void Stop(); }; #endif
ToEvent.cpp
#include "mbed.h" #include "ToEvent.h" // Timeout expired void ToEvent::_flip() { wait_ms(50); _timeout = true; } bool ToEvent::CheckTimeOut() { if( _timeout ){ _timeout=false; return true; } return false; } void ToEvent::InitTimeout() { _to.attach(callback(this, &ToEvent::_flip), _to_time); _timeout=false; } void ToEvent :: Stop() { _to.detach(); }
How to use it
ToEvent to2; void main(){ to1.InitTimeout(); if(to1.CheckTimeOut()) { // ... to1.Stop(); }