static inline void process_absolute(struct touchpad_dispatch *touchpad, struct evdev_device *device, struct input_event *e) { switch (e->code) { case ABS_PRESSURE: if (e->value > touchpad->pressure.touch_high && !(touchpad->state & TOUCHPAD_STATE_TOUCH)) on_touch(touchpad); else if (e->value < touchpad->pressure.touch_low && touchpad->state & TOUCHPAD_STATE_TOUCH) on_release(touchpad); break; case ABS_X: if (touchpad->state & TOUCHPAD_STATE_TOUCH) { touchpad->hw_abs.x = e->value; touchpad->event_mask |= TOUCHPAD_EVENT_ABSOLUTE_ANY; touchpad->event_mask |= TOUCHPAD_EVENT_ABSOLUTE_X; } break; case ABS_Y: if (touchpad->state & TOUCHPAD_STATE_TOUCH) { touchpad->hw_abs.y = e->value; touchpad->event_mask |= TOUCHPAD_EVENT_ABSOLUTE_ANY; touchpad->event_mask |= TOUCHPAD_EVENT_ABSOLUTE_Y; } break; } }
void Touch::run() { // Check if sampling should be initiated if (!m_sampling) { mode(INPUT_MODE); m_sampling = true; return; } // Sample the pin and discharge uint8_t state = is_clear(); mode(OUTPUT_MODE); clear(); m_sampling = false; // Was the pin discharge during the sampling period if (state) { m_start = RTT::millis(); if (!m_touched) { on_touch(); m_touched = true; } return; } // The pin was discharge; low-pass filter pin change if (m_touched && (RTT::since(m_start) > THRESHOLD)) { m_touched = false; } }
static inline void process_key(struct touchpad_dispatch *touchpad, struct evdev_device *device, struct input_event *e, uint32_t time) { uint32_t code; switch (e->code) { case BTN_TOUCH: if (!touchpad->has_pressure) { if (e->value && !(touchpad->state & TOUCHPAD_STATE_TOUCH)) on_touch(touchpad); else if (!e->value) on_release(touchpad); } break; case BTN_LEFT: case BTN_RIGHT: case BTN_MIDDLE: case BTN_SIDE: case BTN_EXTRA: case BTN_FORWARD: case BTN_BACK: case BTN_TASK: if (!touchpad->fsm.enable && e->code == BTN_LEFT && touchpad->finger_state == TOUCHPAD_FINGERS_TWO) code = BTN_RIGHT; else code = e->code; pointer_notify_button( &touchpad->device->base, time, code, e->value ? LIBINPUT_POINTER_BUTTON_STATE_PRESSED : LIBINPUT_POINTER_BUTTON_STATE_RELEASED); break; case BTN_TOOL_PEN: case BTN_TOOL_RUBBER: case BTN_TOOL_BRUSH: case BTN_TOOL_PENCIL: case BTN_TOOL_AIRBRUSH: case BTN_TOOL_MOUSE: case BTN_TOOL_LENS: touchpad->reset = 1; break; case BTN_TOOL_FINGER: if (e->value) touchpad->finger_state |= TOUCHPAD_FINGERS_ONE; else touchpad->finger_state &= ~TOUCHPAD_FINGERS_ONE; break; case BTN_TOOL_DOUBLETAP: if (e->value) touchpad->finger_state |= TOUCHPAD_FINGERS_TWO; else touchpad->finger_state &= ~TOUCHPAD_FINGERS_TWO; break; case BTN_TOOL_TRIPLETAP: if (e->value) touchpad->finger_state |= TOUCHPAD_FINGERS_THREE; else touchpad->finger_state &= ~TOUCHPAD_FINGERS_THREE; break; } }