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
command.h
Go to the documentation of this file.
1 #ifndef COMMAND_H
2 #define COMMAND_H
3 
4 #include "includes.h"
5 
6 // Command operations
7 typedef enum {
8  // Special - handled by readcmd, no device functions
9  NONE = -11,
10  DELAY = -10, CMD_FIRST = DELAY,
11  MODE = -9,
12  SWITCH = -8,
13  LAYOUT = -7,
14  ACCEL = -6,
16  NOTIFYON = -4,
17  NOTIFYOFF = -3,
18  FPS = -2,
19  DITHER = -1,
20 
21  // Hardware data
22  HWLOAD = 0, CMD_VT_FIRST = 0,
26 
27  // Software control on/off
30 
31  // Profile/mode metadata
36  ID,
38 
39  // LED control
40  RGB,
42  ION,
44 
45  // Key binding control
50 
51  // DPI control
52  DPI,
56 
57  // Notifications and output
60  GET,
62 
64 } cmd;
65 #define CMD_COUNT (CMD_LAST - CMD_FIRST + 2)
66 #define CMD_DEV_COUNT (CMD_LAST - CMD_VT_FIRST + 1)
67 
68 // Device command vtable. Most have a standard prototype, but a few are exceptions.
69 // Not all parameters are used by all commands - they are sometimes repurposed or used as dummy arguments. See relevant headers.
70 typedef void (*cmdhandler)(usbdevice* kb, usbmode* modeidx, int notifyidx, int keyindex, const char* parameter); // Normal command
71 typedef int (*cmdhandler_io)(usbdevice* kb, usbmode* modeidx, int notifyidx, int keyindex, const char* parameter); // Command with hardware I/O - returns zero on success
72 typedef void (*cmdhandler_mac)(usbdevice* kb, usbmode* modeidx, int notifyidx, const char* keys, const char* assignment); // Macro command has a different left-side handler
73 typedef union devcmd {
74  // Commands can be accessed by name or by position
78  struct {
79  // profile.h
80  cmdhandler_io hwload;
81  cmdhandler_io hwsave;
82  // firmware.h
84  // device.h
85  cmdhandler_io pollrate;
86 
87  // device.h
88  cmdhandler_io active;
89  cmdhandler_io idle;
90 
91  // profile.h
92  cmdhandler erase;
93  cmdhandler eraseprofile;
94  cmdhandler name;
95  cmdhandler profilename;
96  cmdhandler id;
97  cmdhandler profileid;
98 
99  // led.h
100  cmdhandler rgb;
101  cmdhandler ioff;
102  cmdhandler ion;
103  cmdhandler iauto;
104 
105  // input.h
106  cmdhandler bind;
107  cmdhandler unbind;
108  cmdhandler rebind;
109  cmdhandler_mac macro;
110 
111  // dpi.h
112  cmdhandler_mac dpi;
113  cmdhandler dpisel;
114  cmdhandler lift;
115  cmdhandler snap;
116 
117  // notify.h
118  cmdhandler notify;
119  cmdhandler inotify;
120  cmdhandler get;
122 
123  // Extra functions not command-related
124  // device.h
125  int (*start)(usbdevice* kb, int makeactive);
126  void (*setmodeindex)(usbdevice* kb, int index);
127  // profile.h
128  void (*allocprofile)(usbdevice* kb);
129  int (*loadprofile)(usbdevice* kb);
130  void (*freeprofile)(usbdevice* kb);
131  // led.h
132  int (*updatergb)(usbdevice* kb, int force);
133  // input.h
134  void (*updateindicators)(usbdevice* kb, int force);
135  // dpi.h
136  int (*updatedpi)(usbdevice* kb, int force);
137  };
138 } devcmd;
139 
140 // Parse input from FIFO. Lock dmutex first (see device.h)
141 // This function is also responsible for calling all of the cmd_ functions. They should not be invoked elsewhere.
142 int readcmd(usbdevice* kb, const char* line);
143 
144 #endif // COMMAND_H
145 
Definition: command.h:43
Definition: command.h:19
void freeprofile(usbdevice *kb)
Definition: profile.c:253
Definition: command.h:73
int restart()
Definition: main.c:228
Definition: command.h:10
Definition: command.h:48
Definition: command.h:29
cmd
Definition: command.h:7
struct parameter contains the values for a fresh started macro_play thread. parameter_t is the typede...
Definition: input.h:54
cmdhandler do_cmd[(CMD_LAST-CMD_VT_FIRST+1)]
Definition: command.h:75
Definition: command.h:42
Definition: command.h:28
Definition: command.h:54
union devcmd devcmd
int updatedpi(usbdevice *kb, int force)
Definition: dpi.c:106
Definition: command.h:9
Definition: command.h:18
void(* cmdhandler)(usbdevice *kb, usbmode *modeidx, int notifyidx, int keyindex, const char *parameter)
Definition: command.h:70
#define CMD_DEV_COUNT
Definition: command.h:66
cmdhandler_mac do_macro[(CMD_LAST-CMD_VT_FIRST+1)]
Definition: command.h:77
Definition: command.h:13
Definition: command.h:40
void allocprofile(usbdevice *kb)
Definition: profile.c:198
Definition: main.c:42
int(* cmdhandler_io)(usbdevice *kb, usbmode *modeidx, int notifyidx, int keyindex, const char *parameter)
Definition: command.h:71
Definition: command.h:46
Definition: command.h:22
Definition: command.h:47
Definition: command.h:60
cmdhandler_io do_io[(CMD_LAST-CMD_VT_FIRST+1)]
Definition: command.h:76
Definition: command.h:53
Definition: command.h:36
Definition: command.h:41
Definition: command.h:23
Definition: command.h:34
int readcmd(usbdevice *kb, const char *line)
Definition: command.c:68
Definition: command.h:52
Definition: command.h:12
Definition: command.h:58
int fwupdate(usbdevice *kb, const char *path, int nnumber)
Definition: firmware.c:55
Definition: command.h:14
void(* cmdhandler_mac)(usbdevice *kb, usbmode *modeidx, int notifyidx, const char *keys, const char *assignment)
Definition: command.h:72
Definition: command.h:11
Definition: command.h:32
Definition: command.h:55
Definition: command.h:49
int loadprofile(usbdevice *kb)
Definition: profile.c:208