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 File Reference
#include "command.h"
#include "device.h"
#include "devnode.h"
#include "firmware.h"
#include "input.h"
#include "profile.h"
#include "usb.h"
+ Include dependency graph for device_mouse.c:

Go to the source code of this file.

Functions

int setactive_mouse (usbdevice *kb, int active)
 
int cmd_active_mouse (usbdevice *kb, usbmode *dummy1, int dummy2, int dummy3, const char *dummy4)
 
int cmd_idle_mouse (usbdevice *kb, usbmode *dummy1, int dummy2, int dummy3, const char *dummy4)
 
int cmd_pollrate (usbdevice *kb, usbmode *dummy1, int dummy2, int rate, const char *dummy3)
 

Function Documentation

int cmd_active_mouse ( usbdevice kb,
usbmode dummy1,
int  dummy2,
int  dummy3,
const char *  dummy4 
)

Definition at line 44 of file device_mouse.c.

References setactive_mouse().

44  {
45  (void)dummy1;
46  (void)dummy2;
47  (void)dummy3;
48  (void)dummy4;
49 
50  return setactive_mouse(kb, 1);
51 }
int setactive_mouse(usbdevice *kb, int active)
Definition: device_mouse.c:9

+ Here is the call graph for this function:

int cmd_idle_mouse ( usbdevice kb,
usbmode dummy1,
int  dummy2,
int  dummy3,
const char *  dummy4 
)

Definition at line 53 of file device_mouse.c.

References setactive_mouse().

53  {
54  (void)dummy1;
55  (void)dummy2;
56  (void)dummy3;
57  (void)dummy4;
58 
59  return setactive_mouse(kb, 0);
60 }
int setactive_mouse(usbdevice *kb, int active)
Definition: device_mouse.c:9

+ Here is the call graph for this function:

int cmd_pollrate ( usbdevice kb,
usbmode dummy1,
int  dummy2,
int  rate,
const char *  dummy3 
)

Definition at line 62 of file device_mouse.c.

References MSG_SIZE, usbdevice::pollrate, and usbsend.

62  {
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
unsigned char uchar
Definition: includes.h:24
char pollrate
Definition: structures.h:241
#define usbsend(kb, messages, count)
usbsend macro is used to wrap _usbsend() with debugging information (file and lineno) ...
Definition: usb.h:271
int setactive_mouse ( usbdevice kb,
int  active 
)

Definition at line 9 of file device_mouse.c.

References usbdevice::active, lighting::forceupdate, imutex, IN_CORSAIR, IN_HID, usbdevice::input, inputupdate(), usbinput::keys, usbprofile::lastlight, MSG_SIZE, NEEDS_FW_UPDATE, usbdevice::profile, and usbsend.

Referenced by cmd_active_mouse(), and cmd_idle_mouse().

9  {
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 }
#define MSG_SIZE
Definition: structures.h:176
lighting lastlight
Definition: structures.h:107
usbprofile * profile
Definition: structures.h:221
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
#define NEEDS_FW_UPDATE(kb)
Definition: structures.h:161
#define imutex(kb)
Definition: device.h:22
#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

+ Here is the call graph for this function:

+ Here is the caller graph for this function: