This repository has been archived by the owner on Aug 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
effect.c
80 lines (71 loc) · 2.21 KB
/
effect.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* rzctl(1) -- Razer mouse control utility
* Copyright (c) 2019 Angel <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdio.h>
#include "effect.h"
#include "util.h"
#include "list_devices.h"
int razer_set_effect(struct razer_device *dev, int effect)
{
uint8_t args[3] = {
1, /* persist value? */
0, /* LED ID */
effect
};
/* set logo effect */
args[1] = LED_SCROLL;
razer_send_report(dev, 0x03, 0x02, args, sizeof(args), NULL, 0);
/* set scroll wheel effect */
args[1] = LED_LOGO;
razer_send_report(dev, 0x03, 0x02, args, sizeof(args), NULL, 0);
return 0;
}
int set_effect(int verbose, const char *s_effect)
{
int effect;
struct razer_device *devs;
int ndevs, i;
if (!strcmp("solid", s_effect)) {
effect = EFFECT_SOLID;
} else if (!strcmp("pulse", s_effect)) {
effect = EFFECT_PULSE;
} else if (!strcmp("spectrum", s_effect)) {
effect = EFFECT_SPECTRUM;
} else {
fprintf(stderr, PR_ERROR "invalid effect name: `%s'\n", s_effect);
return 1;
}
if (libusb_init(NULL) < 0) {
fprintf(stderr, PR_ERROR "could not initialize libusb\n");
return 1;
}
if (verbose)
libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_DEBUG);
ndevs = razer_get_devices(&devs);
if (ndevs < 0) {
fprintf(stderr, PR_ERROR "could not get Razer devices\n");
return 1;
}
for (i = 0; i < ndevs; i++) {
razer_init(&devs[i]);
razer_set_effect(&devs[i], effect);
razer_deinit(&devs[i]);
}
razer_free_devices(&devs);
libusb_exit(NULL);
return 0;
}