FSST - Hardwarenahe Programmierung
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 to1; void func(){ to1.InitTimeout(); if(to1.CheckTimeOut()) { // ... to1.Stop(); }