aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common_features.mk4
-rw-r--r--docs/feature_pointing_device.md47
-rw-r--r--docs/features.md2
-rw-r--r--quantum/pointing_device.c62
-rw-r--r--quantum/pointing_device.h31
-rw-r--r--tmk_core/common/keyboard.c10
6 files changed, 155 insertions, 1 deletions
diff --git a/common_features.mk b/common_features.mk
index bae23bb87..69fdac87d 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -69,6 +69,10 @@ ifeq ($(strip $(FAUXCLICKY_ENABLE)), yes)
69 SRC += $(QUANTUM_DIR)/fauxclicky.c 69 SRC += $(QUANTUM_DIR)/fauxclicky.c
70endif 70endif
71 71
72ifeq ($(strip $(POINTING_DEVICE_ENABLE)), yes)
73 SRC += $(QUANTUM_DIR)/pointing_device.c
74endif
75
72ifeq ($(strip $(UCIS_ENABLE)), yes) 76ifeq ($(strip $(UCIS_ENABLE)), yes)
73 OPT_DEFS += -DUCIS_ENABLE 77 OPT_DEFS += -DUCIS_ENABLE
74 UNICODE_COMMON = yes 78 UNICODE_COMMON = yes
diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md
new file mode 100644
index 000000000..1ba8f7759
--- /dev/null
+++ b/docs/feature_pointing_device.md
@@ -0,0 +1,47 @@
1## Pointing Device
2
3Pointing Device is a generic name for a feature intended to be generic: moving the system pointer arround. There are certainly other options for it - like mousekeys - but this aims to be easily modifiable and lightweight. You can implement custom keys to control functionality, or you can gather information from other peripherals and insert it directly here - let QMK handle the processing for you.
4
5To enable Pointing Device, uncomment the following line in your rules.mk:
6
7```
8POINTING_DEVICE_ENABLE = yes
9```
10
11To manipulate the mouse report, you can use the following functions:
12
13* `pointing_device_get_report()` - Returns the current report_mouse_t that represents the information sent to the host computer
14* `pointing_device_set_report(report_mouse_t newMouseReport)` - Overrides and saves the report_mouse_t to be sent to the host computer
15
16Keep in mind that a report_mouse_t (here "mouseReport") has the following properties:
17
18* `mouseReport.x` - this is a signed int from -127 to 127 (not 128, this is defined in USB HID spec) representing movement (+ to the right, - to the left) on the x axis.
19* `mouseReport.y` - this is a signed int from -127 to 127 (not 128, this is defined in USB HID spec) representing movement (+ upward, - downward) on the y axis.
20* `mouseReport.v` - this is a signed int from -127 to 127 (not 128, this is defined in USB HID spec) representing vertical scrolling (+ upward, - downward).
21* `mouseReport.h` - this is a signed int from -127 to 127 (not 128, this is defined in USB HID spec) representing horizontal scrolling (+ right, - left).
22* `mouseReport.buttons` - this is a uint8_t in which the last 5 bits are used. These bits represent the mouse button state - bit 3 is mouse button 5, and bit 7 is mouse button 1.
23
24When the mouse report is sent, the x, y, v, and h values are set to 0 (this is done in "pointing_device_send()", which can be overridden to avoid this behavior). This way, button states persist, but movement will only occur once. For further customization, both `pointing_device_init` and `pointing_device_task` can be overridden.
25
26In the following example, a custom key is used to click the mouse and scroll 127 units vertically and horizontally, then undo all of that when released - because that's a totally useful function. Listen, this is an example:
27
28```
29case MS_SPECIAL:
30 report_mouse_t currentReport = pointing_device_get_report();
31 if (record->event.pressed)
32 {
33 currentReport.v = 127;
34 currentReport.h = 127;
35 currentReport.buttons |= MOUSE_BTN1; //this is defined in report.h
36 }
37 else
38 {
39 currentReport.v = -127;
40 currentReport.h = -127;
41 currentReport.buttons &= ~MOUSE_BTN1;
42 }
43 pointing_device_set_report(currentReport);
44 break;
45```
46
47Recall that the mouse report is set to zero (except the buttons) whenever it is sent, so the scrolling would only occur once in each case. \ No newline at end of file
diff --git a/docs/features.md b/docs/features.md
index c5965f4c0..2ef436156 100644
--- a/docs/features.md
+++ b/docs/features.md
@@ -102,4 +102,4 @@ case MACRO_RAISED:
102 update_tri_layer(LAYER_LOWER, LAYER_RAISED, LAYER_ADJUST); 102 update_tri_layer(LAYER_LOWER, LAYER_RAISED, LAYER_ADJUST);
103 } 103 }
104 break; 104 break;
105``` 105``` \ No newline at end of file
diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c
new file mode 100644
index 000000000..0aaab84cd
--- /dev/null
+++ b/quantum/pointing_device.c
@@ -0,0 +1,62 @@
1/*
2Copyright 2017 Joshua Broekhuijsen <snipeye+qmk@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <stdint.h>
19#include "report.h"
20#include "host.h"
21#include "timer.h"
22#include "print.h"
23#include "debug.h"
24#include "pointing_device.h"
25
26static report_mouse_t mouseReport = {};
27
28__attribute__ ((weak))
29void pointing_device_init(void){
30 //initialize device, if that needs to be done.
31}
32
33__attribute__ ((weak))
34void pointing_device_send(void){
35 //If you need to do other things, like debugging, this is the place to do it.
36 host_mouse_send(mouseReport);
37 //send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device
38 mouseReport.x = 0;
39 mouseReport.y = 0;
40 mouseReport.v = 0;
41 mouseReport.h = 0;
42}
43
44__attribute__ ((weak))
45void pointing_device_task(void){
46 //gather info and put it in:
47 //mouseReport.x = 127 max -127 min
48 //mouseReport.y = 127 max -127 min
49 //mouseReport.v = 127 max -127 min (scroll vertical)
50 //mouseReport.h = 127 max -127 min (scroll horizontal)
51 //mouseReport.buttons = 0x1F (decimal 31, binary 00011111) max (bitmask for mouse buttons 1-5, 1 is rightmost, 5 is leftmost) 0x00 min
52 //send the report
53 pointing_device_send();
54}
55
56report_mouse_t pointing_device_get_report(void){
57 return mouseReport;
58}
59
60void pointing_device_set_report(report_mouse_t newMouseReport){
61 mouseReport = newMouseReport;
62} \ No newline at end of file
diff --git a/quantum/pointing_device.h b/quantum/pointing_device.h
new file mode 100644
index 000000000..40d71f741
--- /dev/null
+++ b/quantum/pointing_device.h
@@ -0,0 +1,31 @@
1/*
2Copyright 2017 Joshua Broekhuijsen <snipeye+qmk@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef POINTING_DEVICE_H
19#define POINTING_DEVICE_H
20
21#include <stdint.h>
22#include "host.h"
23#include "report.h"
24
25void pointingdevice_init(void);
26void pointing_device_task(void);
27void pointing_device_send(void);
28report_mouse_t pointing_device_get_report(void);
29void pointing_device_set_report(report_mouse_t newMouseReport);
30
31#endif
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 1b7c8c1a2..fd2cf74f5 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -63,6 +63,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
63#ifdef VISUALIZER_ENABLE 63#ifdef VISUALIZER_ENABLE
64# include "visualizer/visualizer.h" 64# include "visualizer/visualizer.h"
65#endif 65#endif
66#ifdef POINTING_DEVICE_ENABLE
67# include "pointing_device.h"
68#endif
66 69
67#ifdef MATRIX_HAS_GHOST 70#ifdef MATRIX_HAS_GHOST
68extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; 71extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
@@ -153,6 +156,9 @@ void keyboard_init(void) {
153#ifdef FAUXCLICKY_ENABLE 156#ifdef FAUXCLICKY_ENABLE
154 fauxclicky_init(); 157 fauxclicky_init();
155#endif 158#endif
159#ifdef POINTING_DEVICE_ENABLE
160 pointing_device_init();
161#endif
156#if defined(NKRO_ENABLE) && defined(FORCE_NKRO) 162#if defined(NKRO_ENABLE) && defined(FORCE_NKRO)
157 keymap_config.nkro = 1; 163 keymap_config.nkro = 1;
158#endif 164#endif
@@ -239,6 +245,10 @@ MATRIX_LOOP_END:
239 visualizer_update(default_layer_state, layer_state, visualizer_get_mods(), host_keyboard_leds()); 245 visualizer_update(default_layer_state, layer_state, visualizer_get_mods(), host_keyboard_leds());
240#endif 246#endif
241 247
248#ifdef POINTING_DEVICE_ENABLE
249 pointing_device_task();
250#endif
251
242 // update LED 252 // update LED
243 if (led_status != host_keyboard_leds()) { 253 if (led_status != host_keyboard_leds()) {
244 led_status = host_keyboard_leds(); 254 led_status = host_keyboard_leds();