Ejemplo n.º 1
0
void keypadSetup() {
    KEYPAD(DDR) = KEYPAD_ROWS;
    KEYPAD(PORT) = KEYPAD_COLS; // Rows pulled low; Columns pulled high

    KEYPAD_INT_PINS(DDR) = 0;
    KEYPAD_INT_PINS(PORT) = 0xff;
    KEYPAD_INT(PCMSK) = 0xff;
    PCICR = 1 << KEYPAD_INT(PCIE);
}
Ejemplo n.º 2
0
static void onPress() {
    // Don't trigger any interrupts while strobing the keypad
    KEYPAD_INT(PCMSK) = 0;

    // Pull low each row one by one to find which buttons are pressed
    uint8_t row = 0;
    KEYPAD(PORT) = (~(1 << KEYPAD_ROW0) & KEYPAD_ROWS) | KEYPAD_COLS;
    __builtin_avr_delay_cycles(2);
    uint8_t input = ~KEYPAD(PIN) & KEYPAD_COLS;

    if (!input) {
        row = 1;
        KEYPAD(PORT) = (~(1 << KEYPAD_ROW1) & KEYPAD_ROWS) | KEYPAD_COLS;
        __builtin_avr_delay_cycles(2);
        input = ~KEYPAD(PIN) & KEYPAD_COLS;
    }

    if (!input) {
        row = 2;
        KEYPAD(PORT) = (~(1 << KEYPAD_ROW2) & KEYPAD_ROWS) | KEYPAD_COLS;
        __builtin_avr_delay_cycles(2);
        input = ~KEYPAD(PIN) & KEYPAD_COLS;
    }

    if (!input) {
        row = 3;
        KEYPAD(PORT) = (~(1 << KEYPAD_ROW3) & KEYPAD_ROWS) | KEYPAD_COLS;
        __builtin_avr_delay_cycles(2);
        input = ~KEYPAD(PIN) & KEYPAD_COLS;
    }

    // Restore the keypad's state
    KEYPAD(PORT) = KEYPAD_COLS;
    KEYPAD_INT(PCMSK) = 0xff;

    // Decode the column
    uint8_t col = 0;
    if (input & (1 << KEYPAD_COL0))
        col = 0;
    else if (input & (1 << KEYPAD_COL1))
        col = 1;
    else if (input & (1 << KEYPAD_COL2))
        col = 2;
    else if (input & (1 << KEYPAD_COL3))
        col = 3;

    // Call the callback
    onKeypadPressCallback(pgm_read_byte(&keymap[row][col]));
}
Ejemplo n.º 3
0
int				ft_minishell(t_env *e)
{
	int			len;

	prompt(e);
	while ((len = read(e->fd, e->buf, READ_SIZE)) > 0)
	{
//printf("%d %d %d %d %d %d %d %d\n", e->buf[0], e->buf[1], e->buf[2], e->buf[3], e->buf[4], e->buf[5], e->buf[6], e->buf[7]);
		if (KEYPAD(e) || K_SUPPR(e) || CTRL_C(e))
			keypad_command(e);
		else if (COPY_KEY(e))
			copy_command(e);
		else if (CTRL_D(e))
		{
			if (*e->hist->cmd == '\0')
				break ;
		}
		else
			read_command(len, e->buf, e);
		if (!SHFT_KEY(e) && !CT_SH_KEY(e) && e->cpy.cpy != 0)
			rewrite_command(e);
		ft_memset(e->buf, 0, len);
	}
	return (len);
}
Ejemplo n.º 4
0
/**
 * Apply window-options to the readline panels.
 *
 * @param win Window
 * @return Void
 */
static void
apply_readline_options(WINDOW *win)
{
#define KEYPAD(win, b)   ((void) keypad(win, b))
#define NODELAY(win, b)  ((void) nodelay(win, b))
#define SCROLLOK(win, b) ((void) scrollok(win, b))
    if (!is_keypad(win)) {
	KEYPAD(win, 1);
    }
    if (is_nodelay(win)) {
	NODELAY(win, 0);
    }
    if (is_scrollok(win)) {
	SCROLLOK(win, 0);
    }
}