ロボカップジュニアサッカー IRM2121を用いた専用パルスボールを検知するためのライブラリ
Dependents: BallCheck_IRM2121_InterrputInAdd CatPot_SensorRight
IRM2121.cpp
00001 /* mbed Ping Library respected Library !! 00002 * 00003 * make interruptin_mod by bousiya03 00004 * 00005 */ 00006 00007 00008 #include "IRM2121.h" 00009 #include "interruptin_mod.h" 00010 #include "mbed.h" 00011 00012 IRM2121::IRM2121(PinName IRM_PIN) 00013 : _event(IRM_PIN), _timer() 00014 { 00015 00016 00017 } 00018 00019 void IRM2121::_Start(void) 00020 { 00021 if(_Valid && _Busy ){ 00022 00023 _timer.start(); 00024 _Time = _timer.read_us(); 00025 _Valid = false; 00026 _Busy = true; 00027 _event.fall_disable(this,&IRM2121::_Start); 00028 _event.rise(this,&IRM2121::_Stop); 00029 } 00030 } 00031 00032 void IRM2121::_Stop(void) 00033 { 00034 if(!_Valid && _Busy){ 00035 _Valid = true; // When it stops, update the time 00036 _Busy = false; 00037 _Time = _timer.read_us()-_Time; 00038 _event.rise_disable(this,&IRM2121::_Stop); 00039 } 00040 } 00041 00042 void IRM2121::Set(void) 00043 { 00044 _timer.reset(); 00045 _Valid = true; 00046 _Busy = true; 00047 _event.fall(this,&IRM2121::_Start ); 00048 00049 00050 00051 } 00052 00053 unsigned long IRM2121::Read(void) 00054 // 0 means not valid. 00055 { 00056 if(_Valid && !_Busy){ 00057 _event.fall_disable(this,&IRM2121::_Start); 00058 _event.rise_disable(this,&IRM2121::_Stop); 00059 return _Time; 00060 } 00061 00062 _event.fall_disable(this,&IRM2121::_Start); 00063 _event.rise_disable(this,&IRM2121::_Stop); 00064 00065 return 0; 00066 } 00067 00068 00069 void IRM2121::ReturnVB(bool *valid, bool *busy){ 00070 //use after read_function. this is flag checker. 00071 *valid = _Valid; 00072 *busy = _Busy; 00073 00074 }
Generated on Wed Jul 20 2022 01:27:06 by 1.7.2