当前位置: 首页>>代码示例>>C++>>正文


C++ SoftwareSerial::flush方法代码示例

本文整理汇总了C++中SoftwareSerial::flush方法的典型用法代码示例。如果您正苦于以下问题:C++ SoftwareSerial::flush方法的具体用法?C++ SoftwareSerial::flush怎么用?C++ SoftwareSerial::flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SoftwareSerial的用法示例。


在下文中一共展示了SoftwareSerial::flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setName

/* This function sets the name of an RN-42 module
   name should be an up to 20-character value. It MUST BE TERMINATED by a 
   \r character */
uint8_t makeyMateClass::setName(char * name)
{
  if (bluetooth.available())
    bluetooth.flush();	// Get rid of any characters in the buffer, we'll need to check it fresh

  bluetooth.print("SN,");
  for (int i=0; i<20; i++)
  {
    if (name[i] != '\r')
      bluetooth.write(name[i]);
    else
      break;
  }
  bluetooth.write('\r');
  
  delay(BLUETOOTH_RESPONSE_DELAY);
  bluetoothReceive(rxBuffer);

  /* Double check the setting, output results in Serial monitor */
  bluetooth.flush();
  bluetooth.print("GN");
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  Serial.print("Name set to: ");
  while (bluetooth.available())
    Serial.write(bluetooth.read());

  return bluetoothCheckReceive(rxBuffer, "AOK", 3);
}
开发者ID:TildeWill,项目名称:MaKey-Mate-Bluetooth,代码行数:32,代码来源:makeyMate.cpp

示例2: connect

// TODO: This is extremely kludgy right now. 
//		The delay()'s should be made more robust, faster by periodically checking for a response,
//		while still checking for a timeout.
//		Checking for just the first char of a response is a questionabl solution.
//		Needs more testing.  So many unknown states the BlueSMiRF could be in. 
//		We need some flow chart action here.
int SFE_MetaWatch::connect()
{
	char c;
	int timeout = CONNECT_TIMEOUT;
	
	bt.print('\r');	// Clear any previous commands
	delay(BLUETOOTH_RESPONSE_DELAY);
	bt.flush();
	// Entering command mode. Should either print "CMD" or "?" if already there
	while ((c != 'C') && (c != '?') && (timeout > 0))
	{
		bt.print("$$$");	// Enter command mode
		delay(BLUETOOTH_RESPONSE_DELAY);
		c = bt.read();	// Read first character of response
		bt.flush();
		timeout--;
	}
	
	if (timeout == 0)
		return -2;
	else
		timeout = CONNECT_TIMEOUT;
	
	// After sending connect command, should print "TRYING", may also print "ERR-connected"
	while ((c != 'T') && (c != 'E') && (timeout > 0)) 
	{
		bt.print("C,");
		bt.print(watchAddress);
		bt.print('\r');
		delay(BLUETOOTH_RESPONSE_DELAY);
		c = bt.read();
		bt.flush();
		timeout--;
	}
	// If there was an error, try to exit command mode
	if ((c == 'E') || timeout == 0)
	{
		bt.print("---");	// Exit command mode
		bt.print('\r');
		delay(BLUETOOTH_RESPONSE_DELAY);
		bt.flush();
	}
	
	if (timeout == 0)
		return -1;	// Return -1 if connect command error
	else if (c == 'E')
		return 2;	// Return 2 if we think we're already connected
	else
		return 1;	// Return 1 if all went according to plan
}
开发者ID:JLJames,项目名称:SparkFun_MetaWatch_Library,代码行数:56,代码来源:SparkFun_MetaWatch.cpp

示例3: readRFID

boolean readRFID() {
	//if (RFID.available()) RFID.flush();
	digitalWrite(RFID_ENABLE, LOW);    // Activate the RFID reader
	
	for (byte i = 0; i < RFID_LENGTH; i++)
		rfidCode[i] = 0;

	if (RFID.available()) {
		int val = RFID.read();
		Serial.print(val);

		if (val == RFID_START_CHAR) {
			RFID.readBytes(rfidCode, RFID_LENGTH);

			Serial.print("RFID Read: ");
			Serial.println(rfidCode);

			digitalWrite(RFID_ENABLE, HIGH);   // deactivate the RFID reader for a moment so it will not flood
			RFID.flush();                      // clear the buffer
			delay(1500);                       // wait for a bit

			return true;
		 }
	}
	return false;
}
开发者ID:mikelduke,项目名称:DMS-RFID-Interlock,代码行数:26,代码来源:PowerInterlock.cpp

示例4: clearBuffer

//clear buffer in the serial port - better - try to do this
void HerkulexClass::clearBuffer()
{
  switch (port)
	{
	case SSerial:
                SwSerial.flush();
                delay(1);
                break;
	#if defined (__AVR_ATmega1280__) || defined (__AVR_ATmega128__) || defined (__AVR_ATmega2560__)
	case HSerial1:
				Serial1.flush();
				while (Serial1.available()){
				Serial1.read();
				delayMicroseconds(200);
				}

		break;
	case HSerial2:
	            Serial2.flush();
				while (Serial2.available()){
				Serial2.read();
				delayMicroseconds(200);
				}
		break;
	case HSerial3:
	            Serial3.flush();
				while (Serial3.available()){
					Serial3.read();
					delayMicroseconds(200);
				}

		break;
	#endif
	}
}
开发者ID:NickAlbers,项目名称:RoboCup,代码行数:36,代码来源:Herkulex.cpp

示例5: setup

void setup()
{
  gprsSerial.begin(9600);
  Serial.begin(9600);

  Serial.println("Config SIM900...");
  delay(2000);
  Serial.println("Done!...");
  gprsSerial.flush();
  Serial.flush();

  // attach or detach from GPRS service 
  gprsSerial.println("AT+CGATT?");
  delay(100);
  toSerial();


  // bearer settings
  gprsSerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(2000);
  toSerial();

  // bearer settings
  gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"airtelgprs.com\"");
  delay(2000);
  toSerial();

  // bearer settings
  gprsSerial.println("AT+SAPBR=1,1");
  delay(2000);
  toSerial();
}
开发者ID:spojsolutions,项目名称:spoj,代码行数:32,代码来源:arduino_shuttle.cpp

示例6: sendPacket

/* sendPacket() is called by just about every other member function. It calculates 
	some CRC bytes, then sends the message string.
	If a response is requested, it'll return that in the response array. Otherwise
	that and the responseLength variable should be 0.
	
	If you're using a bluetooth module that's not the RN-42, this'd be the place
	to modify.
*/
void SFE_MetaWatch::sendPacket(unsigned char * data, int length, unsigned char * response, int responseLength)
{
	int crc = ComputeCRC(data, length - 2);	// Get the crc values for our string
	data[length-1] = (crc & 0xFF00) >> 8;	// LSB goes first
	data[length-2] = crc & 0xFF;	// the MSB

	// If you want a response, let's flush out the bt buffer first.
	if (responseLength > 0)
		bt.flush();
	
	// Send the data out to the BlueSMiRF
	for (int i=0; i<length; i++)
	{
		bt.write(data[i]);
	}
	
	// If a response was requested, read that into the response array.
	if (responseLength > 0)
	{
		delay(BLUETOOTH_RESPONSE_DELAY);
		int i=0;
		while (bt.available() && (i < responseLength))
		{
			response[i++] = bt.read();
		}
	}
}
开发者ID:JLJames,项目名称:SparkFun_MetaWatch_Library,代码行数:35,代码来源:SparkFun_MetaWatch.cpp

示例7: getHIDMode

/* This function returns a 1 if the RN-42 is already in HID mode
   The module MUST BE IN COMMAND MODE for this function to work! */
uint8_t makeyMateClass::getHIDMode(void)
{
  bluetooth.flush();
  bluetooth.print("G~");  // '~' is the RN-42's HID/SPP set command
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  bluetoothReceive(rxBuffer);  // receive all response chars into rxBuffer

  return bluetoothCheckReceive(rxBuffer, "6", 1);	
}
开发者ID:TildeWill,项目名称:MaKey-Mate-Bluetooth,代码行数:12,代码来源:makeyMate.cpp

示例8: setupBlueToothConnection

void setupBlueToothConnection()
{
  blueToothSerial.begin(38400); 
  blueToothSerial.print("\r\n+STWMOD=1\r\n");
  blueToothSerial.print("\r\n+STNA=SeeedBTMaster\r\n");
  blueToothSerial.print("\r\n+STAUTO=0\r\n");
  delay(2000); 
  blueToothSerial.flush();
  blueToothSerial.print("\r\n+INQ=1\r\n");
  Serial.println("inquiring");
  delay(2000); 
  
  char recvChar;
 /* while(1){                                       //this part is for auto detecting and connecting to a slave but something is wrong with the parsing of the address, use this to print out the address and then put it in manulely 								below
    if(blueToothSerial.available()){
     recvChar = blueToothSerial.read();
      recvBuf += recvChar;
      nameIndex = recvBuf.indexOf(slaveName);
  
      if ( nameIndex != -1 ){
        
 	addrIndex = (recvBuf.indexOf(retSymb,(nameIndex - retSymb.length()- 18) ) + retSymb.length());	 		
 	slaveAddr = recvBuf.substring(addrIndex, nameIndex);			
 	break;
      }
   }
 }*/
  
  connectCmd += slaveAddr;
  connectCmd += "\r\n";
  int connectOK = 0;
  Serial.print("Connecting to slave:");
  Serial.print(slaveAddr);
  Serial.println(slaveName);

  do{
    blueToothSerial.print("/*put slave address here*/");
    recvBuf = "";
    while(1){
      if(blueToothSerial.available()){
        recvChar = blueToothSerial.read();
 	recvBuf += recvChar;
 	if(recvBuf.indexOf("CONNECT:OK") != -1){
          connectOK = 1;
 	  Serial.println("Connected!");
 	  blueToothSerial.print("Connected!");
 	  break;
 	}else if(recvBuf.indexOf("CONNECT:FAIL") != -1){
 	  Serial.println("Connect again!");
 	  break;
 	}
      }
    }
  }while(0 == connectOK);
}
开发者ID:Phendrana,项目名称:Capstone-Stuff,代码行数:55,代码来源:bluetooth.c

示例9: connect

/* This function will attempt a connection to the stored remote address
   The first time you connect the the RN-42 HID, the master device will
   need to initiate the connection. The first time a connection is made
   the bluetooth address of the master device will be stored on the RN-42.
   If no remote address is stored, a connection will not be made. */
uint8_t makeyMateClass::connect()
{
  freshStart();  // Get the module disconnected, and out of command mode
  
  while (!enterCommandMode())
  {  // Enter command mode
    delay(BLUETOOTH_RESPONSE_DELAY);
  }
  delay(BLUETOOTH_RESPONSE_DELAY);
  bluetooth.flush();
  
  /* get the remote address and print it in the serial monitor */
  bluetooth.print("GR");  // Get the remote address
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  if (bluetooth.peek() == 'N')  // Might say "No remote address stored */
  {  // (bluetooth address is hex values only, so won'te start with 'N'.
    Serial.println("Can't connect. No paired device!");
    bluetooth.flush();
    bluetooth.print("---");  // exit command mode
    bluetooth.write('\r');
    return 0;  // No connect is attempted
  }
  else if (bluetooth.available() == 0)  
  { // If we can't communicate with the module at all, print error
    Serial.println("ERROR!");
    return 0;  // return error
  }
  /* otherwise print the address we're trying to connect to */
  Serial.print("Attempting to connect to: ");
  while (bluetooth.available())
    Serial.write(bluetooth.read());
    
  /* Attempt to connect */
  bluetooth.print("C");  // The connect command
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  while (bluetooth.available())
    Serial.write(bluetooth.read());  // Should print "TRYING"
  
  return 1;
}
开发者ID:TildeWill,项目名称:MaKey-Mate-Bluetooth,代码行数:47,代码来源:makeyMate.cpp

示例10: setHIDMode

/* This function will set the RN-42 into HID mode, from SPP mode.
   Requires a reboot to take effect! */
uint8_t makeyMateClass::setHIDMode(void)
{
  if (bluetooth.available())
    bluetooth.flush();	// Get rid of any characters in the buffer, we'll need to check it fresh

    bluetooth.print("S~,6");  // Bluetooth HID Mode
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  bluetoothReceive(rxBuffer);

  /* Double check the setting, output results in Serial monitor */
  bluetooth.flush();
  bluetooth.print("G~");
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  Serial.print("Profile set to: ");
  while (bluetooth.available())
    Serial.write(bluetooth.read());

  return bluetoothCheckReceive(rxBuffer, "AOK", 3);
}
开发者ID:TildeWill,项目名称:MaKey-Mate-Bluetooth,代码行数:23,代码来源:makeyMate.cpp

示例11: FlashHM

void ICACHE_FLASH_ATTR FlashHM() {  //server request to flash avr file to HM...file exists on spiffs	
	if (!MyWebServer.isAuthorized()) return;

	String fname = "";	
	if (server.hasArg("fname")) { fname=server.arg("fname"); }

	if (fname == "") return server.send(200, "text/html", "Flashing File NOT FOUND");;
	DebugPrintln("FLashing :" + server.arg("fname"));
	MyWebServer.OTAisflashing = true;	
	//delay(200);
#ifdef SoftSerial
	qCon.enableRx(true);
#endif
	qCon.flush();	
//	delay(10);
	qCon.begin(115200);  //HM speed for flashing with optiboot	
	Esp8266AVRFlash.FlashAVR(&qCon, "/"+fname);  //flashAVR HM
	qCon.flush();  	
	server.send(200, "text/html", "Flashing AVR....please wait...will auto-reboot...do NOT touch system!!!");
	delay(2000);
	ESP.restart(); //restart ESP after reboot.....
}
开发者ID:nailbuster,项目名称:EspressModuleHM,代码行数:22,代码来源:globals.cpp

示例12: setSleepMode

/* This function enables low power SNIFF mode. Send a 4-byte string as the 
   sleepConfig variable
   "0000" = disabled
   e.g.: "0050" = Wake up every 50ms
   "8xxx" = Enables deep sleep mode */
uint8_t makeyMateClass::setSleepMode(char * sleepConfig)
{
  if (bluetooth.available())
    bluetooth.flush();	// Get rid of any characters in the buffer, we'll need to check it fresh

    bluetooth.print("SW,");  // SW sets the sniff mode
  bluetooth.print(sleepConfig);  // Should print ASCII vaule
  bluetooth.write('\r');

  delay(BLUETOOTH_RESPONSE_DELAY);  // Response will go to software serial buffer
  bluetoothReceive(rxBuffer);

  /* Double check the setting, output results in Serial monitor */
  bluetooth.flush();
  bluetooth.print("GW");
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  Serial.print("Deep Sleep Mode set to: ");
  while (bluetooth.available())
    Serial.write(bluetooth.read());

  return bluetoothCheckReceive(rxBuffer, "AOK", 3);
}
开发者ID:TildeWill,项目名称:MaKey-Mate-Bluetooth,代码行数:28,代码来源:makeyMate.cpp

示例13: setAuthentication

/* This function enables or disables authentication (pincode pairing)
   Two options are available for Authmode:
   0: Disabled
   1: Enabled */
uint8_t makeyMateClass::setAuthentication(uint8_t authMode)
{
  if (bluetooth.available())
    bluetooth.flush();	// Get rid of any characters in the buffer, we'll need to check it fresh

    bluetooth.print("SA,");  // SA sets the authentication
  bluetooth.print(authMode);  // Should print ASCII vaule
  bluetooth.write('\r');

  delay(BLUETOOTH_RESPONSE_DELAY);  // Response will go to software serial buffer
  bluetoothReceive(rxBuffer);

  /* Double check the setting, output results in Serial monitor */
  bluetooth.flush();
  bluetooth.print("GA");
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  Serial.print("Authentication Mode set to: ");
  while (bluetooth.available())
    Serial.write(bluetooth.read());

  return bluetoothCheckReceive(rxBuffer, "AOK", 3);
}
开发者ID:TildeWill,项目名称:MaKey-Mate-Bluetooth,代码行数:27,代码来源:makeyMate.cpp

示例14: reboot

/* This function issues the reboot command, and adds a lengthy delay to 
   give the RN-42 time to restart. */
uint8_t makeyMateClass::reboot(void)
{
  if (bluetooth.available())
    bluetooth.flush();	// Get rid of any characters in the buffer, we'll need to check it fresh

  bluetooth.print("R,1");  // reboot command
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  bluetoothReceive(rxBuffer);

  delay(BLUETOOTH_RESET_DELAY);

  return bluetoothCheckReceive(rxBuffer, "Reboot!", 7);
}
开发者ID:TildeWill,项目名称:MaKey-Mate-Bluetooth,代码行数:16,代码来源:makeyMate.cpp

示例15: setSpecialConfig

/* This function can send one of the 5 special configuration commands:
   0: Disable all special commands
   4: Disable reading values of GPIO3 and 6 on power-up.
   16: Configure firmware to optimize for low-latency transfers.
   128: Allow for fast reconnect.
   256: Set 2-stop bit mode on UART.
   
   Most of these are not recommended, but the low-latency is useful. */
uint8_t makeyMateClass::setSpecialConfig(uint8_t num)
{
  if (bluetooth.available())
    bluetooth.flush();	// Get rid of any characters in the buffer, we'll need to check it fresh

    bluetooth.print("SQ,");  // SQ sets special config
  bluetooth.print(num);  // Should print ASCII decimal vaule
  bluetooth.write('\r');

  delay(BLUETOOTH_RESPONSE_DELAY);  // Response will go to software serial buffer
  bluetoothReceive(rxBuffer);

  /* Double check the setting, output results in Serial monitor */
  bluetooth.flush();
  bluetooth.print("GQ");
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  Serial.print("Special Config set to: ");
  while (bluetooth.available())
    Serial.write(bluetooth.read());

  return bluetoothCheckReceive(rxBuffer, "AOK", 3);  
}
开发者ID:TildeWill,项目名称:MaKey-Mate-Bluetooth,代码行数:31,代码来源:makeyMate.cpp


注:本文中的SoftwareSerial::flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。