Ejemplo n.º 1
0
void printDouble(double val, uint8_t precision){
  if(val < 0.0){
    printByte('-');
    val = -val;
  }
  printInteger((long)val);
  if(precision > 0) {
    printByte('.');
    unsigned long frac;
    unsigned long mult = 1;
    uint8_t padding = precision -1;
    while(precision--)
      mult *=10;
    if(val >= 0)
      frac = (val - (int)val) * mult;
    else
      frac = ((int)val- val) * mult;
    unsigned long frac1 = frac;
    while(frac1 /= 10 )
      padding--;
    while(padding--)
      printByte('0');
    printInteger(frac);
  }
}
Ejemplo n.º 2
0
const char* Hacklace::printStr(const char* st, byte src_mem_type)
{
	// print zero-terminated string
	// Characters are interpreted using the font.
	// Raw mode is entered by RAW_MODE_CHAR followed by number of raw bytes.
	// A pointer to the byte after the terminating zero is returned.
	
	byte ch, i;

	ch = readByte(st++, src_mem_type);
	while (ch) {
		if (ch == RAW_MODE_CHAR) {
			ch = readByte(st++, src_mem_type);		// read number of raw bytes that follow
			for (i=0; i<ch; i++) { printByte(readByte(st++, src_mem_type)); }
		} else {
			printChar(ch);
		}
		// insert spacing after a printable or user defined character
		// but not after fixed spaces or animations
		if ((ch < SPC8) || (ch > SPC1)) {
			for (i=0; i<spacing; i++) { printByte(0); }
		}
		ch = readByte(st++, src_mem_type);
	}
	return(st);
}
Ejemplo n.º 3
0
void positionCursor(uint8_t row, uint8_t col) {
	transmitByte(0x1b);  // <ESC>
	printString("[");
	printByte(row);
	printString(";");
	printByte(col);
	printString("H");
}
Ejemplo n.º 4
0
/*
 * print( c ) - prints a character adding an EOL and a carriage return
 * 
 */
void WaspUSB::println(char c)
{
	secureBegin();
	printByte(c, _uart);
	printNewline(_uart);
	secureEnd();
}
Ejemplo n.º 5
0
int main(void) {

  initUSART();
  char ramString[STRING_LEN];
  uint8_t counter;

  while (1) {
    printString("\r\n------------------\r\n");
    eeprom_read_block(ramString, eepromString, STRING_LEN);
    printString(ramString);

    printString("\r\nThe counter reads: ");
    counter = eeprom_read_byte(&eepromCounter);
    printByte(counter);

    printString("\r\nMy uint16_t value is: ");
    printWord(eeprom_read_word(&eepromWord));

    printString("\r\n   Enter a new introduction string below:\r\n");
    readString(ramString, STRING_LEN);
    eeprom_update_block(ramString, eepromString, STRING_LEN);
    counter++;
    eeprom_update_byte(&eepromCounter, counter);
  }
  return (0);
}
Ejemplo n.º 6
0
/*
 * print( b ) - prints an unsigned 8-bit integer adding an EOL and a carriage return
 * 
 */
void WaspUSB::println(uint8_t b)
{
	secureBegin();	
	printByte(b,  _uart);
	printNewline(_uart);
	secureEnd();
}
Ejemplo n.º 7
0
void BF_Print(BF* filter){
    for(int i=0;i<filter->byteLen;i++){
        printByte(filter->data[i]);
        printf(" ");
    }
    printf("\n");
}
Ejemplo n.º 8
0
/* getIfReady() - gets if GPRS module is ready or not
 *
 * This function gets if GPRS module is ready or not
 *
 * It modifies 'flag' if expected answer is not received after sending a command to GPRS module
 *
 * Returns nothing. It changes the value of 'not_ready'
*/
void	WaspGPRS::getIfReady()
{
	char command[20];
	char aux='"';
	uint8_t answer=0;
	long previous=0;
	
	printString(AT_COMMAND,PORT_USED);
	printByte('\r',PORT_USED);
	printByte('\n',PORT_USED);
/*	while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<3000) );*/
	delay(10);
	answer=waitForData("OK",2,0,0);
	if(answer==1) not_ready=0;
	else not_ready=1;
}
Ejemplo n.º 9
0
void printer::print(const char *characters) {
    while (*characters)
    {
        printByte(*characters++);
        delay(1);
    }
}
Ejemplo n.º 10
0
void printIntegerInBase(unsigned long n, unsigned long base){ 
  unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 
  unsigned long i = 0;
  if (n == 0) {
    printByte('0');
    return;
  } 
  while (n > 0) {
    buf[i++] = n % base;
    n /= base;
  }
  for (; i > 0; i--)
    printByte(buf[i - 1] < 10 ?
	      '0' + buf[i - 1] :
	      'A' + buf[i - 1] - 10);
}
int main(void) {
  initUSART();

  uint8_t myArray[] = { 10, 11, 12 };
  uint8_t *p;
  uint8_t i;
  p = &myArray[0];
  for (i = 0; i < sizeof(myArray); i++) {
    printByte(*(p + i));
    printString("\r\n");
    _delay_ms(1000);
  }


                                                       /* To use them: */
  char *stringPointer;
                /* Get the pointer to the string you want from PROGMEM */

  stringPointer = (char *) pgm_read_word(&stringIndex[0]);
  printString_Progmem(stringPointer);
                                                                 /* or */
  stringPointer = (char *) pgm_read_word(&stringIndex[1]);
  printString_Progmem(&stringPointer[0]);
                                                                 /* or */
  printString_Progmem(PSTR("And this string got inlined.\r\n"));

  while (1) {
    printData_Progmem(myData, sizeof(myData) / sizeof(myData[0]));
    printString("\r\n");
    _delay_ms(1000);
  }                                                  /* End event loop */
  return 0;                            /* This line is never reached */
}
Ejemplo n.º 12
0
void init_SD(void) 
{
		unsigned char i, response, retry=0 ;

		ENABLE_SD;
		do
		{
				for(i=0;i<10;i++)
					SPI_sendchar(0xff);
				response = SD_sendCommand(GO_IDLE_STATE, 0);      //send 'reset & go idle' command
				retry++;
				if(retry>0xfe) 
				{
					printString("SD init fail..Code: ");
					printByte(response);
					printString("Retry: ");
					printByte(retry);
					printString("\r\n");
					return ;
				} //time out
			 
		} while(response != 0x01);

		DISABLE_SD;
		SPI_sendchar (0xff);
		SPI_sendchar (0xff);

		retry = 0;

		do
		{
				response = SD_sendCommand(SEND_OP_COND, 0); //activate card's initialization process
				response = SD_sendCommand(SEND_OP_COND, 0); //same command sent again for compatibility with some cards
				retry++;
				if(retry>0xfe)
				{
					printString("SD Failed: SEND_OP_COND\r\n");
					return ; //time out
				}
		}while(response);

		SD_sendCommand(CRC_ON_OFF, 0); //disable CRC; deafault - CRC disabled in SPI mode
		SD_sendCommand(SET_BLOCK_LEN, 512); //set block size to 512

		printString("SD initialized\r\n");
		return;
}
Ejemplo n.º 13
0
void dump_debug_trace(void)
{
	int i=0;
	while (i < MAX_TRACE) {
		printByte(debug_trace_data[i++]);
		printString(" ");	
	}
}
Ejemplo n.º 14
0
size_t Print::printByte(uint8 * p, uint8 length, char sep) {
	size_t i, n = 0;
	for(i = 0; i < length; i++) {
		n += printByte(p[i]);
		n += print(sep);
	}
	return n;
}
Ejemplo n.º 15
0
void printInteger(long n)
{
  if(n < 0){
    printByte('-');
    n = -n;
  }
  printIntegerInBase(n, 10);
}
Ejemplo n.º 16
0
size_t Print::printByte(uint32 val) {
	size_t n = 0;
	n += printByte((uint8)(val>>24 &0xff));
	n += printByte((uint8)(val>>16 &0xff));
	n += printByte((uint8)(val>>8 &0xff));
	n += printByte((uint8)val);
	return n;
}
Ejemplo n.º 17
0
/* sendMail() - sends an email
 *
 * This function sends an email
 *
 * Returns '1' on success and '0' if error
*/
uint8_t WaspGPRS::sendMail(char* from, char* to, char* subject, char* body, char* user, char* passw, char* smtp_server, uint16_t port)
{
	uint8_t counter=0;
	char command[30];
	long previous=0;
	uint8_t answer=0;
	
	if(!setFlowControl()) return 0;
		
	if(!configureGPRS()) return 0;
		
	if(!setEmailParams(smtp_server, port, from)) return 0;
		
	if(!setEmailPwd(user, passw)) return 0;
		
	if(!setEmailDestination(to)) return 0;
		
	if(!setEmailSubject(subject)) return 0;
		
	while( body[counter]!='\0' ) counter++;
	counter+=2;
	
	serialFlush(PORT_USED);
	sprintf(command,"AT%s1,%u%c%c",AT_SMTP_SEND,counter,'\r','\n');
	printString(command,PORT_USED);
	previous=millis();
	while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<10000) );
	delay(10);
	answer=waitForData("CONNECT",20,0,0);
	if(answer!=1) return 0;
	
	printString(body,PORT_USED);
	printByte('\r',PORT_USED);
	printByte('\n',PORT_USED);
	
	previous=millis();
	while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<10000) );
	delay(10);
	answer=waitForData("OK",20,0,0);
	if(answer!=1) return 0;
	
	
	return 1;

}
Ejemplo n.º 18
0
void printStream(unsigned char stream[])
{
	int i = 0;
	while(stream[i]){
		printByte(stream[i]);
		i++;
	}
	printf("\n");
}
Ejemplo n.º 19
0
/*
 * print - It prints a buffer specifying the length of the buffer
 * 
 */
void WaspUSB::print(uint8_t* pointer, uint16_t length)
{
	secureBegin();
	for( uint16_t i = 0; i < length; i++ )
	{
		printByte( pointer[i], _uart);
	}	
	secureEnd();
}
Ejemplo n.º 20
0
    /*! 	
     \param  uint8_t dataTX : pointer to dataTX vector. 
    */ 	
	void WaspRFID::sendTX(uint8_t *dataTX, uint8_t length, uint8_t outLength)
	{

	    printByte(PREAMBLE, _uart);
		printByte(PREAMBLE, _uart);
		printByte(STARTCODE2, _uart); 
   
		for (int i = 0; i<length; i++) {
			printByte(dataTX[i], _uart);
		}
			printByte(POSTAMBLE, _uart);			
			getACK(); 
			waitResponse();    // 1C - receive response
			getData(outLength); 
			
		digitalWrite(MUX_USB_XBEE, LOW); 
		delay(_delay);
		}
Ejemplo n.º 21
0
void printer::print(const __FlashStringHelper *msg)
{
    const char PROGMEM *p = (const char PROGMEM *)msg;
    while (1) {
        unsigned char c = pgm_read_byte(p++);
        if (c == 0) break;
        printByte(c);
        delay(1);
    }
}
Ejemplo n.º 22
0
/*
 * print - It prints a buffer specifying the length of the buffer
 * This functions adds an End Of Line after printing the buffer
 * 
 */
void WaspUSB::println(uint8_t* pointer, uint16_t length)
{
	secureBegin();
	for( uint16_t i = 0; i < length; i++ )
	{		
		printByte((char)pointer[i], _uart);
	}
	printNewline(_uart);
	secureEnd();
}
Ejemplo n.º 23
0
/*
 * print( n ) - prints a long integer
 * 
 */
void WaspUSB::print(long n)
{
	secureBegin();
	if (n < 0) 
	{
		printByte('-',_uart);
		n = -n;
	}	
	printIntegerInBase((uint32_t)n, 10,  _uart);
	secureEnd();
}
Ejemplo n.º 24
0
/*
 * print( n ) - prints an integer adding an EOL and a carriage return
 * 
 */
void WaspUSB::println(int n)
{
	secureBegin();
	if (n < 0) 
	{
		printByte('-',_uart);
		n = -n;
	}	
	printIntegerInBase((uint32_t) n, 10,  _uart);
	printNewline(_uart);
	secureEnd();
}
Ejemplo n.º 25
0
void Hacklace::print0_99(byte val, byte y)
{
	// print a value in the range 0..99 using two mini-digits
	
	byte		i, bcd;

	if (val > 99) { val = 99; }

	// convert val to BCD format
	bcd = swap(val) & 0x0F;
	for (i=0; i<4; i++) {
		if ((bcd & 0x0F) > 4) { bcd += 3; }
		bcd <<= 1;  val <<= 1;
		if (val & 0x10) { bcd++; }
	}

	// print digits
	printMiniDigit(swap(bcd) & 0x0F, y);
	printByte(0);  printByte(0);
	printMiniDigit(bcd & 0x0F, y);
}
Ejemplo n.º 26
0
/* 01_anydata (b)
 * Print the given AnyData value, using one of the above functions
 */
void printValue(AnyData val) {
    switch (val.type) {
        case DOUBLE: 
            printDouble(val.value.dval);
            break;
        case INT: 
            printInt(val.value.ival);
            break;
        case BYTE: 
            printByte(val.value.bval);
            break;
    }
}
Ejemplo n.º 27
0
void print_debug(RHTresult *result) {
#if DEBUG
	printString("Bits:\r\n");
	for(int i = 0; i < 43; i++) { 
		printByte(i);
		printString(": ");
		printByte(tries_b[i]);
		printString("\r\n"); 
	}

	printString("\r\n\r\n");
	printString("Temperature: ");
	printWord(result->temperature);
	printString("\r\n");
	printString("Humidity: ");
	printWord(result->humidity);
	printString("\r\n");
	printString("Checksum: ");
	printByte(result->checksum);
	printString("\r\n\r\n");
#endif
}
Ejemplo n.º 28
0
/*
 * printFloat( number , digits ) - prints a 'float' number
 * Parameters: 
 * 		number : the number to print
 * 		digits : the number of non-integer part digits
 * 
 */
void WaspUSB::printFloat(double number, uint8_t digits) 
{
	secureBegin();
	
	// Handle negative numbers
	if (number < 0.0)
	{
		printByte('-', _uart);
		number = -number;
	}

	// Round correctly so that print(1.999, 2) prints as "2.00"
	double rounding = 0.5;
	for (uint8_t i=0; i<digits; ++i)
		rounding /= 10.0;
  
	number += rounding;

	// Extract the integer part of the number and print it
	unsigned long int_part = (unsigned long)number;
	double remainder = number - (double)int_part;	
	printIntegerInBase(int_part, 10, _uart);

	// Print the decimal point, but only if there are digits beyond
	if (digits > 0)
		printByte('.',_uart); 

	// Extract digits from the remainder one at a time
	while (digits-- > 0)
	{
		remainder *= 10.0;
		int toPrint = int(remainder);
		printIntegerInBase( (long) toPrint, 10,  _uart);
		remainder -= toPrint; 
	}
	secureEnd();
}
Ejemplo n.º 29
0
/*
 * 
 * name: sendCommand
 * @param	uint8_t* command: pointer to the buffer with the command to be sent
 * @param	uint16_t length: length of the buffer
 * @return 	void 
 */
void  WaspUART::sendCommand( uint8_t* command, uint16_t length )
{  	
	// clear uart buffer before sending command
	if( _flush_mode == true )
	{
		serialFlush(_uart); 		
	}
	
	/// print command
	for (uint16_t i = 0; i < length; i++)
	{
		printByte( command[i], _uart ); 
	}	

	delay( _def_delay );	
}
Ejemplo n.º 30
0
/*
 * printFloat( ifsh ) - prints a string from Flash memory
 * Parameters: 
 * 		ifsh : FlashStringHelper defined in Flash memory  		
 * 
 */
uint32_t WaspUSB::print(const __FlashStringHelper *ifsh)
{
	unsigned char c;
	
	secureBegin();
	const char * __attribute__((progmem)) p = (const char * ) ifsh;
	uint32_t retries = 1000;
	while( retries > 0 ) 
	{
		retries--;
		c = pgm_read_byte(p++);
		if (c == 0) break;		
		printByte(c,  _uart);
	}
	secureEnd();
	return 0;
}