HU YANG
/
AnalogOut-HelloWorld
aa
Fork of AnalogOut-HelloWorld by
Diff: mdeviceCtrl.cpp
- Revision:
- 5:e6536d2d5aba
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mdeviceCtrl.cpp Mon Oct 10 20:40:05 2016 +0000 @@ -0,0 +1,87 @@ +#include "mdeviceCtrl.h" + +mdeviceCtrl::mdeviceCtrl() +{ + myDevice= new mdevice(); + needleStatus=0; +} + +void mdeviceCtrl::run() +{ + myDevice->updateDeviceStatus(); + int tempB=myDevice->getButtonEdge(); + + int mp0=myDevice->getMotorPos0(); + int mp1=myDevice->getMotorPos1(); + + cout<< mp0 <<" "<< mp1<<endl; + if (tempB==1) + { + myDevice->runMotor0(0.2); + myDevice->runMotor1(-0.02); + } + else if (tempB==-1) + { + myDevice->runMotor0(0.0); + myDevice->runMotor1(0.0); + } +} + +bool mdeviceCtrl::inserNeedle( ) +{ + myDevice->runMotor0(1.0); + int tempPos=myDevice->getMotorPos0(); + if (tempPos>200) + { + return true; + } + else + { + return false; + } +} + +bool mdeviceCtrl::retractNeedle( ) +{ + myDevice->runMotor0(-1.0); + int tempPos=myDevice->getMotorPos0(); + if ( tempPos<10) + { + return true; + } + else + { + return false; + } +} + +bool mdeviceCtrl::switchNeedle1() +{ + needleStatus++; + if (needleStatus%2==0) + { + myDevice->runMotor1(-0.2); + int tempPos=myDevice->getMotorPos1(); + if (tempPos>1) + { + return true; + } + else + { + return false; + } + } + else + { + myDevice->runMotor1(0.2); + int tempPos=myDevice->getMotorPos1(); + if (tempPos<0) + { + return true; + } + else + { + return false; + } + } +}