ckb-next  beta-v0.2.8 at branch testing
ckb-next driver for corsair devices
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
profile_mouse.c File Reference
#include "dpi.h"
#include "profile.h"
#include "usb.h"
#include "led.h"
+ Include dependency graph for profile_mouse.c:

Go to the source code of this file.

Functions

int cmd_hwload_mouse (usbdevice *kb, usbmode *dummy1, int dummy2, int apply, const char *dummy3)
 
int cmd_hwsave_mouse (usbdevice *kb, usbmode *dummy1, int dummy2, int dummy3, const char *dummy4)
 

Function Documentation

int cmd_hwload_mouse ( usbdevice kb,
usbmode dummy1,
int  dummy2,
int  apply,
const char *  dummy3 
)

Definition at line 6 of file profile_mouse.c.

References DELAY_LONG, hwprofile::dpi, usbdevice::hw, hwtonative(), hwprofile::id, hwprofile::light, loaddpi(), loadrgb_mouse(), MSG_SIZE, hwprofile::name, PR_NAME_LEN, usbdevice::profile, and usbrecv.

6  {
7  DELAY_LONG(kb);
8  hwprofile* hw = calloc(1, sizeof(hwprofile));
9  // Ask for profile and mode IDs
10  uchar data_pkt[2][MSG_SIZE] = {
11  { 0x0e, 0x15, 0x01, 0 },
12  { 0x0e, 0x16, 0x01, 0 }
13  };
14  uchar in_pkt[MSG_SIZE];
15  for(int i = 0; i <= 1; i++){
16  data_pkt[0][3] = i;
17  if(!usbrecv(kb, data_pkt[0], in_pkt)){
18  free(hw);
19  return -1;
20  }
21  memcpy(hw->id + i, in_pkt + 4, sizeof(usbid));
22  }
23  // Ask for profile and mode names
24  for(int i = 0; i <= 1; i++){
25  data_pkt[1][3] = i;
26  if(!usbrecv(kb, data_pkt[1],in_pkt)){
27  free(hw);
28  return -1;
29  }
30  memcpy(hw->name[i], in_pkt + 4, PR_NAME_LEN * 2);
31  }
32 
33  // Load the RGB and DPI settings
34  if(loadrgb_mouse(kb, hw->light, 0)
35  || loaddpi(kb, hw->dpi, hw->light)){
36  free(hw);
37  return -1;
38  }
39 
40  // Make the profile active (if requested)
41  if(apply)
42  hwtonative(kb->profile, hw, 1);
43  // Free the existing profile (if any)
44  free(kb->hw);
45  kb->hw = hw;
46  DELAY_LONG(kb);
47  return 0;
48 }
#define MSG_SIZE
Definition: structures.h:176
usbprofile * profile
Definition: structures.h:221
int loadrgb_mouse(usbdevice *kb, lighting *light, int mode)
Definition: led_mouse.c:81
#define DELAY_LONG(kb)
The longest delay takes place where something went wrong (eg when resetting the device) ...
Definition: usb.h:155
#define PR_NAME_LEN
Definition: structures.h:99
usbid id[3+1]
Definition: structures.h:123
unsigned char uchar
Definition: includes.h:24
void hwtonative(usbprofile *profile, hwprofile *hw, int modecount)
Definition: profile.c:235
dpiset dpi[3]
Definition: structures.h:121
hwprofile * hw
Definition: structures.h:223
ushort name[3+1][16]
Definition: structures.h:125
#define usbrecv(kb, out_msg, in_msg)
usbrecv macro is used to wrap _usbrecv() with debugging information (file and lineno) ...
Definition: usb.h:256
lighting light[3]
Definition: structures.h:120
int loaddpi(usbdevice *kb, dpiset *dpi, lighting *light)
Definition: dpi.c:152

+ Here is the call graph for this function:

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

Definition at line 50 of file profile_mouse.c.

References DELAY_LONG, hwprofile::dpi, usbdevice::hw, hwprofile::id, hwprofile::light, MD_NAME_LEN, MSG_SIZE, hwprofile::name, nativetohw(), usbdevice::profile, savedpi(), savergb_mouse(), and usbsend.

50  {
51  DELAY_LONG(kb);
52  hwprofile* hw = kb->hw;
53  if(!hw)
54  hw = kb->hw = calloc(1, sizeof(hwprofile));
55  nativetohw(kb->profile, hw, 1);
56  // Save the profile and mode names
57  uchar data_pkt[2][MSG_SIZE] = {
58  { 0x07, 0x16, 0x01, 0 },
59  { 0x07, 0x15, 0x01, 0 },
60  };
61  for(int i = 0; i <= 1; i++){
62  data_pkt[0][3] = i;
63  memcpy(data_pkt[0] + 4, hw->name[i], MD_NAME_LEN * 2);
64  if(!usbsend(kb, data_pkt[0], 1))
65  return -1;
66  }
67  // Save the IDs
68  for(int i = 0; i <= 1; i++){
69  data_pkt[1][3] = i;
70  memcpy(data_pkt[1] + 4, hw->id + i, sizeof(usbid));
71  if(!usbsend(kb, data_pkt[1], 1))
72  return -1;
73  }
74  // Save the RGB data for the non-DPI zones
75  if(savergb_mouse(kb, hw->light, 0))
76  return -1;
77  // Save the DPI data (also saves RGB for those states)
78  if(savedpi(kb, hw->dpi, hw->light))
79  return -1;
80  DELAY_LONG(kb);
81  return 0;
82 }
int savergb_mouse(usbdevice *kb, lighting *light, int mode)
Definition: led_mouse.c:62
#define MSG_SIZE
Definition: structures.h:176
usbprofile * profile
Definition: structures.h:221
#define DELAY_LONG(kb)
The longest delay takes place where something went wrong (eg when resetting the device) ...
Definition: usb.h:155
int savedpi(usbdevice *kb, dpiset *dpi, lighting *light)
Definition: dpi.c:124
#define MD_NAME_LEN
Definition: structures.h:82
usbid id[3+1]
Definition: structures.h:123
unsigned char uchar
Definition: includes.h:24
dpiset dpi[3]
Definition: structures.h:121
void nativetohw(usbprofile *profile, hwprofile *hw, int modecount)
Definition: profile.c:252
hwprofile * hw
Definition: structures.h:223
ushort name[3+1][16]
Definition: structures.h:125
#define usbsend(kb, messages, count)
usbsend macro is used to wrap _usbsend() with debugging information (file and lineno) ...
Definition: usb.h:239
lighting light[3]
Definition: structures.h:120

+ Here is the call graph for this function: