Пример #1
0
unsigned int SONAR::getDist() {
	debug();

	sendCmd(_distCmd,sizeof(_distCmd));
	delay(1);
	recvDat(distDatSize);
	#ifdef DEBUG
		showDat(distDatSize);
	#endif
	
	if(checksum(distDatSize)==0) return (_recvBuf[5]<<8)+_recvBuf[6];

	return 0xffff;	// not available distance
}
Пример #2
0
unsigned int SONAR::getDist() {
	debug();
	
#if defined(BOARD_maple) || defined(BOARD_maple_native) || defined(BOARD_maple_mini)
	Serial.flush();
#endif

	sendCmd(_distCmd,sizeof(_distCmd));
	delay(1);
	recvDat(distDatSize);
	#ifdef DEBUG
		showDat(distDatSize);
	#endif
	
	if(checksum(distDatSize)==0) return (_recvBuf[5]<<8)+_recvBuf[6];

	return 0xffff;	// not available distance
}
Пример #3
0
unsigned char SONAR::setAddr(unsigned char addr) {
	debug();
	if(addr==0) {
		unsigned startTime=millis();
		unsigned int delta=0;
		bool gotKey=false;

		pinMode(keyS7, INPUT);	// 201209
		while(digitalRead(keyS7)==KEYPRESSED) {
			gotKey=true;
			delay(100);			
			SonarPrint.println(delta=millis()-startTime,DEC);
		}
		if(gotKey) {
			setTX();
			SonarPrint.print("GOt KeyS7(ms): ");
			SonarPrint.println(delta,DEC);
		}
		
		delta/=1000;
		if(0x1<=delta && delta<=0x30) addr=0x10+delta;
	}

	unsigned char addrCmd[sizeof(addrCmdTemplate)];
	if(0x11<=addr && addr<=0x30) {
		generateAddrCmd(addrCmd,addr);
		sendCmd(addrCmd,sizeof(addrCmd));
		delay(1);
		recvDat(addrDatSize);
		#ifdef DEBUG
			showDat(addrDatSize);
		#endif
		if(checksum(addrDatSize)==0) {
			initAddr(addr);
			return addr;
		}
	}
	return 0;
}
Пример #4
0
int SONAR::getTemp() {
	debug();
	unsigned char tempCmd[sizeof(tempCmdTemplate)];
	generateTempCmd(tempCmd,getAddr());

#if defined(BOARD_maple) || defined(BOARD_maple_native) || defined(BOARD_maple_mini)
	Serial.flush();
#endif

	sendCmd(tempCmd,sizeof(tempCmd));
	delay(1);
	recvDat(tempDatSize);
	#ifdef DEBUG
		showDat(tempDatSize);
	#endif
	if(checksum(tempDatSize)==0) {
		int temp=(((_recvBuf[5]&0x0f)<<8)+_recvBuf[6])/10;
		if((_recvBuf[5]&0xf0)==0) return temp;
		return -1*temp;
	}
	return 0xffff;
}