void TestSerialization::testVecPut()
{
	std::vector<u8> buf;

	putU8(&buf, 0x11);
	putU16(&buf, 0x2233);
	putU32(&buf, 0x44556677);
	putU64(&buf, 0x8899AABBCCDDEEFF);

	putS8(&buf, -128);
	putS16(&buf, 30000);
	putS32(&buf, -6);
	putS64(&buf, -43);

	putF1000(&buf, 53.53467f);
	putF1000(&buf, -300000.32f);
	putF1000(&buf, F1000_MIN);
	putF1000(&buf, F1000_MAX);

	putString(&buf, "foobar!");

	putV2S16(&buf, v2s16(500, 500));
	putV3S16(&buf, v3s16(4207, 604, -30));
	putV2S32(&buf, v2s32(1920, 1080));
	putV3S32(&buf, v3s32(-400, 6400054, 290549855));
	putV2F1000(&buf, v2f(500.65661f, 350.34567f));

	putWideString(&buf, L"\x02~woof~\x5455");

	putV3F1000(&buf, v3f(500, 10024.2f, -192.54f));
	putARGB8(&buf, video::SColor(255, 128, 50, 128));

	putLongString(&buf, "some longer string here");

	putU16(&buf, 0xF00D);

	UASSERT(buf.size() == sizeof(test_serialized_data));
	UASSERT(!memcmp(&buf[0], test_serialized_data, sizeof(test_serialized_data)));
}
int main (void)
{ 
    uint8_t setpoint = 0;	/* setpoint in degrees centigrade */
    uint8_t tempc = 0; 		/* temp reading in centigrade */
    
    DDRA = 0;
    DDRB = _BV(4);                 // Set line B4 to be an output, the rest are inputs.
    DDRD = 0;
    
    // Pull-ups on inputs:
    PORTA = InputMaskA;
    PORTB = InputMaskB;
    PORTD = InputMaskD; 
    

    /* We're not really usingthe timer but we'll keep it running... */
    CLKPR = (1 << CLKPCE);        // enable clock prescaler update
    CLKPR = 0;                    // set clock to maximum
    WDTCSR = 0x00;                // disable watchdog timer
    // Set up the timer interrupt:
    TCCR0A = 2;
    OCR0A = 128;
    TIFR = (1 << TOV0);           // clear interrupt flag
    TIMSK = (1 << OCIE0A);         // enable compare interrupt
    TCCR0B = (1 << CS01);         // start timer, prescale by 8

    /* set up the uart for serial debugging; baud rate and sys clock
     are set in UART.c. TX and RX are on X10 and X60 (PD0 PD1)
     switches, keep them OFF. UART rate set in */
    UART_Init();



    /* set up the bit-banged I2C channel to get temp readings, SDA and SCL
     pin assignments are in I2Cbang.c*/
    I2C_Init();

    // Pull-ups on inputs:
    PORTA = 0x03;
    DDRA &= ~(0x03);
    
    /* Sneaky here, in order to reduce wiring, power TC74 from VDD on
     PB3 and GND on PB1. SCLK is PB2 and SDAT is PB0, but those are
     set in i2cbang.c  Also drive PB7, PB6, PB5*/


    DDRB |=  0b11101010;
    PORTB |= 0b00001000;
    PORTB &= 0b11111101;
    //PORTB = InputMaskB;
    PORTD = InputMaskD; 

    sei();		// ENABLE global interrupts


    putstr("Therm 1.0\r\n");

    TurnCoilOff();

    /* like making waffles, throw the first batch away */
    GetTemp();
    _delay_ms(10);		

    GetTemp();
    _delay_ms(10);		


    /* preload the average buffer with the current temp */
    InitBuffer(GetTemp());
         
    for (;;) {  // main loop
        
      setpoint = GetSetPointFromDIP();

      tempc = GetTemp();

      putstr("\r\nsp: ");
      putU8(setpoint);


      putstr(" tc: ");
      putU8(tempc);
      /* add temp to running average, and get the average back */
      tempc = BufferTemp(tempc);
      putstr(" bt: ");
      putU8(tempc);

      putstr(" trig: ");
      putU8((uint8_t)IS_TRIGGERED);


      /* TRIGGER IN is thermostat override switch on PD6*/
      if ((tempc > setpoint) || IS_TRIGGERED) {
	TurnCoilOn();
      }
      else if (tempc <= setpoint - HYSTERESIS) {
	TurnCoilOff();
      }

      /* wait this many milliseconds */
      _delay_ms(500);		



    }
    return 0;
}