ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
device_mouse.c
Go to the documentation of this file.
1 #include "command.h"
2 #include "device.h"
3 #include "devnode.h"
4 #include "firmware.h"
5 #include "input.h"
6 #include "profile.h"
7 #include "usb.h"
8 
9 int setactive_mouse(usbdevice* kb, int active){
10  if(NEEDS_FW_UPDATE(kb))
11  return 0;
12  const int keycount = 20;
13  uchar msg[2][MSG_SIZE] = {
14  { 0x07, 0x04, 0 }, // Disables or enables HW control for DPI and Sniper button
15  { 0x07, 0x40, keycount, 0 }, // Select button input (simlilar to the packet sent to keyboards, but lacks a commit packet)
16  };
17  if(active)
18  // Put the mouse into SW mode
19  msg[0][2] = 2;
20  else
21  // Restore HW mode
22  msg[0][2] = 1;
23  pthread_mutex_lock(imutex(kb));
24  kb->active = !!active;
25  kb->profile->lastlight.forceupdate = 1;
26  // Clear input
27  memset(&kb->input.keys, 0, sizeof(kb->input.keys));
28  inputupdate(kb);
29  pthread_mutex_unlock(imutex(kb));
30  if(!usbsend(kb, msg[0], 1))
31  return -1;
32  if(active){
33  // Set up key input
34  if(!usbsend(kb, msg[1], 1))
35  return -1;
36  for(int i = 0; i < keycount; i++){
37  msg[1][i * 2 + 4] = i + 1;
38  msg[1][i * 2 + 5] = (i < 6 ? IN_HID : IN_CORSAIR);
39  }
40  }
41  return 0;
42 }
43 
44 int cmd_active_mouse(usbdevice* kb, usbmode* dummy1, int dummy2, int dummy3, const char* dummy4){
45  (void)dummy1;
46  (void)dummy2;
47  (void)dummy3;
48  (void)dummy4;
49 
50  return setactive_mouse(kb, 1);
51 }
52 
53 int cmd_idle_mouse(usbdevice* kb, usbmode* dummy1, int dummy2, int dummy3, const char* dummy4){
54  (void)dummy1;
55  (void)dummy2;
56  (void)dummy3;
57  (void)dummy4;
58 
59  return setactive_mouse(kb, 0);
60 }
61 
62 int cmd_pollrate(usbdevice* kb, usbmode* dummy1, int dummy2, int rate, const char* dummy3){
63  (void)dummy1;
64  (void)dummy2;
65  (void)dummy3;
66 
67  uchar msg[MSG_SIZE] = {
68  0x07, 0x0a, 0, 0, (uchar)rate
69  };
70  if(!usbsend(kb, msg, 1))
71  return -1;
72  // Device should disconnect+reconnect, but update the poll rate field in case it doesn't
73  kb->pollrate = rate;
74  return 0;
75 }
#define MSG_SIZE
Definition: structures.h:176
lighting lastlight
Definition: structures.h:107
usbprofile * profile
Definition: structures.h:221
int cmd_active_mouse(usbdevice *kb, usbmode *dummy1, int dummy2, int dummy3, const char *dummy4)
Definition: device_mouse.c:44
usbinput input
Definition: structures.h:245
char active
Definition: structures.h:231
void inputupdate(usbdevice *kb)
Definition: input.c:241
unsigned char uchar
Definition: includes.h:24
uchar forceupdate
Definition: structures.h:77
#define IN_HID
Definition: device.h:64
int cmd_idle_mouse(usbdevice *kb, usbmode *dummy1, int dummy2, int dummy3, const char *dummy4)
Definition: device_mouse.c:53
char pollrate
Definition: structures.h:241
#define NEEDS_FW_UPDATE(kb)
Definition: structures.h:161
#define imutex(kb)
Definition: device.h:22
int cmd_pollrate(usbdevice *kb, usbmode *dummy1, int dummy2, int rate, const char *dummy3)
Definition: device_mouse.c:62
int setactive_mouse(usbdevice *kb, int active)
Definition: device_mouse.c:9
Definitions for using USB interface.
#define usbsend(kb, messages, count)
usbsend macro is used to wrap _usbsend() with debugging information (file and lineno) ...
Definition: usb.h:271
uchar keys[((((152+22+12)+25)+7)/8)]
Definition: structures.h:130
#define IN_CORSAIR
Definition: device.h:65