<commit_before>#include <pebble.h>
#include "screen.h"
#include "configs.h"
#include "keys.h"

static bool initialized;
static int lastPassZ;
static int lastZ;
static bool begin_tap;
static bool mid_tap;
static bool end_tap;
static bool neg;
static int mid_tap_count;
static int end_tap_count;
static bool show_tap_mode;
static int timeout_sec;

static Window *watchface_ref;

static void reset_tap() {
    begin_tap = false;
    mid_tap = false;
    end_tap = false;
    end_tap_count = 0;
    mid_tap_count = 0;
}

static void reset_tap_handler(void * data) {
    show_tap_mode = false;
    redraw_screen(watchface_ref);
}

void accel_data_handler(AccelData *data, uint32_t num_samples) {
    if (show_tap_mode) {
        return;
    }

    int passZ[2];
    int Z[2];
    int X[2];
    int Y[2];

    if (!initialized) {
        passZ[0] = passZ[1] = data[0].z;
        Z[0] = Z[1] = data[0].z;
        initialized = true;
        show_tap_mode = false;
        reset_tap();
    } else {
        passZ[0] = passZ[1] = lastPassZ;
        Z[0] = Z[1] = lastZ;
    }

    X[0] = X[1] = data[0].x;
    Y[0] = Y[1] = data[0].y;

    float a = 0.1;
    int high_threshold = 30;
    int low_threshold = 10;
    int range = 2;
    int x_threshold = 350;
    int y_threshold = 150;
    for (int i = 1; i < (int)num_samples + 1; ++i) {
        Z[1] = data[i-1].z;
        X[1] = data[i-1].x;
        Y[1] = data[i-1].y;

        passZ[1] = (int) (a * (passZ[0] + Z[1] - Z[0]));

        if (!end_tap && mid_tap) {
            if (end_tap_count < 3*range) {
                end_tap_count++;
                if (abs(passZ[1]) <= abs(low_threshold)) {
                    end_tap = true;
                }<commit_msg>increasing tap sensitivity and ignoring accel event when watch vibrates<commit_after>#include <pebble.h>
#include "screen.h"
#include "configs.h"
#include "keys.h"

static bool initialized;
static int lastPassZ;
static int lastZ;
static bool begin_tap;
static bool mid_tap;
static bool end_tap;
static bool neg;
static int mid_tap_count;
static int end_tap_count;
static bool show_tap_mode;
static int timeout_sec;

static Window *watchface_ref;

static void reset_tap() {
    begin_tap = false;
    mid_tap = false;
    end_tap = false;
    end_tap_count = 0;
    mid_tap_count = 0;
}

static void reset_tap_handler(void * data) {
    show_tap_mode = false;
    redraw_screen(watchface_ref);
}

void accel_data_handler(AccelData *data, uint32_t num_samples) {
    if (show_tap_mode || data[0].did_vibrate || data[1].did_vibrate) {
        return;
    }

    int passZ[2];
    int Z[2];
    int X[2];
    int Y[2];

    if (!initialized) {
        passZ[0] = passZ[1] = data[0].z;
        Z[0] = Z[1] = data[0].z;
        initialized = true;
        show_tap_mode = false;
        reset_tap();
    } else {
        passZ[0] = passZ[1] = lastPassZ;
        Z[0] = Z[1] = lastZ;
    }

    X[0] = X[1] = data[0].x;
    Y[0] = Y[1] = data[0].y;

    float a = 0.2;
    int high_threshold = 40;
    int low_threshold = 10;
    int range = 2;
    int x_threshold = 350;
    int y_threshold = 150;
    for (int i = 1; i < (int)num_samples + 1; ++i) {
        Z[1] = data[i-1].z;
        X[1] = data[i-1].x;
        Y[1] = data[i-1].y;

        passZ[1] = (int) (a * (passZ[0] + Z[1] - Z[0]));

        if (!end_tap && mid_tap) {
            if (end_tap_count < 3*range) {
                end_tap_count++;
                if (abs(passZ[1]) <= abs(low_threshold)) {
                    end_tap = true;
                }
{'fraction_non_alphanumeric': 0.1404206935758954, 'fraction_numerical': 0.029562251279135872, 'mean_word_length': 2.3135593220338984, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2581802', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1347, 'n_words': 323}