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


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

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


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

示例1: 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

示例2: echoMode

/* echoMode() will set up an echo interface betwen bluetooth and the Arduino hardware serial
	This is mostly useful if you're having trouble connecting from the BlueSMiRF to MetaWatch.
	
	Anything sent to the Arduino's hardware serial (e.g. entered into the Serial Monitor)
	will be echoed out to the software serial (bluetooth module). ANything sent to the bluetooth
	module will be echoed out of the Arduino's hardware serial (e.g. visible in the Serial monitor).
	
	It's not recommended to try to send message packets to the watch using this echo mode (unless
	you're some kind of genius CRC calculator).
	
	To exit echo mode, type ~~~.
*/
void SFE_MetaWatch::echoMode()
{
	int c;
	int tildeCount = 0;
	Serial.println("Echo mode. Press ~~~ to escape.");

	while(tildeCount < 3)
	{
		if (bt.available())
		{
			c = bt.peek();
			Serial.write(bt.read());
			if (c == '~') tildeCount++;
		}
		if (Serial.available())
		{
			c = Serial.peek();
			bt.write(Serial.read());
			if (c == '~') tildeCount++;
		}
	}
	Serial.println("Exiting echo mode...");
}
开发者ID:JLJames,项目名称:SparkFun_MetaWatch_Library,代码行数:35,代码来源:SparkFun_MetaWatch.cpp

示例3: readData

// * Receiving the lenght of bytes from Serial port
void HerkulexClass::readData(int size)
{
	int i = 0;
    int beginsave=0;
    int Time_Counter=0;
    switch (port)
	{
	case SSerial:

        while((SwSerial.available() < size) & (Time_Counter < TIME_OUT)){
        		Time_Counter++;
        		delayMicroseconds(1000);  //wait 1 millisecond for 10 times
		}
        	
		while (SwSerial.available() > 0){
			byte inchar = (byte)SwSerial.read();
			if ( (inchar == 0xFF) & ((byte)SwSerial.peek() == 0xFF) ){
					beginsave=1; 
					i=0; 				 // if found new header, begin again
			}
			if (beginsave==1 && i<size) {
				   dataEx[i] = inchar;
				   i++;
			}
		}
		SwSerial.flush();
		break;
	
	#if defined (__AVR_ATmega1280__) || defined (__AVR_ATmega128__) || defined (__AVR_ATmega2560__)
	case HSerial1:
		while((Serial1.available() < size) & (Time_Counter < TIME_OUT)){
				Time_Counter++;
				delayMicroseconds(1000);
		}
		while (Serial1.available() > 0){
			byte inchar = (byte)Serial1.read();
			//printHexByte(inchar);
			if ( (inchar == 0xFF) & ((byte)Serial1.peek() == 0xFF) ){
				beginsave=1;
				i=0;
			}
            if (beginsave==1 && i<size) {
                       dataEx[i] = inchar;
                       i++;
			}
		}
		break;
	
	case HSerial2:
	    while((Serial2.available() < size) & (Time_Counter < TIME_OUT)){
        		Time_Counter++;
        		delayMicroseconds(1000);
		}
        	
		while (Serial2.available() > 0){
			byte inchar = (byte)Serial2.read();
			if ( (inchar == 0xFF) & ((byte)Serial2.peek() == 0xFF) ){
					beginsave=1;
					i=0; 					
			}
			if (beginsave==1 && i<size) {
				   dataEx[i] = inchar;
				   i++;
			}
		}
		break;

	case HSerial3:
		while((Serial3.available() < size) & (Time_Counter < TIME_OUT)){
			Time_Counter++;
			delayMicroseconds(1000);
		}
		
		while (Serial3.available() > 0){
			byte inchar = (byte)Serial3.read();
			if ( (inchar == 0xFF) & ((byte)Serial3.peek() == 0xFF) ){
					beginsave=1;
					i=0; 
			}
			if (beginsave==1 && i<size) {
				   dataEx[i] = inchar;
				   i++;
			}
		}
		break;
	#elif (__AVR_ATmega32U4__)
	case HSerial1:
		while((Serial1.available() < size) & (Time_Counter < TIME_OUT)){
			Time_Counter++;
			delayMicroseconds(1000);
		}
		while (Serial1.available() > 0){
			byte inchar = (byte)Serial1.read();
			//printHexByte(inchar);
			if ( (inchar == 0xFF) & ((byte)Serial1.peek() == 0xFF) ){
				beginsave=1;
				i=0;
			}
            if (beginsave==1 && i<size) {
//.........这里部分代码省略.........
开发者ID:MechanicalCoder,项目名称:Prosthetic-Hands,代码行数:101,代码来源:Herkulex.cpp


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