/* We record offsets in a bitmap for the particular chain it should be in.  */
static void record_offset(unsigned char bits[], tdb_off_t off)
{
	uint32_t h1 = off, h2 = 0;
	unsigned int i;

	/* We get two good hash values out of jhash2, so we use both.  Then
	 * we keep going to produce further hash values. */
	for (i = 0; i < NUM_HASHES / 2; i++) {
		hash(off, &h1, &h2);
		bit_flip(bits, h1 % BITMAP_BITS);
		bit_flip(bits, h2 % BITMAP_BITS);
		h2++;
	}
}
Exemple #2
0
void LCD_update( void )
{
	int i,j;

	#ifdef LCD_NO_SKIP_UPDATE
	if(1)
	#else
	if(LCD.update_rows) //if any rows to update
	#endif
	{
		for(i=0; i<HW_ROWS; i++)
		{
			#ifdef LCD_FORCE_TOTAL_UPDATE
			if(1)
			#else
			if(LCD.update_rows & (1<<i))
			#endif
			{
				#ifdef LCD_UPDATE_DEBUG
					bit_flip(lcd_update_toggler,1<<i);
				#endif
				LCD_writeCommand (0x80);   //column
				LCD_writeCommand (0x40|(HW_ROWS-1-i));   //row

				for(j=HW_COLUMNS; j>0; j--)
				{
					#ifdef LCD_UPDATE_DEBUG
					if(lcd_update_toggler&(1<<i))
						LCD_writeData(~lcd_buffer[i][j-1]);
					else
					#endif
						LCD_writeData(lcd_buffer[i][j-1]);
				}
			}
		}
		LCD.update_rows=0;
		LCD_gotoXY (0,0);	//bring the XY position back to (0,0)
	}

}
void sig_handler(int sig)
{
    gettimeofday(&recvtime, NULL);
    show_stackframe();
    bit_flip();
}
int main(void)
{
    bit_set(DDRB, BIT(3));
    bit_set(DDRB, BIT(2));
    bit_clear(PORTB, BIT(3));
    bit_set(PORTB, BIT(2));
    pwm_init();
    adc_init();
    int recording = 0;
    int saved;
    int playing = 0;
    int reading;
    int noteSlot = 0;
    while(1)
    {
        if(playing)
        {
            // GET NOTE
            reading = eeprom_read_byte ((uint8_t*)noteSlot);
            reading = reading * 4;
            //reading = 900;
        }
        else
        {
            // READ ADC
            reading = adc_read();
        }


        if (reading < 128)
        {
            bit_clear(PORTB, BIT(3));
            //bit_clear(PORTB, BIT(2));
            dontplay();

            if(recording){
                bit_clear(PORTB, BIT(2));
                _delay_ms(10);
                if(adc_read()==reading)
                {
                    saved = 0;
                }
            }
		}
		else
		{
            if(recording && !saved)
            {
                // RECORD NOTE
                int readingLess = reading / 4;
                eeprom_write_byte ((uint8_t *)noteSlot, (uint8_t)readingLess);

                noteSlot++;
                if(noteSlot>60)
                {
                    recording = 0;
                    noteSlot = 0;
                    bit_flip(PORTB, BIT(2));
                }
                else
                {
                    saved = 1;
                }
           }
            
            
            bit_set(PORTB, BIT(3));
            if(recording) bit_set(PORTB, BIT(2));
            if ((reading <= 310)) // RECORD
            {
                // DEBOUNCE
                _delay_ms(50);
                if(adc_read()==reading)
                {
                    // Debounce ok, toggle recording mode
                    recording = !recording;
                    if(!recording)
                    {
                        noteSlot++;
                        eeprom_write_byte ((uint8_t *)noteSlot, (uint8_t)0);
                    }
                    noteSlot = 0;
                    //bit_flip(PORTB, BIT(2));

                    while(adc_read()>128){}
                }
            }
            else if ((reading <= 340)) // PLAY
            {
                if(!recording){
                    _delay_ms(2);
                    int secondRead = adc_read();
                    if(secondRead==reading || secondRead==reading+1 || secondRead==reading-1 || secondRead==reading+2 || secondRead==reading-2)
                    {
                        // Debounce ok, start playing
                        playing = 1;
                        noteSlot = 0;
                        bit_clear(PORTB, BIT(2));
                    }
                    while(adc_read()>128){}
                }
            }
            else if ((reading <= 359))
            {
                playnote(A1);
            }
            else if (reading <= 380)
            {
                playnote(AS1);
            }
            else if (reading <= 387)
            {
                playnote(B1);
            }
            else if (reading <= 402)
            {
                playnote(C1);
            }
            else if (reading <= 418)
            {
                playnote(CS1);
            }
            else if (reading <= 436)
            {
                playnote(D1);
            }
            else if (reading <= 455)
            {
                playnote(DS1);
            }
            else if (reading <= 477)
            {
                playnote(E1);
            }
            else if (reading <= 500)
            {
                playnote(F1);
            }
            else if (reading <= 525)
            {
                playnote(FS1);
            }
            else if (reading <= 554)
            {
                playnote(G1);
            }
            else if (reading <= 586)
            {
                playnote(GS1);
            }
            else if (reading <= 621)
            {
                playnote(A2);
            }
            else if (reading <= 661)
            {
                playnote(AS2);
            }
            else if (reading <= 707)
            {
                playnote(B2);
            }
            else if (reading <= 760)
            {
                playnote(C2);
            }
            else if (reading <= 821)
            {
                playnote(CS2);
            }
            else if (reading <= 892)
            {
                playnote(D2);
            }
            else if (reading <= 977)
            {
                playnote(DS2);
            }
            else if (reading > 977)
            {
                playnote(E2);
            }
        }

        if(playing)
        {
            // wait for time
            _delay_ms(200);
            dontplay();
            _delay_ms(200);
            noteSlot++;
            if(noteSlot>60 || reading==0)
            {
                noteSlot = 0;
                playing = 0;
                bit_set(PORTB, BIT(2));
            }
        }
        else
        {
            // loop quickly
            _delay_us(255);
        }
    }
}