Esempio n. 1
0
void ColorWidget::set_colors(const QList<QString>& colors)
{
    qDeleteAll(_buttons);
    _buttons.clear();

    _colors = colors;
    for (int i = 0; i < _colors.size(); ++i)
    {
        QPushButton* b = new QPushButton(this);
        b->setFixedWidth(b->height());
        b->setStyleSheet(QString("background-color: #%1; color: #ffffff;").arg(_colors[i]));
        _buttons << b;
        _layout->addWidget(b);
        _mapper->setMapping(b, i);
        connect(b, SIGNAL(clicked()), _mapper, SLOT(map()));
    }

    if (_colors.isEmpty())
    {
        button_pressed(-1);
    }
    else
    {
        button_pressed(0);
    }
}
Esempio n. 2
0
/*
 * \brief Button debounce routine.
 *
 * Helper function for debouncing the transmit button.
 * \return ret 1 if a button event is detected, 0 otherwise.
 *
 */
bool app_debounce_button(void) 
{
   
    uint8_t ret = 0;
    static uint8_t key_cnt;
    /*Read the current state of the button*/
   
    if (button_pressed()) // Button Pressed
    {
        if (key_cnt != COUNT_FOR_VALID_KEY_PRESS)
        {
            key_cnt++;
        }
    }
    else if (!(button_pressed()) && (key_cnt == COUNT_FOR_VALID_KEY_PRESS)) //Button released
    {
        ret = 1;
        key_cnt = 0;
    }
    else
    {
        key_cnt = 0;
    }
    return ret;
}
static enum hrtimer_restart button_event_timer_func(struct hrtimer *data)
{
	H2W_DBG("");
	
    if (switch_get_state(&hi->sdev) == HEADSET) {
       	if (gpio_get_value(hi->cable_in2) == BTN_STATE_RELEASED) {  /* FIH-SW2-MM-AY-TAP_headset_00 */
       		if (hi->ignore_btn)
                    hi->ignore_btn = 0;
       	else {
       		if (bn_state)
                    button_released();
       		else {
       		    if (!hi->ignore_btn) { /* FIH-SW2-MM-AY-TAP_headset_01 */
       		        button_pressed();
       		        button_released();
       		    } /* FIH-SW2-MM-AY-TAP_headset_01 */
       		}
       	}
    } else {
       	if (!hi->ignore_btn)
       		button_pressed();
       	}
    }

    return HRTIMER_NORESTART;
}
Esempio n. 4
0
int main(int argc, char **argv) {
	segments_init();
	buttons_init();

	uint8_t counters[4] = { 0, 0, 0, 0 };

#define INCR(i) \
	if (++counters[i] >= 10) { \
		counters[i] = 0; \
	}

	while (1) {
		buttons_update();
		if (button_is_down(0)) {
			INCR(0)
		}
		if (button_pressed(1)) {
			INCR(1)
		}
		if (button_pressed(2)) {
			INCR(2)
		}
		for (size_t i = 0; i < sizeof(counters) / sizeof(counters[0]); i++) {
			segments_set_digit(i, counters[i]);
		}
		segments_draw();
		_delay_ms(1);
	}
}
Esempio n. 5
0
/* Ler tecla do buffer */
int button_read(){
	int tecla=read(&fifo);
	if(tecla) return tecla;// existe tecla
	while( !button_pressed() ); // espera por tecla
	
	while( buttonStatus_Pressed != testButton_Pressed ) button_pressed();
	tecla = read(&fifo);
	return tecla; 
}
Esempio n. 6
0
int button_listener(){
	if(button_pressed(1)){
		return 1;
	}else if(button_pressed(2)) {
		return 2;
	}else if(button_pressed(3)){
		return 3;
	}else if(button_pressed(4)){
		return 4;
	}else
		return 0;
}
Esempio n. 7
0
int main(UNUSED int argc, char **argv) {
    pid_t pid = argv[1] ? atoi(argv[1]) : 1; /* for testing */

    void *event_system = IOHIDEventSystemCreate(NULL);
    if (!event_system) {
        ib_log("couldn't create HID event system");
    } else {

            /* consumer page -> Volume Increment */
        if (button_pressed(event_system, 0x0c, 0xe9) ||
            /* telephony page -> Flash */
            button_pressed(event_system, 0x0b, 0x21)) {
            ib_log("disabling due to button press");
            return 0;
        }
    }
    mach_port_t port = 0;
    kern_return_t kr = mach_port_allocate(mach_task_self(),
                                          MACH_PORT_RIGHT_RECEIVE,
                                          &port);
    if (kr) {
        ib_log("mach_port_allocate: %x", kr);
        return 0;
    }
    const char *lib = "/Library/Substitute/Helpers/posixspawn-hook.dylib";
    struct shuttle shuttle = {
        .type = SUBSTITUTE_SHUTTLE_MACH_PORT,
        .u.mach.right_type = MACH_MSG_TYPE_MAKE_SEND,
        .u.mach.port = port
    };
    char *error;
    int ret = substitute_dlopen_in_pid(pid, lib, 0, &shuttle, 1, &error);
    if (ret) {
        ib_log("substitute_dlopen_in_pid: %s/%s",
               substitute_strerror(ret), error);
        return 0;
    }
    /* wait for it to finish */
    static struct {
        mach_msg_header_t hdr;
        mach_msg_trailer_t huh;
    } msg;
    kr = mach_msg_overwrite(NULL, MACH_RCV_MSG, 0, sizeof(msg), port,
                            MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL,
                            &msg.hdr, 0);
    if (kr)
        ib_log("mach_msg_overwrite: %x", kr);
}
Esempio n. 8
0
void cec_callback(void *callback_data, uint32_t param0,
        uint32_t param1, uint32_t param2,
        uint32_t param3, uint32_t param4)
{
    VC_CEC_NOTIFY_T reason;
    uint32_t len, retval;

    reason  = (VC_CEC_NOTIFY_T) CEC_CB_REASON(param0);
    len     = CEC_CB_MSG_LENGTH(param0);
    retval  = CEC_CB_RC(param0);

#ifdef DEBUG
    printf("cec_callback: debug: "
            "reason=0x%04x, len=0x%02x, retval=0x%02x, "
            "param1=0x%08x, param2=0x%08x, param3=0x%08x, param4=0x%08x\n",
            reason, len, retval, param1, param2, param3, param4);
#endif

    if ( reason == VC_CEC_BUTTON_PRESSED ) {
        if ( len > 4 ) {
            printf("cec_callback: warning: len > 4, only using first parameter "
                    "reason=0x%04x, len=0x%02x, retval=0x%02x, "
                    "param1=0x%08x, param2=0x%08x, param3=0x%08x, param4=0x%08x\n",
                    reason, len, retval, param1, param2, param3, param4);
        }
        button_pressed(param1);
    } else if ( reason != VC_CEC_BUTTON_RELEASE ) {
        printf("cec_callback: unknown event: "
                "reason=0x%04x, len=0x%02x, retval=0x%02x, "
                "param1=0x%08x, param2=0x%08x, param3=0x%08x, param4=0x%08x\n",
                reason, len, retval, param1, param2, param3, param4);
    }
}
Esempio n. 9
0
int main()
{
	long sample_rate = 44100;
	
	// Sample rate sets how many samples are generated per second
	if ( buf.set_sample_rate( sample_rate ) )
		return 1; // out of memory
	buf.bass_freq( 0 ); // keep waveforms perfectly flat
	
	// Setup synth
	synth.output( &buf );
	synth.volume( 0.50 );
	
	while ( !button_pressed() )
	{
		// Mouse sets clock rate, higher to the right. The higher the clock
		// rate, the more packed the waveform becomes.
		long rate = sample_rate * (mouse_x() * 10 + 1);
		
		// Clock rate sets how many time units there are per second
		buf.clock_rate( rate );
		
		// Generate random waveform, with each transition spaced 50 clocks apart.
		srand( 1 );
		buf.clear();
		for ( int time = 0; time < 500; time += 50 )
			synth.update( time, rand() % 20 - 10 );
		
		buf.end_frame( 600 );
		
		show_buffer_unscaled( buf );
	}
	
	return 0;
}
void headset_button_event(int is_press, int type)
{
	HS_DBG();

	if (hi->hs_35mm_type == HEADSET_UNPLUG &&
	    hi->h2w_35mm_type == HEADSET_UNPLUG) {
		HS_LOG("IGNORE key %d (HEADSET_UNPLUG)", type);
		return;
	}

	if (!hs_hpin_stable()) {
		HS_LOG("IGNORE key %d (Unstable HPIN)", type);
		return;
	}

	if (!get_mic_state()) {
		HS_LOG("IGNORE key %d (Not support MIC)", type);
		return;
	}

	if (!is_press)
		button_released(type);
	else if (!atomic_read(&hi->btn_state))
		button_pressed(type);
}
Esempio n. 11
0
/** \brief This is the task function for monitoring the button and joysticks.
 *  \details This function monitors the "Target Set" button, and when it is pressed,
 *  updates shared variables "motor1_power_SHARED", and "motor2_power_SHARED" with adc_channel
 *  readings. If the button is NOT pressed, the motor power shareds are set to the effective
 *  "zero power" value of 512.(1024 adc values corresponding to full forward(1023), and
 *  full reverse(0);
 */
void task_sensors(void* pvParameters){
	uint8_t default_sensor_prio = uxTaskPriorityGet(NULL);
	portTickType xLastWakeTime;
    xLastWakeTime = xTaskGetTickCount();
    adc_init();
    uint16_t joystick_y;
    uint16_t joystick_x;
    button_init();
       
    while(1)
    {
        if(button_pressed()){
            joystick_y = adc_read(ADC_JOYSTICK_Y);
            joystick_x = adc_read(ADC_JOYSTICK_X);
            vTaskPrioritySet(NULL, configMAX_PRIORITIES - 1);
    	        motor1_power_SHARED = joystick_y;
    	        motor2_power_SHARED = joystick_x;
    	    vTaskPrioritySet(NULL, default_sensor_prio);
    	}
    	else{
	    vTaskPrioritySet(NULL, configMAX_PRIORITIES - 1);
    	        motor1_power_SHARED = 512;
    	        motor2_power_SHARED = 512;
    	    vTaskPrioritySet(NULL, default_sensor_prio);
	    }
    	vTaskDelayUntil(&xLastWakeTime, 100/portTICK_RATE_MS);
    }

	
}
Esempio n. 12
0
int main() {
	Button button;
	int status;
	
	start_buttons();
	
	status = camera_open();
	if (status == FALSE) {
		printf("Could not open the camera.\n");
		return 1;
	}
	
	while (TRUE) {
		button = button_pressed();
		switch (button) {
			case A_BUTTON: cv_show_image(RAW_IMAGE); break;
			case B_BUTTON: cv_show_image(GRAYSCALE); break;
			case C_BUTTON: cv_show_image(CANNY); break;
			case X_BUTTON: cv_show_image(HOUGHLINES); break;
			case Y_BUTTON: camera_update(); break;
			case Z_BUTTON: cv_show_image(RAW_IMAGE); break;
		}
	}
	
	camera_close();
	return 0;
}
Esempio n. 13
0
int main()
{
	while ( !button_pressed() )
	{
		setup_demo( buf, synth );
		
		// base frequency and amplitude on mouse position
		int period = mouse_x() * 100 + 10;
		int amplitude = mouse_y() * 9 + 1;
		
		// generate alternating signs of square wave, spaced by period
		int time = 0;
		while ( time < 1000 )
		{
			amplitude = -amplitude;
			synth.update( time, amplitude );
			time += period;
		}
		buf.end_frame( 1000 );
		
		show_buffer( buf );
	}
	
	return 0;
}
Esempio n. 14
0
//USER ISR
void EINT0_IRQHandler(void){
    if (EXTI_GetITStatus(EXTI_Line2) != RESET){
		if(pressed) pressed = 0;
		  else pressed = 1;
		button_pressed();
        EXTI_ClearITPendingBit(EXTI_Line2);
    }
}
Esempio n. 15
0
void wait_button_release(void)
{
	target_clock_t start = target_clock();
	while (target_clock() - start < TARGET_CLOCKS_PER_SEC / 10) {
		if (button_pressed())
			start = target_clock();
	}
}
Esempio n. 16
0
int main ( int argc, char **argv ) {
    // pid_t pid;
    int res, status_led, blinks;

    // Must be called with 3 arguments
    if ( argc != 3 ) usage();

    if ( access( argv[2], F_OK|X_OK ) != 0 ) {
        fprintf( stderr, "Command does not exist or is not executable!" );
        exit( EXIT_FAILURE );
    }

    // Open the serial port
    if ( ( fd = open( argv[1], O_RDWR | O_NDELAY ) ) < 0 ) {
        fprintf( stderr, "Failed to open serial port" );
        perror( "open" );
        exit( EXIT_FAILURE );
    }

    // Register signal handlers to turn off the LEDs before exiting
    signal( SIGINT, cleanup );
    signal( SIGTERM, cleanup );

    // turn off the red led and turn on the green one
    // to indicate that we're working
    setled( GREEN_LED, 0 );
    setled( RED_LED, 1 );

    /*
    // fork into the background
    if ( ( pid = fork() ) < 0 ) {
        perror( "fork failed" );
        exit( 1 );
    } else if ( pid > 0 ) {
        exit( 0 );
    }
    */

    // daemonize
    while( 1 ) {
        if ( button_pressed() ) {
            setled( GREEN_LED, 0 );
            setled( RED_LED, 1 );
            res = system( argv[2] );
            status_led = ( res == 0 ) ? GREEN_LED : RED_LED;
            blinks = 30;
            setled( GREEN_LED, 0 );
            setled( RED_LED, 0 );
            while ( blinks > 0 ) {
                setled( status_led, -1 );
                sleep( 1 );
            }
        }
        sleep( 1 );
    }
    return ( 1 );
}
Esempio n. 17
0
int main(unsigned r0) {
	hw_digital_input(BTN1);

	if (r0 == BOOT_MAGIC || !flash_valid() || button_pressed()) {
		bootloader_main();
	}

	jump_to_flash(FLASH_FW_ADDR, 0);
}
Esempio n. 18
0
//Program entry point
int main()
{
	setup();

	//If both buttons are pressed on startup enter test mode
	if(button_pressed(0) && button_pressed(1))
	{
		while(1)
			test_program();
	}
	else
	{
		while(1)
			main_program();
	}
	
	return 0;
}
Esempio n. 19
0
int
setFanOff(void)
{
        led_control(FAN, FAN_OFF);
        if( !button_pressed(BTN_FAN) )
                puts("1");
        else
                puts("ATE_ERROR");
}
Esempio n. 20
0
bool one2two() {
    bool pressed = button_pressed();
    if (pressed) {
        lcd.display();
        led.on();
        lcd.print("Counting!");
    }
    return pressed;
}
Esempio n. 21
0
/*
 * Updates the player.
 */
 int player_update(void) {
    if (button_pressed(3)) {
        y -= gravity;
    } else {
        y += gravity;
    }

    limit_y();
    return y;
 }
Esempio n. 22
0
/**
 * \brief Checks whether Configuartion Mode is selected or not
 *
 * This will be checked during the INIT state
 * \ingroup group_config_mode
 */
static void configuration_mode_selection(void)
{
	/* Is button pressed */
	if (button_pressed()) {
		/* Enable configuration mode */
		node_info.configure_mode = true;
	} else {
		node_info.configure_mode = false;
	}

	/*
	 * Wait for the user to release the button to proceed further, otherwise
	 * button press will start Peer search in Range measurement mode which
	 * is
	 * not an intended behavior
	 */
	while (button_pressed()) {
	}
}
Esempio n. 23
0
static irqreturn_t button_irq_handler(int irq, void *dev_id)
{
    struct hsd_info *hi = (struct hsd_info *) dev_id;
    int value = 0;
    int fp = read_file(EARJACK_FILENAME);

    if(fp < 0)
    {


        HSD_DBG("button_irq_handler");

        value = gpio_get_value_cansleep(hi->gpio_key);

        if (value) button_pressed(hi);
        else button_released(hi);

        return IRQ_HANDLED;
    }
    else
    {
        if(fp)
        {

            HSD_DBG("button_irq_handler");

            value = gpio_get_value_cansleep(hi->gpio_key);

            if (value) button_pressed(hi);
            else button_released(hi);

            return IRQ_HANDLED;
        }
        else
        {

            return IRQ_NONE;
        }
    }

    return IRQ_NONE;
}
Esempio n. 24
0
void EMSCRIPTEN_KEEPALIVE main_loop(void)
{
    time_t now = time(NULL);
    static time_t graph_update;
    char url[64];
    static int tatami = 1;
    static time_t forced_update;
#if 1
    SDL_Event event;
    while (SDL_PollEvent(&event)) {
	switch(event.type) {
	case SDL_MOUSEBUTTONDOWN: {
	    SDL_MouseButtonEvent *m = (SDL_MouseButtonEvent*)&event;
	    //printf("button down: %d,%d  %d,%d\n", m->button, m->state, m->x, m->y);
	    button_pressed(m->x, m->y);
	    break;
	}
	}
    }

    if (now > next_update ||
	now > forced_update + 3 ||
	icontimer == 1) {
	refresh_window();
	forced_update = now;
    }

    timeout_ask_for_data(NULL);

    if (now > graph_update+2) {
	graph_update = now;
	emscripten_async_wget_data("matchinfo?t=0", NULL, onloadabstract, onerror);
    }

    mouse_move();

    if (icontimer > 0) {
	icontimer--;
    }

    SDL_Rect dest;
    dest.x = dest.y = dest.w = dest.h = 0;
    //dest.y = icontimer - 50;
    //if (dest.y > 0) dest.y = 0;
    if (menuicon && icontimer > 2) {
	SDL_BlitSurface(menuicon, NULL, darea, &dest);
    }

    if (menu_on && menubg) {
	icontimer = 50;
	show_menu();
    }
#endif
}
Esempio n. 25
0
void select_note(void)
{
    // Light up buttons according to data
    display_pattern();

    // Go through each of the 16 upper buttons
    for (uint8_t i = 0; i < 16; i++) {
        if (button_pressed(i)) {
            enter_note_init(i);
            break;
        }
    }

    leds_7seg_set(4, current_channel + 1);

    if (button_pressed(BTN_BACK)) {
        for (uint8_t i = 0; i < 16; i++)
            button_led_off(i);
        state = STATE_TOPLEVEL;
    }
}
Esempio n. 26
0
void check_hook_key_state_work_func(struct work_struct *work)
{
	int hook_key_status = 0;
	int rc = 0;
	unsigned long irq_flags;

	HEADSET_DBG("");
	if ( HSD_HEADSET != g_headset_type )
	{
		HEADSET_INFO("Headset remove!! or may ear phone noise !!");
		
		return;
	}
	hook_key_status = gpio_get_value(headset_data.hook_gpio);
	if ( 1 == hook_key_status )
	{
		
		button_pressed();
		atomic_set(&headset_data.is_button_press, 1);
		
		
		rc = set_irq_type(headset_data.hook_irq, IRQF_TRIGGER_LOW);
		if (rc)
			HEADSET_ERR( "change hook key detection type as low fail!!");

	}
	else
	{
		if ( 1 == atomic_read(&headset_data.is_button_press))
		{
			
			button_released();
			atomic_set(&headset_data.is_button_press, 0);
			
			
			rc = set_irq_type(headset_data.hook_irq, IRQF_TRIGGER_HIGH);
			HEADSET_DBG("Hook Key release change hook key detection type as high");
			if (rc)
				HEADSET_ERR("change hook key detection type as high fail!!");
		}
	}
	
	if ( HSD_IRQ_DISABLE == headset_data.hook_irq_status)
	{
		local_irq_save(irq_flags);
		
		enable_irq(headset_data.hook_irq);
		headset_data.hook_irq_status = HSD_IRQ_ENABLE;
		set_irq_wake(headset_data.hook_irq, 1);
		local_irq_restore(irq_flags);

	}
}
Esempio n. 27
0
//
// Функция ожидания, с остановом при нажатой кнопке.
//
void wait (unsigned msec, int button)
{
    unsigned t0 = timer_milliseconds (&timer);

    while (button_pressed (button) ||
           timer_milliseconds (&timer) - t0 < msec)
    {
        // Если нажата указанная кнопка - ждём,
        // пока она не освободится.
        timer_delay (&timer, 10);
    }
}
Esempio n. 28
0
/* Pattern selection state */
void select_pattern(void)
{

    if (state == STATE_SAVE) {
        sequencer_pattern_save(current_pattern);
        state = STATE_TOPLEVEL;
    }

    else if (ui_updown((int8_t*)&current_pattern, 0, 99))
        sequencer_pattern_load(current_pattern);

    else if (button_pressed(BTN_SAVE)) {
        save_init(&current_pattern);
    }

    for (uint8_t b = 0; b < 5; b++) {
        if (button_pressed(b)) {
            current_channel = b;
            state = STATE_SELECT_NOTE;
        }
    }

    if (button_pressed(BTN_PLAY)) {
        sequencer_play();
        state = STATE_PLAYING;
    }

    if (button_pressed(BTN_SCALE)) {
        getvalue.button1 = BTN_SCALE;
        getvalue.button2 = 0xFF;
        getvalue.parameter.target = &sequencer_pattern.scale;
        getvalue.parameter.type = SCALE;
        getvalue.parameter.min = 0;
        getvalue.parameter.max = 2;
        getvalue.previous_mode = mode;
        mode = MODE_GETVALUE;
    }

    leds_7seg_two_digit_set(3, 4, current_pattern);
}
Esempio n. 29
0
void enter_note(void)
{
    // Check if any of the note buttons have been pressed:
    uint8_t note = 0xFF;
    for (uint8_t i = 0; i < 16; i++) {
        if (button_pressed(i))
            note = btn_to_note(i);
    }

    // If none of the on-board keys were pressed, check MIDI:
    if (sequencer_midi_note != 0xFF)
        note = sequencer_midi_note;

    if (note != 0xFF) {
        sequencer_pattern.notes[current_channel][current_note].note = note;
        sequencer_pattern.notes[current_channel][current_note].length = channel_length[current_channel];
        enter_note_exit();
    }

    // Other button presses:
    else if (button_pressed(BTN_NOTE_CLEAR)) {
        sequencer_pattern.notes[current_channel][current_note].length = 0;
        enter_note_exit();
    }

    else if (button_on(BTN_OCTAVE)) {
        leds_7seg_two_digit_set(3, 4, channel_octave[current_channel]);
        ui_updown((int8_t*)&channel_octave[current_channel], 1, 7);
    }

    else if (button_pressed(BTN_OK))
        enter_note_exit();

    else {
        leds_7seg_two_digit_set(3, 4, channel_length[current_channel]);
        ui_updown((int8_t*)&channel_length[current_channel], 1, 4);
    }

}
static enum hrtimer_restart button_35mm_event_timer_func(struct hrtimer *data)
{
	printk(KERN_INFO "%s\n", __func__);
	if (gpio_get_value(hi->gpio_headset_mic)) {
		button_pressed();
		hi->btn35mm_debounce_time = ktime_set(0, 200 * 1000 * 1000);
	} else {
		button_released();
		hi->btn35mm_debounce_time = ktime_set(0, 500 * 1000 * 1000);
	}

	return HRTIMER_NORESTART;
}