static void ed_cleanup(Ed *ed) { log_msg("ED", "ed_cleanup"); log_msg("ED", "%d", ed->state); if (BITMASK_CHECK(ED_RENAME, ed->state)) { del_param_list(ed->src.argv, ed->src.argc); unlink(ed->tmp_name); close(ed->fd); } if (BITMASK_CHECK(ED_CONFRM, ed->state)) del_param_list(ed->dest.argv, ed->dest.argc); if (!BITMASK_CHECK(ED_CLOSED, ed->state)) { ed_chown_plugin(ed); window_close_focus(); } else free(ed); }
/* debounce the inputs */ void input_task( void) { uint8_t value; static uint8_t old_address = 0; static uint8_t old_buttons = 0; /* only check the inputs every debounce time */ if (timer_interval_expired(&Debounce_Timer)) { timer_interval_reset(&Debounce_Timer); /* pins used are PA6, PA5, PA4, PA3, PA2, PA1, PA0 */ #if BDK_V1_HACK /* version 1 BDK - workaround */ value = (PINA & 0x7F); #else /* version 2 BDK - has inverted inputs */ value = ~PINA; value &= 0x7F; #endif if (value == old_address) { /* stable value */ Address_Switch = old_address; } old_address = value; #if (BDK_VERSION==4) /* pins used are PB3, PB2, PB1 */ value = BITMASK_CHECK(PINB, 0x0E); value >>= 1; #else /* pins used are PB4, PB3, PB2, PB1, PB0 */ value = BITMASK_CHECK(PINB, 0x1F); #endif if (value == old_buttons) { /* stable value */ Buttons = old_buttons; } old_buttons = value; }
void test_bitmaskCheck(void) { int i = 0xff; TEST_ASSERT_EQUAL(15, BITMASK_CHECK(i, 0xf)); }
int getButton(int button) { int buttons = getButtons(); return BITMASK_CHECK(buttons, button) ? BUTTON_ON : BUTTON_OFF; }