예제 #1
0
static void kbd_task(void *pvParameters)
{
    uint8_t idx = 0;
    bool last_state = false;
    char hikob[] = "-- HiKoB --";

    while (1)
    {
        /*  LED used to indicate if the device is set up  */
        if(kbd_get_state())
            leds_off(LED_1);

        last_state = false;
        leds_toggle(LED_0);
        vTaskDelay(configTICK_RATE_HZ/10);

        if(!button_state() && !last_state){	//if the button is pushed
            kbd_send(hikob[idx]);
            idx ++;
            last_state = true;
        }
        else{
            kbd_send(NO_CHAR);
            last_state = false;
        }

        if(idx > sizeof(hikob))
            idx = 0;
    }
}
예제 #2
0
/* Pesquisa de tecla */
int button_pressed(){
	int i;
	switch(buttonStatus_Pressed){
		case testButton_Pressed: // Testar se existe alguma tecla premida
						for(i=0; i<maxButton; ++i)
							if( button_state(i) ){
								buttonStatus_Pressed = pressedDebounce;
								initial = chrono_start();
								actualButton_Pressed = i;
								break;
							}
						break;
		case pressedDebounce: // Esperar tempo (debounce)
						if(chrono_timeout(initial, debounceTime)){
							if( button_state(actualButton_Pressed) ){
								write(&fifo, buttons[actualButton_Pressed].id);// escreve no fifobuffer
								buttonStatus_Pressed = testButton_Released;
								return 1; //botao premido
							}
							buttonStatus_Pressed = testButton_Pressed; // Nao ha tecla premida
						}
						break;						
		case testButton_Released: // verificar se botao continua pressionado
						if( !button_state(actualButton_Pressed) ){
							initial = chrono_start();
							buttonStatus_Pressed = releaseDebounce;
						}
						//return 1; //botao continua pressionado
						break;
		case releaseDebounce: // Debounce (botao largado)
						if(chrono_timeout(initial, debounceTime) ){
							if( button_state(actualButton_Pressed) ){
								buttonStatus_Pressed = testButton_Released; // continua premido
								//return 1;
							}
							else buttonStatus_Pressed = testButton_Pressed;
						}
						//else return 1;
						break;
		default:
						return 0;
	}
	return 0;
}
예제 #3
0
파일: main.c 프로젝트: makapuf/bitbox-mod
void game_snd_buffer(uint16_t *stream, int size)
{
	for (int i=0;i<size; i++) {

		if (sample_in_tick++==Player.samplesPerTick) {

			// check button for next song ...
			if (!button_state() && prev_but){
				set_led(vga_frame & 64);
				loadNextFile();
			} else {
				player();
			}
			prev_but=button_state();
			sample_in_tick=0;
		}
		stream[i] = mixer(stream); 
	}
} 
예제 #4
0
파일: demo.c 프로젝트: makapuf/bitbox
void game_frame()
{
    // if button pressed, send 'a' quickly
    if (button_state())
    	serial_putchar('a'); // low level output

    if (vga_frame%16) return;
    led=1-led;
    set_led(led);

    // echo input first character
    if (serial_rx_ready())
    	serial_putchar(serial_getchar()); // could block 
}
예제 #5
0
__attribute__((weak)) int main(void)
{
	game_init();

	while (1) {
		game_frame();

		// wait next frame.
		int oframe=vga_frame;
		while (oframe==vga_frame);

		set_led(button_state());
	}
}
예제 #6
0
파일: main.c 프로젝트: zyxstar/exam_c
int main(void)
{
	int ret;

	button_init();

	while(1){
		ret = button_state();	
		if(ret != 4)
			printf("button %d is down\n", ret);
	}

	return 0;
}
예제 #7
0
파일: main.c 프로젝트: makapuf/bitbox
int bitbox_main() {
	static int i;
	while(1) {
		set_led(button_state() || (i++ & 1<<20));
	}
}