UniSet
1.4.0
|
00001 // -------------------------------------------------------------------------- 00002 #ifndef Pulse_H_ 00003 #define Pulse_H_ 00004 // -------------------------------------------------------------------------- 00005 #include <iostream> 00006 #include "PassiveTimer.h" 00007 // -------------------------------------------------------------------------- 00008 class Pulse 00009 { 00010 public: 00011 Pulse(): ostate(false),isOn(false), 00012 t1_msec(0),t0_msec(0) 00013 {} 00014 ~Pulse(){} 00015 00016 // t1_msec - интервал "вкл" 00017 // t0_msec - интерфал "откл" 00018 inline void run( int _t1_msec, int _t0_msec ) 00019 { 00020 t1_msec = _t1_msec; 00021 t0_msec = _t0_msec; 00022 t1.setTiming(t1_msec); 00023 t0.setTiming(t0_msec); 00024 set(true); 00025 } 00026 00027 inline void set_next( int _t1_msec, int _t0_msec ) 00028 { 00029 t1_msec = _t1_msec; 00030 t0_msec = _t0_msec; 00031 } 00032 00033 inline void reset() 00034 { 00035 set(true); 00036 } 00037 00038 inline bool step() 00039 { 00040 if( !isOn ) 00041 { 00042 ostate = false; 00043 return false; 00044 } 00045 00046 if( ostate && t1.checkTime() ) 00047 { 00048 ostate = false; 00049 t0.setTiming(t0_msec); 00050 } 00051 else if( !ostate && t0.checkTime() ) 00052 { 00053 t1.setTiming(t1_msec); 00054 ostate = true; 00055 } 00056 00057 return ostate; 00058 } 00059 00060 inline bool out(){ return ostate; } 00061 inline void set( bool state ) 00062 { 00063 isOn = state; 00064 if( !isOn ) 00065 ostate = false; 00066 else 00067 { 00068 t1.reset(); 00069 t0.reset(); 00070 ostate = true; 00071 } 00072 } 00073 00074 friend std::ostream& operator<<(std::ostream& os, Pulse& p ) 00075 { 00076 return os << " idOn=" << p.isOn 00077 << " t1=" << p.t1.getInterval() 00078 << " t0=" << p.t0.getInterval() 00079 << " out=" << p.ostate; 00080 } 00081 00082 friend std::ostream& operator<<(std::ostream& os, Pulse* p ) 00083 { 00084 return os << (*p); 00085 } 00086 00087 00088 protected: 00089 PassiveTimer t1; // таймер "1" 00090 PassiveTimer t0; // таймер "0" 00091 bool ostate; 00092 bool isOn; 00093 long t1_msec; 00094 long t0_msec; 00095 00096 }; 00097 // -------------------------------------------------------------------------- 00098 #endif 00099 // --------------------------------------------------------------------------