aboutsummaryrefslogtreecommitdiff
path: root/users/mtdjr/solenoid.h
diff options
context:
space:
mode:
authormtdjr <mtdjr@users.noreply.github.com>2018-05-31 11:30:05 -0400
committerDrashna Jaelre <drashna@live.com>2018-05-31 08:30:05 -0700
commitee9a7aba396160929604aca54a23ad5534d59940 (patch)
treef4fbbde03ed548a68fd56bec5c6baf8cf217f180 /users/mtdjr/solenoid.h
parent21ad968ac14b177a7c97d34106c4d6201912627f (diff)
downloadqmk_firmware-ee9a7aba396160929604aca54a23ad5534d59940.tar.gz
qmk_firmware-ee9a7aba396160929604aca54a23ad5534d59940.zip
add not-so-minidox handwire keyboard (#3061)
* add not-so-minidox handwire keyboard * corrected keymap * multiple adjustments to not_so_minidox keyboard * remove I2C master left define * update default layer set function * move solenoid code into userspace * minor adjustments to config.h * update keymaps to utilize userspace * move features and config to userspace, correct build issue * correct solenoid pin * adjust defaults for solenoid pin and enable * default solenoid to on for not_so_minidox * disable RGBLIGHT_SLEEP for xd75 * tweaking solenoid enable/disable in userspace and keymaps
Diffstat (limited to 'users/mtdjr/solenoid.h')
-rw-r--r--users/mtdjr/solenoid.h103
1 files changed, 103 insertions, 0 deletions
diff --git a/users/mtdjr/solenoid.h b/users/mtdjr/solenoid.h
new file mode 100644
index 000000000..38066f4c3
--- /dev/null
+++ b/users/mtdjr/solenoid.h
@@ -0,0 +1,103 @@
1#ifndef SOLENOID_H
2#define SOLENOID_H
3
4#include <timer.h>
5#include "pincontrol.h"
6
7#define SOLENOID_DEFAULT_DWELL 12
8#define SOLENOID_MAX_DWELL 100
9#define SOLENOID_MIN_DWELL 4
10#ifndef SOLENOID_ACTIVE
11 #define SOLENOID_ACTIVE false
12#endif
13//#define SOLENOID_PIN F6
14
15bool solenoid_enabled = SOLENOID_ACTIVE;
16bool solenoid_on = false;
17bool solenoid_buzz = false;
18bool solenoid_buzzing = false;
19uint16_t solenoid_start = 0;
20uint8_t solenoid_dwell = SOLENOID_DEFAULT_DWELL;
21
22
23void solenoid_buzz_on(void) {
24 solenoid_buzz = true;
25}
26
27void solenoid_buzz_off(void) {
28 solenoid_buzz = false;
29}
30
31void solenoid_dwell_minus(void) {
32 if (solenoid_dwell > 0) solenoid_dwell--;
33}
34
35void solenoid_dwell_plus(void) {
36 if (solenoid_dwell < SOLENOID_MAX_DWELL) solenoid_dwell++;
37}
38
39void solenoid_toggle(void) {
40 solenoid_enabled = !solenoid_enabled;
41}
42
43void solenoid_stop(void) {
44 digitalWrite(SOLENOID_PIN, PinLevelLow);
45 solenoid_on = false;
46 solenoid_buzzing = false;
47}
48
49void solenoid_fire(void) {
50 if (!solenoid_enabled) return;
51
52 if (!solenoid_buzz && solenoid_on) return;
53 if (solenoid_buzz && solenoid_buzzing) return;
54
55 solenoid_on = true;
56 solenoid_buzzing = true;
57 solenoid_start = timer_read();
58 digitalWrite(SOLENOID_PIN, PinLevelHigh);
59}
60
61void solenoid_check(void) {
62 uint16_t elapsed = 0;
63
64 if (!solenoid_on) return;
65
66 elapsed = timer_elapsed(solenoid_start);
67
68 //Check if it's time to finish this solenoid click cycle
69 if (elapsed > solenoid_dwell) {
70 solenoid_stop();
71 return;
72 }
73
74 //Check whether to buzz the solenoid on and off
75 if (solenoid_buzz) {
76 if (elapsed / SOLENOID_MIN_DWELL % 2 == 0){
77 if (!solenoid_buzzing) {
78 solenoid_buzzing = true;
79 digitalWrite(SOLENOID_PIN, PinLevelHigh);
80 }
81 }
82 else {
83 if (solenoid_buzzing) {
84 solenoid_buzzing = false;
85 digitalWrite(SOLENOID_PIN, PinLevelLow);
86 }
87 }
88 }
89}
90
91void solenoid_setup(void) {
92 pinMode(SOLENOID_PIN, PinDirectionOutput);
93}
94
95void matrix_init_user(void) {
96 solenoid_setup();
97}
98
99void matrix_scan_user(void) {
100 solenoid_check();
101}
102
103#endif