int MeUsb::probeDevice() { int c; if(!usb_online){ USB_WR( CMD_CHECK_EXIST ); USB_WR( 0x5A); c = USB_RD(); // should return 0xA5 Serial.println(c); if(c!=0xA5) return 0; usb_online = true; resetBus(); } c = getIrq(); if(c!=USB_INT_CONNECT) return 0; resetBus(); // reset bus and wait the device online again c=0; while(c!=USB_INT_CONNECT){ delay(500); // some device may need long time to get ready c = getIrq(); Serial.print("waiting:"); Serial.println(c,HEX); } if( initHIDDevice()==1) device_online=true; }
int16_t MeUSBHost::probeDevice() { int16_t c; if(!ch375_online){ CH375_WR( CMD_CHECK_EXIST ); CH375_WR( 0x5A); c = CH375_RD(); // should return 0xA5 if(c!=0xA5) return 0; ch375_online = true; resetBus(); } c = getIrq(); if(c!=USB_INT_CONNECT) return 0; resetBus(); // reset bus and wait the device online again c=0; while(c!=USB_INT_CONNECT){ delay(500); // some device may need long time to get ready c = getIrq(); #ifdef CH375_DBG Serial.print("waiting:"); Serial.println(c,HEX); #endif } if( initHIDDevice()==1) device_online=true; }
LOW_linkPassiveSerial::LOW_linkPassiveSerial( const LOW_portSerialFactory::portSpecifier_t &inSerPortSpec, const bool inAllowProgPulse) : LOW_link( false, false, inAllowProgPulse) { serialPort = LOW_portSerialFactory::new_portSerial( inSerPortSpec); resetLinkAdapter(); resetBus(); // to detect a missing adapter }
Camera::Camera(int rr,int gr,int br,int erosion,int dilation) :contours(0),adjustment(0),erosion(erosion),dilation(dilation),resWidth(1024),resHeight(768),redRange(rr),greenRange(gr),blueRange(br) { resetBus(); /* Setup camera capture, grab first frame, and create resultant image */ storage = cvCreateMemStorage(0); capture = cvCaptureFromCAM(0); // 160 x 120 is the one that always works // 1024 x 768 is ideal // Set the resolution of the picture to be taken cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH,resWidth); cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT,resHeight); //cvSetCaptureProperty(capture,CV_CAP_PROP_AUTO_EXPOSURE, (double)false); //std::cout << "auto exposure: " << cvGetCaptureProperty(capture,CV_CAP_PROP_AUTO_EXPOSURE) << "\n"; //cvSetCaptureProperty(capture,CV_CAP_PROP_EXPOSURE, (double)-10); //std::cout << "Exposure value: " << cvGetCaptureProperty(capture,CV_CAP_PROP_EXPOSURE) << "\n"; // std::cout << "Taking a "<< cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH) << // "x" << cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT) << " picture.\n"; // std::cout << "Erodes set to " << erosion << " and dilation set to " << dilation << ".\n"; // Attempt to take a picture frame = cvQueryFrame(capture); if(!frame) { CV_Error(CV_StsError, "failed to take initial picture"); } // Create a result as well as contour image result = cvCreateImage(cvGetSize(frame), 8, 1); contourimage = cvCreateImage(cvGetSize(frame), 8, 1); }
LOW_deviceID::deviceIDVec_t LOW_link::searchDevices( const bool inOnlyAlarm, const LOW_deviceIDRaw inPreload, const LOW_deviceIDRaw::devFamCode_t inFamCode, const bool inDoReset) { commLock lock( *this); LOW_deviceIDRaw searchVec = LOW_deviceIDRaw( inPreload); LOW_deviceIDRaw foundID; LOW_deviceIDRaw discrVec; int lastDiscr = 0; LOW_deviceID::deviceIDVec_t foundIDVec; // preload family type if ( inFamCode != LOW_device::anyDev_famCode ) searchVec.setFamilyCode( inFamCode); while ( true ) { if ( resetBus() == false ) return foundIDVec; //throw LOW_device::noDevice_error( "Reset indicated no devices", __FILE__, __LINE__); if ( inOnlyAlarm ) writeData( LOW_device::SearchAlarmROM_COMMAND); else writeData( LOW_device::SearchROM_COMMAND); doSearchSequence( searchVec, foundID, discrVec); if ( foundID.getBit( 63)==true && discrVec.getBit( 63)==true) // no devices found return foundIDVec; //throw LOW_device::noDevice_error( "No devices during search found", __FILE__, __LINE__); LOW_deviceID newID = LOW_deviceID( foundID); if ( inFamCode!=LOW_device::anyDev_famCode && newID.getFamilyCode()!=inFamCode ) break; foundIDVec.push_back( newID); // find last discrepancy int newDiscr = 0xff; for( int a=63 ; a>=0; a--) { if ( discrVec.getBit( a)==true && foundID.getBit( a)==false) { newDiscr = a; break; } } if ( newDiscr==0xff /*|| newDiscr==lastDiscr*/ ) { // search has ended break; } lastDiscr = newDiscr; // prepare next search vector for( int a=0; a<64; a++) { if ( a<lastDiscr ) { searchVec.setBit( a, foundID.getBit( a)); } else if ( a==lastDiscr ) { searchVec.setBit( a, true); } else { searchVec.setBit( a, false); } } } if ( inDoReset ) if ( resetBus() == false ) throw LOW_device::noDevice_error( "Reset indicated no devices", __FILE__, __LINE__); return foundIDVec; }