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