From f8505aabecb83b55a1cb412573fb4dd869cb9f67 Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sat, 11 Jul 2020 01:44:54 +0300 Subject: [PATCH 01/14] solenoid: remove two functions that do nothing. These functions modify the argument, and so they do nothing. Note: versions of these functions exist in mtdjr's user folder, however to core solenoid support and mtdjr user-specific solenoid support are exclusive (only one can be used at a time). So removing these confusing functions does no harm. --- drivers/haptic/solenoid.c | 8 -------- drivers/haptic/solenoid.h | 2 -- 2 files changed, 10 deletions(-) diff --git a/drivers/haptic/solenoid.c b/drivers/haptic/solenoid.c index d645c379ae97..aa7d316c9525 100644 --- a/drivers/haptic/solenoid.c +++ b/drivers/haptic/solenoid.c @@ -32,14 +32,6 @@ void solenoid_buzz_off(void) { haptic_set_buzz(0); } void solenoid_set_buzz(int buzz) { haptic_set_buzz(buzz); } -void solenoid_dwell_minus(uint8_t solenoid_dwell) { - if (solenoid_dwell > 0) solenoid_dwell--; -} - -void solenoid_dwell_plus(uint8_t solenoid_dwell) { - if (solenoid_dwell < SOLENOID_MAX_DWELL) solenoid_dwell++; -} - void solenoid_set_dwell(uint8_t dwell) { solenoid_dwell = dwell; } void solenoid_stop(void) { diff --git a/drivers/haptic/solenoid.h b/drivers/haptic/solenoid.h index dd6ececa685e..088fb9aed50f 100644 --- a/drivers/haptic/solenoid.h +++ b/drivers/haptic/solenoid.h @@ -37,8 +37,6 @@ void solenoid_buzz_on(void); void solenoid_buzz_off(void); void solenoid_set_buzz(int buzz); -void solenoid_dwell_minus(uint8_t solenoid_dwell); -void solenoid_dwell_plus(uint8_t solenoid_dwell); void solenoid_set_dwell(uint8_t dwell); void solenoid_stop(void); From 9fe10b6d1626a615cf719e4edda646e63c35cf0d Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sat, 11 Jul 2020 02:09:29 +0300 Subject: [PATCH 02/14] solenoid: bugfix: don't allow dwell time to go 1ms below minimum time. The previous code allowed dwell time to go 1ms below the configured minimum. This change corrects it. --- drivers/haptic/haptic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c index 2ce279b753ae..eaed0feea5e8 100644 --- a/drivers/haptic/haptic.c +++ b/drivers/haptic/haptic.c @@ -131,7 +131,7 @@ void haptic_dwell_increase(void) { void haptic_dwell_decrease(void) { uint8_t dwell = haptic_config.dwell - 1; #ifdef SOLENOID_ENABLE - if (haptic_config.dwell < SOLENOID_MIN_DWELL) { + if (haptic_config.dwell <= SOLENOID_MIN_DWELL) { dwell = SOLENOID_MAX_DWELL; } solenoid_set_dwell(dwell); From 5d4796e8d8f4a1c2758c05b65c006332ba52daf3 Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sat, 11 Jul 2020 02:11:35 +0300 Subject: [PATCH 03/14] solenoid: bugfix: when incrementing above maximum dwell time, jump back to minimum, not to 1 The previous code used to jump back to 1, which might be way under the configured minimum setting. --- drivers/haptic/haptic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c index eaed0feea5e8..c0d3b7c4ccfc 100644 --- a/drivers/haptic/haptic.c +++ b/drivers/haptic/haptic.c @@ -121,7 +121,7 @@ void haptic_dwell_increase(void) { uint8_t dwell = haptic_config.dwell + 1; #ifdef SOLENOID_ENABLE if (haptic_config.dwell >= SOLENOID_MAX_DWELL) { - dwell = 1; + dwell = SOLENOID_MIN_DWELL; } solenoid_set_dwell(dwell); #endif From f106ce5bfaca0c7d3127efb2dfd43b3e9bcb8e77 Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sat, 11 Jul 2020 02:35:15 +0300 Subject: [PATCH 04/14] solenoid: bugfix: on startup actually use the eeprom-stored dwell-time This is because the dwell time is stored in two variables. --- drivers/haptic/haptic.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c index c0d3b7c4ccfc..b5c96c63658e 100644 --- a/drivers/haptic/haptic.c +++ b/drivers/haptic/haptic.c @@ -33,6 +33,9 @@ void haptic_init(void) { eeconfig_init(); } haptic_config.raw = eeconfig_read_haptic(); +#ifdef SOLENOID_ENABLE + solenoid_set_dwell(haptic_config.dwell); +#endif if (haptic_config.mode < 1) { haptic_config.mode = 1; } From 6055e03cbe89a37822d025d295e620cae6e01907 Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sat, 11 Jul 2020 02:36:25 +0300 Subject: [PATCH 05/14] solenoid: bugfix: on haptic_reset, actually use the newly set default dwell time. This is needed because dwell time is configured in two variables. --- drivers/haptic/haptic.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c index b5c96c63658e..bbef111957b1 100644 --- a/drivers/haptic/haptic.c +++ b/drivers/haptic/haptic.c @@ -153,6 +153,7 @@ void haptic_reset(void) { #ifdef SOLENOID_ENABLE uint8_t dwell = SOLENOID_DEFAULT_DWELL; haptic_config.dwell = dwell; + solenoid_set_dwell(dwell); #endif eeconfig_update_haptic(haptic_config.raw); xprintf("haptic_config.feedback = %u\n", haptic_config.feedback); From afeef8857d3d803e48d2ce5f99424a9c030634c0 Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sat, 11 Jul 2020 02:41:26 +0300 Subject: [PATCH 06/14] solenoid: on HPT_RST set buzz to a default value --- docs/feature_haptic_feedback.md | 1 + drivers/haptic/haptic.c | 1 + drivers/haptic/solenoid.h | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/docs/feature_haptic_feedback.md b/docs/feature_haptic_feedback.md index ff7337a51a44..83ed729e2d92 100644 --- a/docs/feature_haptic_feedback.md +++ b/docs/feature_haptic_feedback.md @@ -48,6 +48,7 @@ First you will need a build a circuit to drive the solenoid through a mosfet as |`SOLENOID_DEFAULT_DWELL` | `12` ms |Configures the default dwell time for the solenoid. | |`SOLENOID_MIN_DWELL` | `4` ms |Sets the lower limit for the dwell. | |`SOLENOID_MAX_DWELL` | `100` ms |Sets the upper limit for the dwell. | +|`SOLENOID_DEFAULT_BUZZ` | 0 (disabled) |On HPT_RST buzz is set "on" if this is "1" | ?> Dwell time is how long the "plunger" stays activated. The dwell time changes how the solenoid sounds. diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c index bbef111957b1..e43f85544dfc 100644 --- a/drivers/haptic/haptic.c +++ b/drivers/haptic/haptic.c @@ -153,6 +153,7 @@ void haptic_reset(void) { #ifdef SOLENOID_ENABLE uint8_t dwell = SOLENOID_DEFAULT_DWELL; haptic_config.dwell = dwell; + haptic_config.buzz = SOLENOID_DEFAULT_BUZZ; solenoid_set_dwell(dwell); #endif eeconfig_update_haptic(haptic_config.raw); diff --git a/drivers/haptic/solenoid.h b/drivers/haptic/solenoid.h index 088fb9aed50f..579b93ddc0d4 100644 --- a/drivers/haptic/solenoid.h +++ b/drivers/haptic/solenoid.h @@ -29,6 +29,10 @@ # define SOLENOID_MIN_DWELL 4 #endif +#ifndef SOLENOID_DEFAULT_BUZZ +# define SOLENOID_DEFAULT_BUZZ 0 +#endif + #ifndef SOLENOID_PIN # error SOLENOID_PIN not defined #endif From 36833b2ab5e0fd6b17078fe849ce26b72ca91f90 Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sat, 11 Jul 2020 03:00:38 +0300 Subject: [PATCH 07/14] solenoid: buzz: reworked to make more configurable. Previous behaviour maintained. --- docs/feature_haptic_feedback.md | 16 +++++++++------- drivers/haptic/solenoid.c | 2 +- drivers/haptic/solenoid.h | 8 ++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/feature_haptic_feedback.md b/docs/feature_haptic_feedback.md index 83ed729e2d92..9e91158b9b52 100644 --- a/docs/feature_haptic_feedback.md +++ b/docs/feature_haptic_feedback.md @@ -42,13 +42,15 @@ First you will need a build a circuit to drive the solenoid through a mosfet as [Wiring diagram provided by Adafruit](https://playground.arduino.cc/uploads/Learning/solenoid_driver.pdf) -| Settings | Default | Description | -|--------------------------|---------------|-------------------------------------------------------| -|`SOLENOID_PIN` | *Not defined* |Configures the pin that the Solenoid is connected to. | -|`SOLENOID_DEFAULT_DWELL` | `12` ms |Configures the default dwell time for the solenoid. | -|`SOLENOID_MIN_DWELL` | `4` ms |Sets the lower limit for the dwell. | -|`SOLENOID_MAX_DWELL` | `100` ms |Sets the upper limit for the dwell. | -|`SOLENOID_DEFAULT_BUZZ` | 0 (disabled) |On HPT_RST buzz is set "on" if this is "1" | +| Settings | Default | Description | +|----------------------------|----------------------|-------------------------------------------------------| +|`SOLENOID_PIN` | *Not defined* |Configures the pin that the Solenoid is connected to. | +|`SOLENOID_DEFAULT_DWELL` | `12` ms |Configures the default dwell time for the solenoid. | +|`SOLENOID_MIN_DWELL` | `4` ms |Sets the lower limit for the dwell. | +|`SOLENOID_MAX_DWELL` | `100` ms |Sets the upper limit for the dwell. | +|`SOLENOID_DEFAULT_BUZZ` | `0` (disabled) |On HPT_RST buzz is set "on" if this is "1" | +|`SOLENOID_BUZZ_ACTUATED` | `SOLENOID_MIN_DWELL` |Actuated-time when the solenoid is in buzz mode | +|`SOLENOID_BUZZ_NONACTUATED` | `SOLENOID_MIN_DWELL` |Non-Actuated-time when the solenoid is in buzz mode | ?> Dwell time is how long the "plunger" stays activated. The dwell time changes how the solenoid sounds. diff --git a/drivers/haptic/solenoid.c b/drivers/haptic/solenoid.c index aa7d316c9525..2975ef893a9f 100644 --- a/drivers/haptic/solenoid.c +++ b/drivers/haptic/solenoid.c @@ -65,7 +65,7 @@ void solenoid_check(void) { // Check whether to buzz the solenoid on and off if (haptic_config.buzz) { - if (elapsed / SOLENOID_MIN_DWELL % 2 == 0) { + if ((elapsed % (SOLENOID_BUZZ_ACTUATED + SOLENOID_BUZZ_NONACTUATED)) < SOLENOID_BUZZ_ACTUATED) { if (!solenoid_buzzing) { solenoid_buzzing = true; writePinHigh(SOLENOID_PIN); diff --git a/drivers/haptic/solenoid.h b/drivers/haptic/solenoid.h index 579b93ddc0d4..a41383bb78ff 100644 --- a/drivers/haptic/solenoid.h +++ b/drivers/haptic/solenoid.h @@ -33,6 +33,14 @@ # define SOLENOID_DEFAULT_BUZZ 0 #endif +#ifndef SOLENOID_BUZZ_ACTUATED +# define SOLENOID_BUZZ_ACTUATED SOLENOID_MIN_DWELL +#endif + +#ifndef SOLENOID_BUZZ_NONACTUATED +# define SOLENOID_BUZZ_NONACTUATED SOLENOID_MIN_DWELL +#endif + #ifndef SOLENOID_PIN # error SOLENOID_PIN not defined #endif From fffefab3ab56b7c2645497c7ab4503f2706c8342 Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sat, 11 Jul 2020 03:13:58 +0300 Subject: [PATCH 08/14] solenoid: documentation: clarify meaning of dwell time --- docs/feature_haptic_feedback.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/feature_haptic_feedback.md b/docs/feature_haptic_feedback.md index 9e91158b9b52..e355d6166b42 100644 --- a/docs/feature_haptic_feedback.md +++ b/docs/feature_haptic_feedback.md @@ -52,7 +52,8 @@ First you will need a build a circuit to drive the solenoid through a mosfet as |`SOLENOID_BUZZ_ACTUATED` | `SOLENOID_MIN_DWELL` |Actuated-time when the solenoid is in buzz mode | |`SOLENOID_BUZZ_NONACTUATED` | `SOLENOID_MIN_DWELL` |Non-Actuated-time when the solenoid is in buzz mode | -?> Dwell time is how long the "plunger" stays activated. The dwell time changes how the solenoid sounds. +* If solenoid buzz is off, then dwell time is how long the "plunger" stays activated. The dwell time changes how the solenoid sounds. +* If solenoid buzz is on, then dwell time sets the length of the buzz, while `SOLENOID_BUZZ_ACTUATED` and `SOLENOID_BUZZ_NONACTUATED` set the (non-)actuation times withing the buzz period. Beware that some pins may be powered during bootloader (ie. A13 on the STM32F303 chip) and will result in the solenoid kept in the on state through the whole flashing process. This may overheat and damage the solenoid. If you find that the pin the solenoid is connected to is triggering the solenoid during bootloader/DFU, select another pin. From 0f87c94e58f49cf6bc6e3c87c0b02ca2a4f9e1f2 Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sat, 11 Jul 2020 03:28:26 +0300 Subject: [PATCH 09/14] solenoid: add feature SOLENOID_DWELL_STEP_SIZE --- docs/feature_haptic_feedback.md | 1 + drivers/haptic/haptic.c | 24 ++++++++++++++++-------- drivers/haptic/solenoid.h | 4 ++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/docs/feature_haptic_feedback.md b/docs/feature_haptic_feedback.md index e355d6166b42..64783e0a9b17 100644 --- a/docs/feature_haptic_feedback.md +++ b/docs/feature_haptic_feedback.md @@ -48,6 +48,7 @@ First you will need a build a circuit to drive the solenoid through a mosfet as |`SOLENOID_DEFAULT_DWELL` | `12` ms |Configures the default dwell time for the solenoid. | |`SOLENOID_MIN_DWELL` | `4` ms |Sets the lower limit for the dwell. | |`SOLENOID_MAX_DWELL` | `100` ms |Sets the upper limit for the dwell. | +|`SOLENOID_DWELL_STEP_SIZE` | `1` ms |The step size to use when `HPT_DWL*` keycodes are sent | |`SOLENOID_DEFAULT_BUZZ` | `0` (disabled) |On HPT_RST buzz is set "on" if this is "1" | |`SOLENOID_BUZZ_ACTUATED` | `SOLENOID_MIN_DWELL` |Actuated-time when the solenoid is in buzz mode | |`SOLENOID_BUZZ_NONACTUATED` | `SOLENOID_MIN_DWELL` |Non-Actuated-time when the solenoid is in buzz mode | diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c index e43f85544dfc..91d1c5f96169 100644 --- a/drivers/haptic/haptic.c +++ b/drivers/haptic/haptic.c @@ -121,25 +121,33 @@ void haptic_mode_decrease(void) { } void haptic_dwell_increase(void) { - uint8_t dwell = haptic_config.dwell + 1; + int16_t next_dwell = ((int16_t)haptic_config.dwell) + SOLENOID_DWELL_STEP_SIZE; #ifdef SOLENOID_ENABLE if (haptic_config.dwell >= SOLENOID_MAX_DWELL) { - dwell = SOLENOID_MIN_DWELL; + // if it's already at max, we wrap back to min + next_dwell = SOLENOID_MIN_DWELL; + } else if (next_dwell > SOLENOID_MAX_DWELL) { + // if we overshoot the max, then cap at max + next_dwell = SOLENOID_MAX_DWELL; } - solenoid_set_dwell(dwell); + solenoid_set_dwell(next_dwell); #endif - haptic_set_dwell(dwell); + haptic_set_dwell(next_dwell); } void haptic_dwell_decrease(void) { - uint8_t dwell = haptic_config.dwell - 1; + int16_t next_dwell = ((int16_t)haptic_config.dwell) - SOLENOID_DWELL_STEP_SIZE; #ifdef SOLENOID_ENABLE if (haptic_config.dwell <= SOLENOID_MIN_DWELL) { - dwell = SOLENOID_MAX_DWELL; + // if it's already at min, we wrap to max + next_dwell = SOLENOID_MAX_DWELL; + } else if (next_dwell < SOLENOID_MIN_DWELL) { + // if we go below min, then we cap to min + next_dwell = SOLENOID_MIN_DWELL; } - solenoid_set_dwell(dwell); + solenoid_set_dwell(next_dwell); #endif - haptic_set_dwell(dwell); + haptic_set_dwell(next_dwell); } void haptic_reset(void) { diff --git a/drivers/haptic/solenoid.h b/drivers/haptic/solenoid.h index a41383bb78ff..f2a3bc4c3094 100644 --- a/drivers/haptic/solenoid.h +++ b/drivers/haptic/solenoid.h @@ -29,6 +29,10 @@ # define SOLENOID_MIN_DWELL 4 #endif +#ifndef SOLENOID_DWELL_STEP_SIZE +# define SOLENOID_DWELL_STEP_SIZE 1 +#endif + #ifndef SOLENOID_DEFAULT_BUZZ # define SOLENOID_DEFAULT_BUZZ 0 #endif From 84354e8707ed69dac6713bc2813c0cb653dc24eb Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sat, 11 Jul 2020 03:16:00 +0300 Subject: [PATCH 10/14] solenoid: documentation: added note about the precision of the solenoid time settings --- docs/feature_haptic_feedback.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/feature_haptic_feedback.md b/docs/feature_haptic_feedback.md index 64783e0a9b17..64b66310b6ca 100644 --- a/docs/feature_haptic_feedback.md +++ b/docs/feature_haptic_feedback.md @@ -55,6 +55,8 @@ First you will need a build a circuit to drive the solenoid through a mosfet as * If solenoid buzz is off, then dwell time is how long the "plunger" stays activated. The dwell time changes how the solenoid sounds. * If solenoid buzz is on, then dwell time sets the length of the buzz, while `SOLENOID_BUZZ_ACTUATED` and `SOLENOID_BUZZ_NONACTUATED` set the (non-)actuation times withing the buzz period. +* With the current implementation, for any of the above time settings, the precision of these settings may be affected by how fast the keyboard is able to scan the matrix. + Therefore, if the keyboards scanning routine is slow, it may be preferable to set `SOLENOID_DWELL_STEP_SIZE` to a value slightly smaller than the time it takes to scan the keyboard. Beware that some pins may be powered during bootloader (ie. A13 on the STM32F303 chip) and will result in the solenoid kept in the on state through the whole flashing process. This may overheat and damage the solenoid. If you find that the pin the solenoid is connected to is triggering the solenoid during bootloader/DFU, select another pin. From e8d5b11b09caa82ae2297847ff11a95f4a059f2a Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sat, 11 Jul 2020 04:55:05 +0300 Subject: [PATCH 11/14] haptic: Correctly call haptic_reset when eeprom is corrupt. --- drivers/haptic/haptic.c | 7 ------- tmk_core/common/eeconfig.c | 8 ++++++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c index 91d1c5f96169..7d5972d013c0 100644 --- a/drivers/haptic/haptic.c +++ b/drivers/haptic/haptic.c @@ -36,13 +36,6 @@ void haptic_init(void) { #ifdef SOLENOID_ENABLE solenoid_set_dwell(haptic_config.dwell); #endif - if (haptic_config.mode < 1) { - haptic_config.mode = 1; - } - if (!haptic_config.mode) { - dprintf("No haptic config found in eeprom, setting default configs\n"); - haptic_reset(); - } #ifdef SOLENOID_ENABLE solenoid_setup(); dprintf("Solenoid driver initialized\n"); diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c index fe56c57d1177..0b73ed28661c 100644 --- a/tmk_core/common/eeconfig.c +++ b/tmk_core/common/eeconfig.c @@ -13,6 +13,10 @@ # include "eeprom_driver.h" #endif +#if defined(HAPTIC_ENABLE) +# include "haptic.h" +#endif + /** \brief eeconfig enable * * FIXME: needs doc @@ -65,6 +69,10 @@ void eeconfig_init_quantum(void) { eeprom_update_byte(EECONFIG_HANDEDNESS, 0); #endif +#if defined(HAPTIC_ENABLE) + haptic_reset(); +#endif + eeconfig_init_kb(); } From 56b2a32171e48418b113607320b4619b0e8ab99e Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sat, 11 Jul 2020 05:12:37 +0300 Subject: [PATCH 12/14] haptic: improve what happens if haptic is enabled without erasing eeprom --- drivers/haptic/haptic.c | 11 +++++++++++ tmk_core/common/eeconfig.c | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c index 7d5972d013c0..6a09c4fca811 100644 --- a/drivers/haptic/haptic.c +++ b/drivers/haptic/haptic.c @@ -36,6 +36,17 @@ void haptic_init(void) { #ifdef SOLENOID_ENABLE solenoid_set_dwell(haptic_config.dwell); #endif + if ((haptic_config.raw == 0) +#ifdef SOLENOID_ENABLE + || (haptic_config.dwell == 0) +#endif + ) { + // this will be called, if the eeprom is not corrupt, + // but the previous firmware didn't have haptic enabled, + // or the previous firmware didn't have solenoid enabled, + // and the current one has solenoid enabled. + haptic_reset(); + } #ifdef SOLENOID_ENABLE solenoid_setup(); dprintf("Solenoid driver initialized\n"); diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c index 0b73ed28661c..e15897552f11 100644 --- a/tmk_core/common/eeconfig.c +++ b/tmk_core/common/eeconfig.c @@ -71,6 +71,11 @@ void eeconfig_init_quantum(void) { #if defined(HAPTIC_ENABLE) haptic_reset(); +#else + // this is used in case haptic is disabled, but we still want sane defaults + // in the haptic configuration eeprom. All zero will trigger a haptic_reset + // when a haptic-enabled firmware is loaded onto the keyboard. + eeprom_update_dword(EECONFIG_HAPTIC, 0); #endif eeconfig_init_kb(); From 8043609d999a270996d03f0f523fb127c3c202d7 Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sat, 11 Jul 2020 06:04:43 +0300 Subject: [PATCH 13/14] haptic: improve what happens if solenoid is enabled without erasing eeprom --- drivers/haptic/haptic.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c index 6a09c4fca811..6cd699ba79f3 100644 --- a/drivers/haptic/haptic.c +++ b/drivers/haptic/haptic.c @@ -167,6 +167,10 @@ void haptic_reset(void) { haptic_config.dwell = dwell; haptic_config.buzz = SOLENOID_DEFAULT_BUZZ; solenoid_set_dwell(dwell); +#else + // This is to trigger haptic_reset again, if solenoid is enabled in the future. + haptic_config.dwell = 0; + haptic_config.buzz = 0; #endif eeconfig_update_haptic(haptic_config.raw); xprintf("haptic_config.feedback = %u\n", haptic_config.feedback); From d5c748e2aa4ab99ee30d175c6228560a770611d6 Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Fri, 17 Jul 2020 21:19:04 +0300 Subject: [PATCH 14/14] drivers/haptic: fix compilation issue, when haptic is enabled, but solenoid isn't --- drivers/haptic/haptic.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/haptic/haptic.c b/drivers/haptic/haptic.c index 6cd699ba79f3..e4cf5850154c 100644 --- a/drivers/haptic/haptic.c +++ b/drivers/haptic/haptic.c @@ -125,8 +125,8 @@ void haptic_mode_decrease(void) { } void haptic_dwell_increase(void) { - int16_t next_dwell = ((int16_t)haptic_config.dwell) + SOLENOID_DWELL_STEP_SIZE; #ifdef SOLENOID_ENABLE + int16_t next_dwell = ((int16_t)haptic_config.dwell) + SOLENOID_DWELL_STEP_SIZE; if (haptic_config.dwell >= SOLENOID_MAX_DWELL) { // if it's already at max, we wrap back to min next_dwell = SOLENOID_MIN_DWELL; @@ -135,13 +135,15 @@ void haptic_dwell_increase(void) { next_dwell = SOLENOID_MAX_DWELL; } solenoid_set_dwell(next_dwell); +#else + int16_t next_dwell = ((int16_t)haptic_config.dwell) + 1; #endif haptic_set_dwell(next_dwell); } void haptic_dwell_decrease(void) { - int16_t next_dwell = ((int16_t)haptic_config.dwell) - SOLENOID_DWELL_STEP_SIZE; #ifdef SOLENOID_ENABLE + int16_t next_dwell = ((int16_t)haptic_config.dwell) - SOLENOID_DWELL_STEP_SIZE; if (haptic_config.dwell <= SOLENOID_MIN_DWELL) { // if it's already at min, we wrap to max next_dwell = SOLENOID_MAX_DWELL; @@ -150,6 +152,8 @@ void haptic_dwell_decrease(void) { next_dwell = SOLENOID_MIN_DWELL; } solenoid_set_dwell(next_dwell); +#else + int16_t next_dwell = ((int16_t)haptic_config.dwell) - 1; #endif haptic_set_dwell(next_dwell); }