Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 358d4f04 authored by Nathan Grebowiec's avatar Nathan Grebowiec
Browse files

Enable optional swipe based touch controls

Enabled via BOARD_RECOVERY_SWIPE := true in BoardConfig.mk.
Does not interfere with hardware keys, they continue to work.

Patchset 1) Initial set
Patchset 2) change Board Config variable
            don't add if BOARD_TOUCH_RECOVERY set
Patchset 3) more ifdef's for all!
Patchset 4) moved instructions
            even more stuff ifdef'ed
            no more abs name issues
Patchset 5) clean up commit message
Patchset 6) Move things to swipe.c to clean up ui.c
Patchset 7) white space

Change-Id: Id9844c38c31bd1985dd78a6d1dd81e71aa1f87f3
parent 3144dc22
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ BOARD_RECOVERY_CHAR_HEIGHT := $(shell echo $(BOARD_USE_CUSTOM_RECOVERY_FONT) | c

LOCAL_CFLAGS += -DBOARD_RECOVERY_CHAR_WIDTH=$(BOARD_RECOVERY_CHAR_WIDTH) -DBOARD_RECOVERY_CHAR_HEIGHT=$(BOARD_RECOVERY_CHAR_HEIGHT)

BOARD_RECOVERY_DEFINES := BOARD_HAS_NO_SELECT_BUTTON BOARD_UMS_LUNFILE BOARD_RECOVERY_ALWAYS_WIPES BOARD_RECOVERY_HANDLES_MOUNT BOARD_TOUCH_RECOVERY RECOVERY_EXTEND_NANDROID_MENU TARGET_USE_CUSTOM_LUN_FILE_PATH TARGET_DEVICE TARGET_RECOVERY_FSTAB
BOARD_RECOVERY_DEFINES := BOARD_RECOVERY_SWIPE BOARD_HAS_NO_SELECT_BUTTON BOARD_UMS_LUNFILE BOARD_RECOVERY_ALWAYS_WIPES BOARD_RECOVERY_HANDLES_MOUNT BOARD_TOUCH_RECOVERY RECOVERY_EXTEND_NANDROID_MENU TARGET_USE_CUSTOM_LUN_FILE_PATH TARGET_DEVICE TARGET_RECOVERY_FSTAB

$(foreach board_define,$(BOARD_RECOVERY_DEFINES), \
  $(if $($(board_define)), \
+10 −0
Original line number Diff line number Diff line
@@ -910,6 +910,16 @@ main(int argc, char **argv) {
    device_ui_init(&ui_parameters);
    ui_init();
    ui_print(EXPAND(RECOVERY_VERSION)"\n");

#ifdef BOARD_RECOVERY_SWIPE
#ifndef BOARD_TOUCH_RECOVERY
    //display directions for swipe controls
    ui_print("Swipe up/down to change selections.\n");
    ui_print("Swipe to the right for enter.\n");
    ui_print("Swipe to the left for back.\n");
#endif
#endif

    load_volume_table();
    process_volumes();
    vold_client_start(&v_callbacks, 0);

swipe.c

0 → 100644
+82 −0
Original line number Diff line number Diff line
static int in_touch = 0; // 1 = in a touch
static int slide_right = 0;
static int slide_left = 0;
static int touch_x = 0;
static int touch_y = 0;
static int old_x = 0;
static int old_y = 0;
static int diff_x = 0;
static int diff_y = 0;

static void reset_gestures() {
    diff_x = 0;
    diff_y = 0;
    old_x = 0;
    old_y = 0;
    touch_x = 0;
    touch_y = 0;
}

void swipe_handle_input(int fd, struct input_event *ev) {
    int abs_store[6] = {0};
    int k;

    ioctl(fd, EVIOCGABS(ABS_MT_POSITION_X), abs_store);
    int max_x_touch = abs_store[2];

    ioctl(fd, EVIOCGABS(ABS_MT_POSITION_Y), abs_store);
    int max_y_touch = abs_store[2];

    if(ev->type == EV_ABS && ev->code == ABS_MT_TRACKING_ID) {
        if(in_touch == 0) {
            in_touch = 1;
            reset_gestures();
        } else { // finger lifted
            ev->type = EV_KEY;
            int keywidth = gr_fb_width() / 4;
            if(slide_right == 1) {
                ev->code = KEY_POWER;
                slide_right = 0;
            } else if(slide_left == 1) {
                ev->code = KEY_BACK;
                slide_left = 0;
            }

            ev->value = 1;
            in_touch = 0;
            reset_gestures();
        }
    } else if(ev->type == EV_ABS && ev->code == ABS_MT_POSITION_X) {
        old_x = touch_x;
        float touch_x_rel = (float)ev->value / (float)max_x_touch;
        touch_x = touch_x_rel * gr_fb_width();

        if(old_x != 0) diff_x += touch_x - old_x;

        if(diff_x > 100) {
            slide_right = 1;
            reset_gestures();
        } else if(diff_x < -100) {
            slide_left = 1;
            reset_gestures();
        }
    } else if(ev->type == EV_ABS && ev->code == ABS_MT_POSITION_Y) {
        old_y = touch_y;
        float touch_y_rel = (float)ev->value / (float)max_y_touch;
        touch_y = touch_y_rel * gr_fb_height();

        if(old_y != 0) diff_y += touch_y - old_y;

        if(diff_y > 80) {
            ev->code = KEY_VOLUMEDOWN;
            ev->type = EV_KEY;
            reset_gestures();
        } else if(diff_y < -80) {
            ev->code = KEY_VOLUMEUP;
            ev->type = EV_KEY;
            reset_gestures();
        }
    }

    return;
}
+9 −1
Original line number Diff line number Diff line
@@ -134,6 +134,10 @@ static void update_screen_locked(void);

#ifdef BOARD_TOUCH_RECOVERY
#include "../../vendor/koush/recovery/touch.c"
#else
#ifdef BOARD_RECOVERY_SWIPE
#include "swipe.c"
#endif
#endif

// Return the current time as a double (including fractions of a second).
@@ -403,6 +407,10 @@ static int input_callback(int fd, short revents, void *data)
#ifdef BOARD_TOUCH_RECOVERY
    if (touch_handle_input(fd, ev))
        return 0;
#else
#ifdef BOARD_RECOVERY_SWIPE
    swipe_handle_input(fd, &ev);
#endif
#endif

    if (ev.type == EV_SYN) {