Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haptic: driver-> feature #13713

Merged
merged 6 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,9 @@ endif
HAPTIC_ENABLE ?= no
ifneq ($(strip $(HAPTIC_ENABLE)),no)
COMMON_VPATH += $(DRIVER_PATH)/haptic
SRC += haptic.c
OPT_DEFS += -DHAPTIC_ENABLE
SRC += $(QUANTUM_DIR)/haptic.c
SRC += $(QUANTUM_DIR)/process_keycode/process_haptic.c
endif

ifneq ($(filter DRV2605L, $(HAPTIC_ENABLE)), )
Expand Down
133 changes: 3 additions & 130 deletions drivers/haptic/haptic.c → quantum/haptic.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
#include "haptic.h"
#include "eeconfig.h"
#include "progmem.h"
#include "debug.h"
#ifdef DRV2605L
# include "DRV2605L.h"
Expand All @@ -28,7 +27,6 @@
haptic_config_t haptic_config;

void haptic_init(void) {
debug_enable = 1; // Debug is ON!
if (!eeconfig_is_enabled()) {
eeconfig_init();
}
Expand Down Expand Up @@ -65,7 +63,7 @@ void haptic_task(void) {
}

void eeconfig_debug_haptic(void) {
dprintf("haptic_config eprom\n");
dprintf("haptic_config eeprom\n");
dprintf("haptic_config.enable = %d\n", haptic_config.enable);
dprintf("haptic_config.mode = %d\n", haptic_config.mode);
}
Expand Down Expand Up @@ -214,6 +212,8 @@ void haptic_set_dwell(uint8_t dwell) {
xprintf("haptic_config.dwell = %u\n", haptic_config.dwell);
}

uint8_t haptic_get_enable(void) { return haptic_config.enable; }

uint8_t haptic_get_mode(void) {
if (!haptic_config.enable) {
return false;
Expand Down Expand Up @@ -254,14 +254,11 @@ void haptic_disable_continuous(void) {
}

void haptic_toggle_continuous(void) {
#ifdef DRV2605L
if (haptic_config.cont) {
haptic_disable_continuous();
} else {
haptic_enable_continuous();
}
eeconfig_update_haptic(haptic_config.raw);
#endif
}

void haptic_cont_increase(void) {
Expand Down Expand Up @@ -291,130 +288,6 @@ void haptic_play(void) {
#endif
}

__attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) {
switch(keycode) {
# ifdef NO_HAPTIC_MOD
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
if (record->tap.count == 0) return false;
break;
case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
if (record->tap.count != TAPPING_TOGGLE) return false;
break;
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
if (record->tap.count == 0) return false;
break;
case KC_LCTRL ... KC_RGUI:
case QK_MOMENTARY ... QK_MOMENTARY_MAX:
# endif
# ifdef NO_HAPTIC_FN
case KC_FN0 ... KC_FN31:
# endif
# ifdef NO_HAPTIC_ALPHA
case KC_A ... KC_Z:
# endif
# ifdef NO_HAPTIC_PUNCTUATION
case KC_ENTER:
case KC_ESCAPE:
case KC_BSPACE:
case KC_SPACE:
case KC_MINUS:
case KC_EQUAL:
case KC_LBRACKET:
case KC_RBRACKET:
case KC_BSLASH:
case KC_NONUS_HASH:
case KC_SCOLON:
case KC_QUOTE:
case KC_GRAVE:
case KC_COMMA:
case KC_SLASH:
case KC_DOT:
case KC_NONUS_BSLASH:
# endif
# ifdef NO_HAPTIC_LOCKKEYS
case KC_CAPSLOCK:
case KC_SCROLLLOCK:
case KC_NUMLOCK:
# endif
# ifdef NO_HAPTIC_NAV
case KC_PSCREEN:
case KC_PAUSE:
case KC_INSERT:
case KC_DELETE:
case KC_PGDOWN:
case KC_PGUP:
case KC_LEFT:
case KC_UP:
case KC_RIGHT:
case KC_DOWN:
case KC_END:
case KC_HOME:
# endif
# ifdef NO_HAPTIC_NUMERIC
case KC_1 ... KC_0:
# endif
return false;
}
return true;
}

bool process_haptic(uint16_t keycode, keyrecord_t *record) {
if (keycode == HPT_ON && record->event.pressed) {
haptic_enable();
}
if (keycode == HPT_OFF && record->event.pressed) {
haptic_disable();
}
if (keycode == HPT_TOG && record->event.pressed) {
haptic_toggle();
}
if (keycode == HPT_RST && record->event.pressed) {
haptic_reset();
}
if (keycode == HPT_FBK && record->event.pressed) {
haptic_feedback_toggle();
}
if (keycode == HPT_BUZ && record->event.pressed) {
haptic_buzz_toggle();
}
if (keycode == HPT_MODI && record->event.pressed) {
haptic_mode_increase();
}
if (keycode == HPT_MODD && record->event.pressed) {
haptic_mode_decrease();
}
if (keycode == HPT_DWLI && record->event.pressed) {
haptic_dwell_increase();
}
if (keycode == HPT_DWLD && record->event.pressed) {
haptic_dwell_decrease();
}
if (keycode == HPT_CONT && record->event.pressed) {
haptic_toggle_continuous();
}
if (keycode == HPT_CONI && record->event.pressed) {
haptic_cont_increase();
}
if (keycode == HPT_COND && record->event.pressed) {
haptic_cont_decrease();
}

if (haptic_config.enable) {
if (record->event.pressed) {
// keypress
if (haptic_config.feedback < 2 && get_haptic_enabled_key(keycode, record)) {
haptic_play();
}
} else {
// keyrelease
if (haptic_config.feedback > 0 && get_haptic_enabled_key(keycode, record)) {
haptic_play();
}
}
}
return true;
}

void haptic_shutdown(void) {
#ifdef SOLENOID_ENABLE
solenoid_shutdown();
Expand Down
6 changes: 1 addition & 5 deletions drivers/haptic/haptic.h → quantum/haptic.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "quantum.h"
#ifdef DRV2605L
# include "DRV2605L.h"
#endif

#ifndef HAPTIC_FEEDBACK_DEFAULT
# define HAPTIC_FEEDBACK_DEFAULT 0
Expand Down Expand Up @@ -52,7 +48,6 @@ typedef enum HAPTIC_FEEDBACK {
HAPTIC_FEEDBACK_MAX,
} HAPTIC_FEEDBACK;

bool process_haptic(uint16_t keycode, keyrecord_t *record);
void haptic_init(void);
void haptic_task(void);
void eeconfig_debug_haptic(void);
Expand All @@ -69,6 +64,7 @@ void haptic_set_mode(uint8_t mode);
void haptic_set_dwell(uint8_t dwell);
void haptic_set_buzz(uint8_t buzz);
void haptic_buzz_toggle(void);
uint8_t haptic_get_enable(void);
uint8_t haptic_get_mode(void);
uint8_t haptic_get_feedback(void);
void haptic_dwell_increase(void);
Expand Down
147 changes: 147 additions & 0 deletions quantum/process_keycode/process_haptic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/* Copyright 2021 QMK
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "haptic.h"
#include "process_haptic.h"
#include "quantum_keycodes.h"

__attribute__((weak)) bool get_haptic_enabled_key(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
#ifdef NO_HAPTIC_MOD
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
if (record->tap.count == 0) return false;
break;
case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
if (record->tap.count != TAPPING_TOGGLE) return false;
break;
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
if (record->tap.count == 0) return false;
break;
case KC_LCTRL ... KC_RGUI:
case QK_MOMENTARY ... QK_MOMENTARY_MAX:
#endif
#ifdef NO_HAPTIC_FN
case KC_FN0 ... KC_FN31:
#endif
#ifdef NO_HAPTIC_ALPHA
case KC_A ... KC_Z:
#endif
#ifdef NO_HAPTIC_PUNCTUATION
case KC_ENTER:
case KC_ESCAPE:
case KC_BSPACE:
case KC_SPACE:
case KC_MINUS:
case KC_EQUAL:
case KC_LBRACKET:
case KC_RBRACKET:
case KC_BSLASH:
case KC_NONUS_HASH:
case KC_SCOLON:
case KC_QUOTE:
case KC_GRAVE:
case KC_COMMA:
case KC_SLASH:
case KC_DOT:
case KC_NONUS_BSLASH:
#endif
#ifdef NO_HAPTIC_LOCKKEYS
case KC_CAPSLOCK:
case KC_SCROLLLOCK:
case KC_NUMLOCK:
#endif
#ifdef NO_HAPTIC_NAV
case KC_PSCREEN:
case KC_PAUSE:
case KC_INSERT:
case KC_DELETE:
case KC_PGDOWN:
case KC_PGUP:
case KC_LEFT:
case KC_UP:
case KC_RIGHT:
case KC_DOWN:
case KC_END:
case KC_HOME:
#endif
#ifdef NO_HAPTIC_NUMERIC
case KC_1 ... KC_0:
#endif
return false;
}
return true;
}

bool process_haptic(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
switch (keycode) {
case HPT_ON:
haptic_enable();
break;
case HPT_OFF:
haptic_disable();
break;
case HPT_TOG:
haptic_toggle();
break;
case HPT_RST:
haptic_reset();
break;
case HPT_FBK:
haptic_feedback_toggle();
break;
case HPT_BUZ:
haptic_buzz_toggle();
break;
case HPT_MODI:
haptic_mode_increase();
break;
case HPT_MODD:
haptic_mode_decrease();
break;
case HPT_DWLI:
haptic_dwell_increase();
break;
case HPT_DWLD:
haptic_dwell_decrease();
break;
case HPT_CONT:
haptic_toggle_continuous();
break;
case HPT_CONI:
haptic_cont_increase();
break;
case HPT_COND:
haptic_cont_decrease();
break;
}
}

if (haptic_get_enable()) {
if (record->event.pressed) {
// keypress
if (haptic_get_feedback() < 2 && get_haptic_enabled_key(keycode, record)) {
haptic_play();
}
} else {
// keyrelease
if (haptic_get_feedback() > 0 && get_haptic_enabled_key(keycode, record)) {
haptic_play();
}
}
}

return true;
}
21 changes: 21 additions & 0 deletions quantum/process_keycode/process_haptic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright 2021 QMK
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#include <stdbool.h>
#include "action.h"

bool process_haptic(uint16_t keycode, keyrecord_t *record);
Loading