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.
EixoMonitoring.cpp
00001 #include "EixoMonitoring.h" 00002 00003 bool EixoMonitoring::stopAll = false; 00004 bool EixoMonitoring::isCalibrated = false; 00005 00006 00007 EixoMonitoring::EixoMonitoring(PinName pinOrigin, PinName pinEnd) { 00008 00009 this->stopMoviment = false; 00010 this->stopMonitoring = false; 00011 this->delayTimer = 700; 00012 PinName pin_End = pinEnd; 00013 PinName pin_Origin = pinOrigin; 00014 00015 sensor_End = new DigitalIn(pin_End); 00016 sensorInput_End = 0; 00017 sensor_Origin = new DigitalIn(pin_Origin); 00018 sensorInput_Origin = 0; 00019 00020 debug = new Debug(); 00021 } 00022 00023 00024 void EixoMonitoring::startThreads(){ 00025 hitSensor = 0; 00026 this->stopMoviment = false; 00027 this->stopMonitoring = false; 00028 00029 sensorThread_End.start( callback(this, &EixoMonitoring::readSensor_End) ); 00030 handleSensorThread_End.start( callback(this, &EixoMonitoring::handleReadSensor_End) ); 00031 00032 sensorThread_Origin.start( callback(this, &EixoMonitoring::readSensor_Origin) ); 00033 handleSensorThread_Origin.start( callback(this, &EixoMonitoring::handleReadSensor_Origin) ); 00034 } 00035 00036 void EixoMonitoring::readSensor_End(){ 00037 while(stopMonitoring == false){ 00038 stdioMutex.lock(); 00039 sensorInput_End = sensor_End->read(); 00040 stdioMutex.unlock(); 00041 Thread::wait(50); 00042 } 00043 } 00044 00045 00046 void EixoMonitoring::readSensor_Origin(){ 00047 while(stopMonitoring == false){ 00048 stdioMutex.lock(); 00049 sensorInput_Origin = sensor_Origin->read(); 00050 stdioMutex.unlock(); 00051 Thread::wait(50); 00052 } 00053 } 00054 00055 void EixoMonitoring::handleReadSensor_End(){ 00056 Timer* timerLeitura = new Timer(); 00057 timerLeitura->start(); 00058 00059 while(stopMonitoring == false){ 00060 if (stopMoviment == false){ 00061 stdioMutex.lock(); 00062 if(sensorInput_End == 1 && timerLeitura->read_ms()> this->delayTimer ){ // sensor pressionado ? e passou meio segundo 00063 hitSensor++; 00064 timerLeitura->reset(); 00065 } 00066 stdioMutex.unlock(); 00067 } 00068 00069 00070 // SEGURANÇA DA CNC: 00071 if (isCalibrated == false){ 00072 00073 if(hitSensor > 1){ // Na fase de calibragem, se bateu + de 2 vezes(achou origem e na contagem de passos): -> true 00074 stopMoviment = true; 00075 stopAll = true; 00076 timerLeitura->stop(); 00077 } 00078 } 00079 else{ 00080 if(hitSensor > 0){ // Na fase de teste, se bateu + de 1 vez: -> true 00081 stopMoviment = true; 00082 stopAll = true; 00083 timerLeitura->stop(); 00084 } 00085 } 00086 00087 Thread::wait(50); 00088 } 00089 timerLeitura->stop(); 00090 } 00091 00092 void EixoMonitoring::handleReadSensor_Origin(){ 00093 00094 Timer* timerLeitura = new Timer(); 00095 timerLeitura->start(); 00096 00097 while(stopMonitoring == false){ 00098 00099 if (stopMoviment == false){ 00100 stdioMutex.lock(); 00101 if(sensorInput_Origin == 1 && timerLeitura->read_ms()> this->delayTimer){ // sensor pressionado ? 00102 hitSensor++; 00103 timerLeitura->reset(); 00104 } 00105 stdioMutex.unlock(); 00106 } 00107 00108 00109 // SEGURANÇA DA CNC: 00110 if (isCalibrated == false){ 00111 if(hitSensor > 1){ // Na fase de calibragem, se bateu + de 2 vezes(achou origem e na contagem de passos): -> true 00112 stopMoviment = true; 00113 stopAll = true; 00114 timerLeitura->stop(); 00115 } 00116 } 00117 else{ 00118 if(hitSensor > 0){ // Na fase de teste, se bateu + de 1 vez: -> true 00119 stopMoviment = true; 00120 stopAll = true; 00121 timerLeitura->stop(); 00122 } 00123 } 00124 00125 Thread::wait(50); 00126 } 00127 timerLeitura->stop(); 00128 } 00129 00130 void EixoMonitoring::stopThreads(){ 00131 00132 this->stopMoviment = true; 00133 this->stopMonitoring = true; 00134 00135 sensorThread_End.join(); 00136 handleSensorThread_End.join(); 00137 sensorThread_Origin.join(); 00138 handleSensorThread_Origin.join(); 00139 00140 sensorThread_End.terminate(); 00141 handleSensorThread_End.terminate(); 00142 sensorThread_Origin.terminate(); 00143 handleSensorThread_Origin.terminate(); 00144 00145 }
Generated on Sun Jul 24 2022 20:01:40 by
1.7.2