Exemple #1
0
// Send a byte array of UBX protocol to the GPS
void sendUBX(uint8_t *MSG, uint8_t len)
{
    int i;
    for(i=0; i<len; i++) {
        uart0SendByte(MSG[i]);
    }
}
_ssize_t _write_r (
	struct _reent *r,
	int file,
	const void *ptr,
	size_t len)
{
    int i;
    const uint8_t *p =
	(const uint8_t *) ptr;

    for (i = 0; i < len; i++) {
	if (*p == '\n' ) {
	    uart0SendByte('\r');
	}
	uart0SendByte(*p++);
    }

    return len;
}
// new code for _read_r provided by Alexey Shusharin - Thanks
_ssize_t _read_r(struct _reent *r, int file, void *ptr, size_t len)
{
    char c;
    int  i;
    unsigned char *p;

    p = (unsigned char*)ptr;

    for (i = 0; i < len; i++)
    {
	c = uart0GetByteWait();

	*p++ = c;
	uart0SendByte(c);

	if (c == 0x0D && i <= (len - 2))
	{
	    *p = 0x0A;
	    uart0SendByte(0x0A);
	    return i + 2;
	}
    }
    return i;
}
Exemple #4
0
void control(void)
{
  reset_timer5();
  uartFlushReceiveBuffer(1);

  a2dSetReference(ADC_REFERENCE_256V);
  delay_us(100);

  PORT_OFF(PORTB,7);

  while(1) {
    char read = uart1GetByte();
    if(read == 'U') { //Rangefinder only for the Hand! We only have 3 uart ports!
      uart0SendByte(0x22); //sends 4 bytes with the command to read distance (0x22)
      uart0SendByte(0x00); uart0SendByte(0x00);uart0SendByte(0x22);delay_us(50);
      uart0GetByte(); //we don't care about this byte
      rprintf("%d\r\n", 255*uart0GetByte() + uart0GetByte());
      uart0GetByte(); //we don't care about this byte
    } else if(read == 'L') {
      rprintf("%d\r\n", 255 - a2dConvert8bit(0));
    } else if(read == 'R') {
      rprintf("%d\r\n", 255 - a2dConvert8bit(1));
    } else if(read == 'D') {
      int buff='#';
      uart2SendByte('#'); uart2SendByte('o'); uart2SendByte('s');
      uart2SendByte('#'); uart2SendByte('f');
      delay_ms(60); // Do not change this delay or you'll get in trouble! 
      while(1) {
	buff = uart2GetByte();
	if(buff==10 || buff==13 || buff==-1) {
	  uart1SendByte('\r');
	  uart1SendByte('\n');
	  break;
	}
	uart1SendByte(buff);
      }
      while((buff=uart2GetByte()) != -1);
    }  else if(read == 'E') {
      int buff='#';
      uart3SendByte('#'); uart3SendByte('o'); uart3SendByte('s');
      uart3SendByte('#'); uart3SendByte('f');
      delay_ms(60); // Do not change this delay or you'll get in trouble! 
      while(1) {
	buff = uart3GetByte();
	if(buff==10 || buff==13 || buff==-1) {
	  uart1SendByte('\r');
	  uart1SendByte('\n');
	  break;
	}
	uart1SendByte(buff);
      }
      while((buff=uart3GetByte()) != -1);
    } else if(read == 'M') {
      int buff='#';
      uart2SendByte('#'); uart2SendByte('o'); uart2SendByte('t');
      uart2SendByte('#'); uart2SendByte('f');
      delay_ms(60); // Do not change this delay or you'll get in trouble! 
      while(1) {
	buff = uart2GetByte();
	if(buff==10 || buff==13 || buff==-1) {
	  uart1SendByte('\r');
	  uart1SendByte('\n');
	  break;
	}
	uart1SendByte(buff);
      }
      while((buff=uart2GetByte()) != -1);
    } else if(read == 'N') {
      int buff='#';
      uart3SendByte('#'); uart3SendByte('o'); uart3SendByte('t');
      uart3SendByte('#'); uart3SendByte('f');
      delay_ms(60); // Do not change this delay or you'll get in trouble! 
      while(1) {
	buff = uart3GetByte();
	if(buff==10 || buff==13 || buff==-1) {
	  uart1SendByte('\r');
	  uart1SendByte('\n');
	  break;
	}
	uart1SendByte(buff);
      }
      while((buff=uart3GetByte()) != -1);
    } else if(read == 'P') {
      PORT_ON(PORTB,6);
    } else if(read == 'p') {
      PORT_OFF(PORTB,6);
    } else if(read == 'Q') {
      PORT_ON(PORTB,7);
    } else if(read == 'q') {
      PORT_OFF(PORTB,7);
    } else if(read == 'X') {
      PORT_ON(PORTB,4);
    } else if(read == 'x') {
      PORT_OFF(PORTB,4);
    } else if(read == 'Y') {
      PORT_ON(PORTB,5);
    } else if(read == 'y') {
      PORT_OFF(PORTB,5);
    } 
    delay_us(50);
  }
}