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
notify.c File Reference
#include "device.h"
#include "devnode.h"
#include "dpi.h"
#include "led.h"
#include "notify.h"
#include "profile.h"
+ Include dependency graph for notify.c:

Go to the source code of this file.

Macros

#define HWMODE_OR_RETURN(kb, index)
 
#define HW_STANDARD
 

Functions

void nprintf (usbdevice *kb, int nodenumber, usbmode *mode, const char *format,...)
 
void nprintkey (usbdevice *kb, int nnumber, int keyindex, int down)
 
void nprintind (usbdevice *kb, int nnumber, int led, int on)
 
void cmd_notify (usbdevice *kb, usbmode *mode, int nnumber, int keyindex, const char *toggle)
 
static void _cmd_get (usbdevice *kb, usbmode *mode, int nnumber, const char *setting)
 
void cmd_get (usbdevice *kb, usbmode *mode, int nnumber, int dummy, const char *setting)
 
int restart ()
 
void cmd_restart (usbdevice *kb, usbmode *mode, int nnumber, int dummy, const char *content)
 

Macro Definition Documentation

#define HW_STANDARD
Value:
if(!kb->hw) \
return; \
unsigned index = INDEX_OF(mode, profile->mode); \
/* Make sure the mode number is valid */ \
#define INDEX_OF(entry, array)
Definition: includes.h:27
#define HWMODE_OR_RETURN(kb, index)
Definition: notify.c:73

Definition at line 83 of file notify.c.

Referenced by _cmd_get().

#define HWMODE_OR_RETURN (   kb,
  index 
)
Value:
if(IS_K95(kb)){ \
if((index) >= HWMODE_K95) \
return; \
} else { \
if((index) >= HWMODE_K70) \
return; \
}
#define HWMODE_K70
Definition: structures.h:115
#define HWMODE_K95
Definition: structures.h:116
#define IS_K95(kb)
Definition: usb.h:83

Definition at line 73 of file notify.c.

Function Documentation

static void _cmd_get ( usbdevice kb,
usbmode mode,
int  nnumber,
const char *  setting 
)
static

Definition at line 90 of file notify.c.

References dpiset::current, usbmode::dpi, hwprofile::dpi, gethwmodename(), gethwprofilename(), getid(), getmodename(), getprofilename(), usbdevice::hw, usbdevice::hw_ileds, HW_STANDARD, I_CAPS, I_NUM, I_SCROLL, usbmode::id, usbprofile::id, hwprofile::id, usbdevice::input, keymap, usbinput::keys, dpiset::lift, usbmode::light, hwprofile::light, usbid::modified, N_KEYS_INPUT, nprintf(), nprintind(), nprintkey(), printdpi(), printrgb(), usbdevice::profile, and dpiset::snap.

Referenced by cmd_get().

90  {
91  usbprofile* profile = kb->profile;
92  if(!strcmp(setting, ":mode")){
93  // Get the current mode number
94  nprintf(kb, nnumber, mode, "switch\n");
95  return;
96  } else if(!strcmp(setting, ":rgb")){
97  // Get the current RGB settings
98  char* rgb = printrgb(&mode->light, kb);
99  nprintf(kb, nnumber, mode, "rgb %s\n", rgb);
100  free(rgb);
101  return;
102  } else if(!strcmp(setting, ":hwrgb")){
103  // Get the current hardware RGB settings
104  HW_STANDARD;
105  char* rgb = printrgb(kb->hw->light + index, kb);
106  nprintf(kb, nnumber, mode, "hwrgb %s\n", rgb);
107  free(rgb);
108  return;
109  } else if(!strcmp(setting, ":profilename")){
110  // Get the current profile name
111  char* name = getprofilename(profile);
112  nprintf(kb, nnumber, 0, "profilename %s\n", name[0] ? name : "Unnamed");
113  free(name);
114  } else if(!strcmp(setting, ":name")){
115  // Get the current mode name
116  char* name = getmodename(mode);
117  nprintf(kb, nnumber, mode, "name %s\n", name[0] ? name : "Unnamed");
118  free(name);
119  } else if(!strcmp(setting, ":hwprofilename")){
120  // Get the current hardware profile name
121  if(!kb->hw)
122  return;
123  char* name = gethwprofilename(kb->hw);
124  nprintf(kb, nnumber, 0, "hwprofilename %s\n", name[0] ? name : "Unnamed");
125  free(name);
126  } else if(!strcmp(setting, ":hwname")){
127  // Get the current hardware mode name
128  HW_STANDARD;
129  char* name = gethwmodename(kb->hw, index);
130  nprintf(kb, nnumber, mode, "hwname %s\n", name[0] ? name : "Unnamed");
131  free(name);
132  } else if(!strcmp(setting, ":profileid")){
133  // Get the current profile ID
134  char* guid = getid(&profile->id);
135  int modified;
136  memcpy(&modified, &profile->id.modified, sizeof(modified));
137  nprintf(kb, nnumber, 0, "profileid %s %x\n", guid, modified);
138  free(guid);
139  } else if(!strcmp(setting, ":id")){
140  // Get the current mode ID
141  char* guid = getid(&mode->id);
142  int modified;
143  memcpy(&modified, &mode->id.modified, sizeof(modified));
144  nprintf(kb, nnumber, mode, "id %s %x\n", guid, modified);
145  free(guid);
146  } else if(!strcmp(setting, ":hwprofileid")){
147  // Get the current hardware profile ID
148  if(!kb->hw)
149  return;
150  char* guid = getid(&kb->hw->id[0]);
151  int modified;
152  memcpy(&modified, &kb->hw->id[0].modified, sizeof(modified));
153  nprintf(kb, nnumber, 0, "hwprofileid %s %x\n", guid, modified);
154  free(guid);
155  } else if(!strcmp(setting, ":hwid")){
156  // Get the current hardware mode ID
157  HW_STANDARD;
158  char* guid = getid(&kb->hw->id[index + 1]);
159  int modified;
160  memcpy(&modified, &kb->hw->id[index + 1].modified, sizeof(modified));
161  nprintf(kb, nnumber, mode, "hwid %s %x\n", guid, modified);
162  free(guid);
163  } else if(!strcmp(setting, ":keys")){
164  // Get the current state of all keys
165  for(int i = 0; i < N_KEYS_INPUT; i++){
166  if(!keymap[i].name)
167  continue;
168  int byte = i / 8, bit = 1 << (i & 7);
169  uchar state = kb->input.keys[byte] & bit;
170  if(state)
171  nprintkey(kb, nnumber, i, 1);
172  }
173  } else if(!strcmp(setting, ":i")){
174  // Get the current state of all indicator LEDs
175  if(kb->hw_ileds & I_NUM) nprintind(kb, nnumber, I_NUM, 1);
176  if(kb->hw_ileds & I_CAPS) nprintind(kb, nnumber, I_CAPS, 1);
177  if(kb->hw_ileds & I_SCROLL) nprintind(kb, nnumber, I_SCROLL, 1);
178  } else if(!strcmp(setting, ":dpi")){
179  // Get the current DPI levels
180  char* dpi = printdpi(&mode->dpi, kb);
181  nprintf(kb, nnumber, mode, "dpi %s\n", dpi);
182  free(dpi);
183  return;
184  } else if(!strcmp(setting, ":hwdpi")){
185  // Get the current hardware DPI levels
186  HW_STANDARD;
187  char* dpi = printdpi(kb->hw->dpi + index, kb);
188  nprintf(kb, nnumber, mode, "hwdpi %s\n", dpi);
189  free(dpi);
190  return;
191  } else if(!strcmp(setting, ":dpisel")){
192  // Get the currently-selected DPI
193  nprintf(kb, nnumber, mode, "dpisel %d\n", mode->dpi.current);
194  } else if(!strcmp(setting, ":hwdpisel")){
195  // Get the currently-selected hardware DPI
196  HW_STANDARD;
197  nprintf(kb, nnumber, mode, "hwdpisel %d\n", kb->hw->dpi[index].current);
198  } else if(!strcmp(setting, ":lift")){
199  // Get the mouse lift height
200  nprintf(kb, nnumber, mode, "lift %d\n", mode->dpi.lift);
201  } else if(!strcmp(setting, ":hwlift")){
202  // Get the hardware lift height
203  HW_STANDARD;
204  nprintf(kb, nnumber, mode, "hwlift %d\n", kb->hw->dpi[index].lift);
205  } else if(!strcmp(setting, ":snap")){
206  // Get the angle snap status
207  nprintf(kb, nnumber, mode, "snap %s\n", mode->dpi.snap ? "on" : "off");
208  } else if(!strcmp(setting, ":hwsnap")){
209  // Get the hardware angle snap status
210  HW_STANDARD;
211  nprintf(kb, nnumber, mode, "hwsnap %s\n", kb->hw->dpi[index].snap ? "on" : "off");
212  }
213 }
void nprintf(usbdevice *kb, int nodenumber, usbmode *mode, const char *format,...)
Definition: notify.c:8
usbprofile * profile
Definition: structures.h:221
char * getprofilename(usbprofile *profile)
Definition: profile.c:156
usbinput input
Definition: structures.h:245
char * getmodename(usbmode *mode)
Definition: profile.c:152
const key keymap[(((152+22+12)+25)+12)]
Definition: keymap.c:5
char modified[4]
Definition: structures.h:10
usbid id
Definition: structures.h:111
lighting light
Definition: structures.h:84
usbid id[3+1]
Definition: structures.h:123
dpiset dpi
Definition: structures.h:86
char * gethwprofilename(hwprofile *profile)
Definition: profile.c:164
char * gethwmodename(hwprofile *profile, int index)
Definition: profile.c:160
unsigned char uchar
Definition: includes.h:24
void nprintkey(usbdevice *kb, int nnumber, int keyindex, int down)
Definition: notify.c:35
#define HW_STANDARD
Definition: notify.c:83
Definition: main.c:42
void nprintind(usbdevice *kb, int nnumber, int led, int on)
Definition: notify.c:43
uchar snap
Definition: structures.h:67
char * getid(usbid *id)
Definition: profile.c:79
uchar lift
Definition: structures.h:65
dpiset dpi[3]
Definition: structures.h:121
#define I_NUM
Definition: structures.h:19
char * printrgb(const lighting *light, const usbdevice *kb)
Definition: led.c:120
hwprofile * hw
Definition: structures.h:223
#define N_KEYS_INPUT
Definition: keymap.h:36
uchar current
Definition: structures.h:61
char * printdpi(const dpiset *dpi, const usbdevice *kb)
Definition: dpi.c:84
uchar hw_ileds
Definition: structures.h:247
uchar keys[((((152+22+12)+25)+7)/8)]
Definition: structures.h:130
lighting light[3]
Definition: structures.h:120
#define I_CAPS
Definition: structures.h:20
#define I_SCROLL
Definition: structures.h:21
usbid id
Definition: structures.h:88

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void cmd_get ( usbdevice kb,
usbmode mode,
int  nnumber,
int  dummy,
const char *  setting 
)

Definition at line 215 of file notify.c.

References _cmd_get(), and imutex.

215  {
216  (void)dummy;
217 
218  pthread_mutex_lock(imutex(kb));
219  _cmd_get(kb, mode, nnumber, setting);
220  pthread_mutex_unlock(imutex(kb));
221 }
static void _cmd_get(usbdevice *kb, usbmode *mode, int nnumber, const char *setting)
Definition: notify.c:90
#define imutex(kb)
Definition: device.h:22

+ Here is the call graph for this function:

void cmd_notify ( usbdevice kb,
usbmode mode,
int  nnumber,
int  keyindex,
const char *  toggle 
)

Definition at line 61 of file notify.c.

References CLEAR_KEYBIT, imutex, N_KEYS_INPUT, usbmode::notify, and SET_KEYBIT.

61  {
62  if(keyindex >= N_KEYS_INPUT)
63  return;
64  pthread_mutex_lock(imutex(kb));
65  if(!strcmp(toggle, "on") || *toggle == 0)
66  SET_KEYBIT(mode->notify[nnumber], keyindex);
67  else if(!strcmp(toggle, "off"))
68  CLEAR_KEYBIT(mode->notify[nnumber], keyindex);
69  pthread_mutex_unlock(imutex(kb));
70 }
#define CLEAR_KEYBIT(array, index)
Definition: structures.h:16
#define SET_KEYBIT(array, index)
Definition: structures.h:15
#define imutex(kb)
Definition: device.h:22
#define N_KEYS_INPUT
Definition: keymap.h:36
uchar notify[10][((((152+22+12)+25)+7)/8)]
Definition: structures.h:91
void cmd_restart ( usbdevice kb,
usbmode mode,
int  nnumber,
int  dummy,
const char *  content 
)

Definition at line 225 of file notify.c.

References ckb_info, nprintf(), and restart().

225  {
226  (void)mode;
227  (void)nnumber;
228  (void)dummy;
229 
230  ckb_info("RESTART called with %s\n", content);
231  nprintf(kb, -1, 0, "RESTART called with %s\n", content);
232  restart();
233 }
void nprintf(usbdevice *kb, int nodenumber, usbmode *mode, const char *format,...)
Definition: notify.c:8
#define ckb_info(fmt, args...)
Definition: includes.h:55
int restart()
Definition: main.c:228

+ Here is the call graph for this function:

void nprintf ( usbdevice kb,
int  nodenumber,
usbmode mode,
const char *  format,
  ... 
)

Definition at line 8 of file notify.c.

References INDEX_OF, usbprofile::mode, usbdevice::outfifo, OUTFIFO_MAX, and usbdevice::profile.

Referenced by _cmd_get(), cmd_fwupdate(), cmd_restart(), fwupdate(), nprintind(), and nprintkey().

8  {
9  if(!kb)
10  return;
11  usbprofile* profile = kb->profile;
12  va_list va_args;
13  int fifo;
14  if(nodenumber >= 0){
15  // If node number was given, print to that node (if open)
16  if((fifo = kb->outfifo[nodenumber] - 1) != -1){
17  va_start(va_args, format);
18  if(mode)
19  dprintf(fifo, "mode %d ", INDEX_OF(mode, profile->mode) + 1);
20  vdprintf(fifo, format, va_args);
21  }
22  return;
23  }
24  // Otherwise, print to all nodes
25  for(int i = 0; i < OUTFIFO_MAX; i++){
26  if((fifo = kb->outfifo[i] - 1) != -1){
27  va_start(va_args, format);
28  if(mode)
29  dprintf(fifo, "mode %d ", INDEX_OF(mode, profile->mode) + 1);
30  vdprintf(fifo, format, va_args);
31  }
32  }
33 }
usbprofile * profile
Definition: structures.h:221
usbmode mode[6]
Definition: structures.h:103
int outfifo[10]
Definition: structures.h:227
#define INDEX_OF(entry, array)
Definition: includes.h:27
#define OUTFIFO_MAX
Definition: structures.h:24

+ Here is the caller graph for this function:

void nprintind ( usbdevice kb,
int  nnumber,
int  led,
int  on 
)

Definition at line 43 of file notify.c.

References I_CAPS, I_NUM, I_SCROLL, and nprintf().

Referenced by _cmd_get(), and updateindicators_kb().

43  {
44  const char* name = 0;
45  switch(led){
46  case I_NUM:
47  name = "num";
48  break;
49  case I_CAPS:
50  name = "caps";
51  break;
52  case I_SCROLL:
53  name = "scroll";
54  break;
55  default:
56  return;
57  }
58  nprintf(kb, nnumber, 0, "i %c%s\n", on ? '+' : '-', name);
59 }
void nprintf(usbdevice *kb, int nodenumber, usbmode *mode, const char *format,...)
Definition: notify.c:8
#define I_NUM
Definition: structures.h:19
#define I_CAPS
Definition: structures.h:20
#define I_SCROLL
Definition: structures.h:21

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void nprintkey ( usbdevice kb,
int  nnumber,
int  keyindex,
int  down 
)

Definition at line 35 of file notify.c.

References keymap, key::name, and nprintf().

Referenced by _cmd_get(), and inputupdate_keys().

35  {
36  const key* map = keymap + keyindex;
37  if(map->name)
38  nprintf(kb, nnumber, 0, "key %c%s\n", down ? '+' : '-', map->name);
39  else
40  nprintf(kb, nnumber, 0, "key %c#%d\n", down ? '+' : '-', keyindex);
41 }
void nprintf(usbdevice *kb, int nodenumber, usbmode *mode, const char *format,...)
Definition: notify.c:8
const key keymap[(((152+22+12)+25)+12)]
Definition: keymap.c:5
Definition: keymap.h:49
const char * name
Definition: keymap.h:50

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int restart ( )

Definition at line 228 of file main.c.

References ckb_err, main(), main_ac, main_av, and quitWithLock().

Referenced by cmd_restart(), and main().

228  {
229  ckb_err("restart called, running quit without mutex-lock.\n");
230  quitWithLock(0);
231  return main(main_ac, main_av);
232 }
static char ** main_av
Definition: main.c:8
#define ckb_err(fmt, args...)
Definition: includes.h:49
int main(int argc, char **argv)
Definition: main.c:88
static void quitWithLock(char mut)
quitWithLock
Definition: main.c:40
static int main_ac
Definition: main.c:7

+ Here is the call graph for this function:

+ Here is the caller graph for this function: