aboutsummaryrefslogtreecommitdiff
path: root/drivers/haptic/solenoid.c
diff options
context:
space:
mode:
authorskullY <skullydazed@gmail.com>2019-08-30 11:19:03 -0700
committerskullydazed <skullydazed@users.noreply.github.com>2019-08-30 15:01:52 -0700
commitb624f32f944acdc59dcb130674c09090c5c404cb (patch)
treebc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /drivers/haptic/solenoid.c
parent61af76a10d00aba185b8338604171de490a13e3b (diff)
downloadqmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz
qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip
clang-format changes
Diffstat (limited to 'drivers/haptic/solenoid.c')
-rw-r--r--drivers/haptic/solenoid.c100
1 files changed, 43 insertions, 57 deletions
diff --git a/drivers/haptic/solenoid.c b/drivers/haptic/solenoid.c
index 2d39dbc17..d645c379a 100644
--- a/drivers/haptic/solenoid.c
+++ b/drivers/haptic/solenoid.c
@@ -19,91 +19,77 @@
19#include "solenoid.h" 19#include "solenoid.h"
20#include "haptic.h" 20#include "haptic.h"
21 21
22bool solenoid_on = false; 22bool solenoid_on = false;
23bool solenoid_buzzing = false; 23bool solenoid_buzzing = false;
24uint16_t solenoid_start = 0; 24uint16_t solenoid_start = 0;
25uint8_t solenoid_dwell = SOLENOID_DEFAULT_DWELL; 25uint8_t solenoid_dwell = SOLENOID_DEFAULT_DWELL;
26 26
27extern haptic_config_t haptic_config; 27extern haptic_config_t haptic_config;
28 28
29void solenoid_buzz_on(void) { haptic_set_buzz(1); }
29 30
30void solenoid_buzz_on(void) { 31void solenoid_buzz_off(void) { haptic_set_buzz(0); }
31 haptic_set_buzz(1);
32}
33
34void solenoid_buzz_off(void) {
35 haptic_set_buzz(0);
36}
37
38void solenoid_set_buzz(int buzz) {
39 haptic_set_buzz(buzz);
40}
41 32
33void solenoid_set_buzz(int buzz) { haptic_set_buzz(buzz); }
42 34
43void solenoid_dwell_minus(uint8_t solenoid_dwell) { 35void solenoid_dwell_minus(uint8_t solenoid_dwell) {
44 if (solenoid_dwell > 0) solenoid_dwell--; 36 if (solenoid_dwell > 0) solenoid_dwell--;
45} 37}
46 38
47void solenoid_dwell_plus(uint8_t solenoid_dwell) { 39void solenoid_dwell_plus(uint8_t solenoid_dwell) {
48 if (solenoid_dwell < SOLENOID_MAX_DWELL) solenoid_dwell++; 40 if (solenoid_dwell < SOLENOID_MAX_DWELL) solenoid_dwell++;
49} 41}
50 42
51void solenoid_set_dwell(uint8_t dwell) { 43void solenoid_set_dwell(uint8_t dwell) { solenoid_dwell = dwell; }
52 solenoid_dwell = dwell;
53}
54 44
55void solenoid_stop(void) { 45void solenoid_stop(void) {
56 writePinLow(SOLENOID_PIN); 46 writePinLow(SOLENOID_PIN);
57 solenoid_on = false; 47 solenoid_on = false;
58 solenoid_buzzing = false; 48 solenoid_buzzing = false;
59} 49}
60 50
61void solenoid_fire(void) { 51void solenoid_fire(void) {
62 if (!haptic_config.buzz && solenoid_on) return; 52 if (!haptic_config.buzz && solenoid_on) return;
63 if (haptic_config.buzz && solenoid_buzzing) return; 53 if (haptic_config.buzz && solenoid_buzzing) return;
64 54
65 solenoid_on = true; 55 solenoid_on = true;
66 solenoid_buzzing = true; 56 solenoid_buzzing = true;
67 solenoid_start = timer_read(); 57 solenoid_start = timer_read();
68 writePinHigh(SOLENOID_PIN); 58 writePinHigh(SOLENOID_PIN);
69} 59}
70 60
71void solenoid_check(void) { 61void solenoid_check(void) {
72 uint16_t elapsed = 0; 62 uint16_t elapsed = 0;
73
74 if (!solenoid_on) return;
75 63
76 elapsed = timer_elapsed(solenoid_start); 64 if (!solenoid_on) return;
77 65
78 //Check if it's time to finish this solenoid click cycle 66 elapsed = timer_elapsed(solenoid_start);
79 if (elapsed > solenoid_dwell) {
80 solenoid_stop();
81 return;
82 }
83 67
84 //Check whether to buzz the solenoid on and off 68 // Check if it's time to finish this solenoid click cycle
85 if (haptic_config.buzz) { 69 if (elapsed > solenoid_dwell) {
86 if (elapsed / SOLENOID_MIN_DWELL % 2 == 0){ 70 solenoid_stop();
87 if (!solenoid_buzzing) { 71 return;
88 solenoid_buzzing = true;
89 writePinHigh(SOLENOID_PIN);
90 }
91 } 72 }
92 else { 73
93 if (solenoid_buzzing) { 74 // Check whether to buzz the solenoid on and off
94 solenoid_buzzing = false; 75 if (haptic_config.buzz) {
95 writePinLow(SOLENOID_PIN); 76 if (elapsed / SOLENOID_MIN_DWELL % 2 == 0) {
96 } 77 if (!solenoid_buzzing) {
78 solenoid_buzzing = true;
79 writePinHigh(SOLENOID_PIN);
80 }
81 } else {
82 if (solenoid_buzzing) {
83 solenoid_buzzing = false;
84 writePinLow(SOLENOID_PIN);
85 }
86 }
97 } 87 }
98 }
99} 88}
100 89
101void solenoid_setup(void) { 90void solenoid_setup(void) {
102 setPinOutput(SOLENOID_PIN); 91 setPinOutput(SOLENOID_PIN);
103 solenoid_fire(); 92 solenoid_fire();
104} 93}
105 94
106void solenoid_shutdown(void) { 95void solenoid_shutdown(void) { writePinLow(SOLENOID_PIN); }
107 writePinLow(SOLENOID_PIN);
108
109}