Skip to content

Commit 54add43

Browse files
committed
RELEASE: 0.2.3
Merge branch 'release/0.2.3'
2 parents 5c8a2b8 + 4186808 commit 54add43

File tree

4 files changed

+170
-55
lines changed

4 files changed

+170
-55
lines changed

AUTHORS.creole

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
== RatSlap Contributors ==
66

7-
-
7+
[[ https://github.com/captn3m0 | Nemo ]]
8+
* [[ https://github.com/krayon/ratslap/pull/14 | GitHub PR #14 ]]
89
910
<<< vim:set ts=4 sw=4 tw=80 et cindent ai si syn=creole: >>>

CONTRIBUTING.creole

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
= Contributing =
22

3-
== Pull Requests ==
3+
== Making Changes ==
44

5-
If you have a pull request (PR) for a change or a fix, please try to base your
6-
changes off develop unless it's a serious security issue with a specific release
7-
in which case base it off that.
8-
9-
Don't be too concerned if you can't deside, an incorrectly targeted PR is better
10-
than no PR :D
5+
Wherever possible, please base your changes on the //develop// branch. The one
6+
exception is if you have a fix for a security issue in a specific release in
7+
which case base it off that release branch. Either way, don't be too concerned
8+
if you can't decide what to branch off, an incorrectly targeted PR is better
9+
than no PR at all :D
1110

1211
... and Thank you.
1312

13+
== Basic workflow ==
14+
15+
# Go to the project page, and select //Fork//
16+
# Clone your copy of the repository:
17+
{{{
18+
git clone https://gitlab.com/<YOURUSERNAME>/ratslap
19+
}}}
20+
# Check out the //develop// branch as your new feature branch:
21+
{{{
22+
git checkout -b feature/coolnewfeature origin/develop
23+
}}}
24+
# Make your changes and commit them to your branch.
25+
# Push your branch up to your repository:
26+
{{{
27+
git push origin feature/coolnewfeature:feature/coolnewfeature
28+
}}}
29+
# Create a Pull Request (PR - GitHub)/Merge Request (MR - GitLab) with
30+
//develop// as the base/destination.
31+
1432
<<< vim:set ts=4 sw=4 tw=80 et cindent ai si syn=creole: >>>

README.creole

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,44 @@ please see [[CONTRIBUTING.creole]] .
3737

3838
== Availability ==
3939

40-
//RatSlap// source is available on [[https://gitlab.com/krayon/ratslap|GitLab]],
41-
[[https://github.com/krayon/ratslap|GitHub]] and
42-
[[https://bitbucket.org/krayonx/ratslap|BitBucket]] with the primary (public)
43-
repository being [[https://gitlab.com/krayon/ratslap|GitLab]].
40+
The most current release is v0.2.3 and is available from:
41+
42+
* [[https://gitlab.com/krayon/ratslap/tags/0.2.3|GitLab (RELEASE v0.2.3)]]
43+
* [[https://github.com/krayon/ratslap/releases/tag/0.2.3|GitHub (RELEASE v0.2.3)]]
4444
4545
//RatSlap// binary and archive should be signed with my GPG key (
4646
[[http://pgp.mit.edu/pks/lookup?op=get&search=0x231A94F481ECF212|231A 94F4 81EC F212]]
4747
).
4848

49+
Binary signature files end in .asc and can be verified using
50+
[[https://www.gnupg.org/|gpg/gpg2]] thus:
51+
{{{
52+
gpg --verify ratslap-0.2.2.x86_64.tar.gz.asc
53+
gpg: assuming signed data in `ratslap-0.2.2.x86_64.tar.gz'
54+
gpg: Signature made 2018-05-01T01:00:52 AEST using RSA key ID 81ECF212
55+
gpg: Good signature from "Krayon (Code Signing Key) <krayon.git@qdnx.org>"
56+
gpg: WARNING: This key is not certified with a trusted signature!
57+
gpg: There is no indication that the signature belongs to the owner.
58+
Primary key fingerprint: CDEC 1051 0874 06FB 8323 46DC 231A 94F4 81EC F212
59+
}}}
60+
61+
You may first need to retrieve my public key if you haven't already done so:
62+
{{{
63+
gpg --recv-keys 81ECF212
64+
gpg: keyring `/home/krayon//.gnupg/secring.gpg' created
65+
gpg: requesting key 81ECF212 from hkp server keys.gnupg.net
66+
gpg: /home/krayon//.gnupg/trustdb.gpg: trustdb created
67+
gpg: key 81ECF212: public key "Krayon (Code Signing Key) <krayon.git@qdnx.org>" imported
68+
gpg: no ultimately trusted keys found
69+
gpg: Total number processed: 1
70+
gpg: imported: 1 (RSA: 1)
71+
}}}
72+
73+
//RatSlap// source is available on [[https://gitlab.com/krayon/ratslap|GitLab]],
74+
[[https://github.com/krayon/ratslap|GitHub]] and
75+
[[https://bitbucket.org/krayonx/ratslap|BitBucket]] with the primary (public)
76+
repository being [[https://gitlab.com/krayon/ratslap|GitLab]].
77+
4978
== Bug Tracker ==
5079

5180
Bugs are tracked on the
@@ -254,14 +283,19 @@ tool cannot do).
254283
** Prettier Changelog
255284
** Added man page
256285
* v0.2.2
257-
** [[https://bugs.qdnx.org/121|QB#121 - set_debug is deprecated, use libusb_set_option instead]]
286+
** [[https://bugs.qdnx.org/bug/121|QB#121 - set_debug is deprecated, use libusb_set_option instead]]
258287
** Added some documentation: AUTHORS, CONTRIBUTING
288+
* v0.2.3
289+
** [[https://bugs.qdnx.org/bug/122|QB#122 - Help shouldn't require USB permissions]]
290+
** [[https://bugs.qdnx.org/bug/123|QB#123 - Check mode_load() return code]]
291+
** [[https://bugs.qdnx.org/bug/124|QB#124 - Failed operations don't abort execution]]
259292
260293
== TODO ==
261294

262-
* [[https://bugs.qdnx.org/bug/113|QB#113 - Configure DPI #[1-4], DPI Default and * DPI Shift values]]
263-
* [[https://bugs.qdnx.org/bug/114|QB#114 - Factory reset option]]
264-
* [[https://bugs.qdnx.org/bug/115|QB#115 - Ability to save/load profiles]]
295+
* BUG: [[https://bugs.qdnx.org/bug/125|QB#125 - Error assigning Num+]]
296+
* FEATURE: [[https://bugs.qdnx.org/bug/113|QB#113 - Configure DPI #[1-4], DPI Default and * DPI Shift values]]
297+
* FEATURE: [[https://bugs.qdnx.org/bug/114|QB#114 - Factory reset option]]
298+
* FEATURE: [[https://bugs.qdnx.org/bug/115|QB#115 - Ability to save/load profiles]]
265299
266300
== Notes ==
267301

main.c

Lines changed: 101 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,44 @@ const int report_rate[] = {
391391
};
392392
const int n_report_rates = 4;
393393

394-
static int dpi_point(int dpip) {
395-
return dpip * 250;
396-
}
394+
397395

398396
libusb_context *usb_ctx = NULL;
399397
libusb_device_handle *usb_dev_handle = NULL;
400398
libusb_device *usb_device = NULL;
401399
struct libusb_device_descriptor usb_desc;
402400
int usb_interface_index = -1;
401+
int mouse_primed = 0;
402+
403+
404+
405+
static int dpi_point(int dpip);
406+
static void help_version(void);
407+
static void help_usage(void);
408+
static void keylist_print(void);
409+
static libusb_context *usb_init(void);
410+
static int usb_deinit(void);
411+
static libusb_device_handle *mouse_init(const uint16_t vendor_id, const uint16_t product_id, const char* product_name);
412+
static int mouse_deinit(void);
413+
static void display_mouse_hid(const uint16_t vendor_id, const uint16_t product_id);
414+
int mouse_hid_detach_kernel(int iface);
415+
int mouse_hid_attach_kernel(int iface);
416+
static t_mode change_mode(libusb_device_handle *usb_dev_handle, t_mode mode);
417+
static int mode_load(unsigned char *mode_data, libusb_device_handle *usb_dev_handle, t_mode mode);
418+
static int mode_save(unsigned char *mode_data, libusb_device_handle *usb_dev_handle, const t_mode mode);
419+
static int mode_print(unsigned char *mode_data, int len);
420+
static int set_mode_rate(unsigned char *mode_data, const int rate);
421+
static unsigned char set_mode_colour(unsigned char *mode_data, const t_colour colour);
422+
static int set_mode_button(unsigned char *mode_data, const unsigned char button, const char *keys);
423+
static int mouse_editmode(void);
424+
int mouse_prime(void);
425+
int mouse_unprime(void);
426+
427+
428+
429+
static int dpi_point(int dpip) {
430+
return dpip * 250;
431+
}
403432

404433
static void help_version(void) {
405434
printf("%s v%s (BUILT: %s)\n", (APP_NAME), (APP_VERSION), (BUILD_DATE));
@@ -740,7 +769,7 @@ static t_mode change_mode(libusb_device_handle *usb_dev_handle, t_mode mode) {
740769

741770
int ret;
742771

743-
if (!usb_dev_handle || mode >= mode_COUNT) return mode_COUNT;
772+
if (!mouse_primed || !usb_dev_handle || mode >= mode_COUNT) return mode_COUNT;
744773

745774
if (mode == mode_f3) {
746775
// Top Mode
@@ -791,7 +820,7 @@ static int mode_load(unsigned char *mode_data, libusb_device_handle *usb_dev_han
791820
uint16_t mi;
792821
int ret;
793822

794-
if (!mode_data || !usb_dev_handle || mode >= mode_COUNT) return 0;
823+
if (!mouse_primed || !mode_data || !usb_dev_handle || mode >= mode_COUNT) return 0;
795824

796825
if (mode == mode_f3) mi = 0xf3;
797826
else if (mode == mode_f4) mi = 0xf4;
@@ -838,7 +867,7 @@ static int mode_save(unsigned char *mode_data, libusb_device_handle *usb_dev_han
838867

839868
unsigned char cmp[255];
840869

841-
if (!mode_data || !usb_dev_handle || mode >= mode_COUNT) return 0;
870+
if (!mouse_primed || !mode_data || !usb_dev_handle || mode >= mode_COUNT) return 0;
842871

843872
if (mode == mode_f3) mi = 0xf3;
844873
else if (mode == mode_f4) mi = 0xf4;
@@ -1094,6 +1123,8 @@ static int set_mode_button(unsigned char *mode_data, const unsigned char button,
10941123
++ky;
10951124
}
10961125

1126+
// FIXME: QB#125 - Handle Keys containing '+' (currently only "Num+")
1127+
10971128
// If it's not the last element...
10981129
if (*kptr) {
10991130
// And didn't match a modifier, BAD!
@@ -1148,8 +1179,9 @@ static int set_mode_button(unsigned char *mode_data, const unsigned char button,
11481179

11491180
return 1;
11501181
}
1182+
11511183
static int mouse_editmode(void) {
1152-
if (!usb_dev_handle) return 0;
1184+
if (!mouse_primed || !usb_dev_handle) return 0;
11531185

11541186
// LAUNCH EDITOR
11551187
// 2117030035 S Co:2:039:0 s 21 09 03f0 0001 0004 4 = f0423900
@@ -1189,21 +1221,8 @@ static int mouse_editmode(void) {
11891221
return 1;
11901222
}
11911223

1192-
int main (int argc, char *argv[]) {
1193-
t_exit ret = exit_none;
1194-
int c;
1195-
1196-
t_mode mode = mode_COUNT;
1197-
1198-
// Data structures to store loaded and ready to save mode data
1199-
unsigned char mode_data_l[255];
1200-
unsigned char mode_data_s[255];
1201-
1202-
log_init();
1203-
1204-
help_version();
1205-
1206-
// FIXME: Help and version shouldn't initialise USB
1224+
int mouse_prime(void) {
1225+
if (mouse_primed) return exit_none;
12071226

12081227
// Initialise USB
12091228
usb_init();
@@ -1239,6 +1258,43 @@ int main (int argc, char *argv[]) {
12391258
return exit_usberr;
12401259
}
12411260

1261+
mouse_primed = 1;
1262+
1263+
return exit_none;
1264+
}
1265+
1266+
int mouse_unprime(void) {
1267+
if (!mouse_primed) return exit_none;
1268+
1269+
// Re-attach kernel driver
1270+
printf("Attaching kernel driver...\n");
1271+
mouse_hid_attach_kernel(usb_interface_index);
1272+
1273+
// De-initialise mouse
1274+
mouse_deinit();
1275+
1276+
// De-initialise USB
1277+
usb_deinit();
1278+
1279+
mouse_primed = 0;
1280+
1281+
return exit_none;
1282+
}
1283+
1284+
int main (int argc, char *argv[]) {
1285+
t_exit ret = exit_none;
1286+
int c;
1287+
1288+
t_mode mode = mode_COUNT;
1289+
1290+
// Data structures to store loaded and ready to save mode data
1291+
unsigned char mode_data_l[255];
1292+
unsigned char mode_data_s[255];
1293+
1294+
log_init();
1295+
1296+
help_version();
1297+
12421298
while (1) {
12431299
int option_index = 0;
12441300
static struct option long_options[] = {
@@ -1285,8 +1341,8 @@ int main (int argc, char *argv[]) {
12851341
c = getopt_long(argc, argv, "hVs:p:m:r:c:1:2:3:4:5:6:7:8:9:",
12861342
long_options, &option_index);
12871343

1288-
if (c == -1)
1289-
break;
1344+
// If we've had a previous error, or there's not more options, break
1345+
if (ret != exit_none || c == -1) break;
12901346

12911347
switch (c) {
12921348
// Help
@@ -1326,6 +1382,10 @@ int main (int argc, char *argv[]) {
13261382

13271383
printf("Mode Selection Specified: %s\n", s_mode[mnew]);
13281384

1385+
// Initialise USB and mouse, detach kernel driver (if necessary)
1386+
// If we cannot, abort (caught at start of loop)
1387+
if ((ret = mouse_prime())) continue;
1388+
13291389
if (mode != mode_COUNT) {
13301390
// They've been editing another mode, so save
13311391
printf("Saving Mode: %s\n", s_mode[mode]);
@@ -1360,6 +1420,10 @@ int main (int argc, char *argv[]) {
13601420
continue;
13611421
}
13621422

1423+
// Initialise USB and mouse, detach kernel driver (if necessary)
1424+
// If we cannot, abort (caught at start of loop)
1425+
if ((ret = mouse_prime())) continue;
1426+
13631427
if (mode != mode_COUNT) {
13641428
// They've been editing another mode, so save
13651429
printf("Saving Mode: %s\n", s_mode[mode]);
@@ -1369,8 +1433,9 @@ int main (int argc, char *argv[]) {
13691433

13701434
printf("Printing Mode: %s\n", s_mode[mnew]);
13711435

1372-
len = mode_load(&mode_data_p[0], usb_dev_handle, mnew);
1373-
mode_print(&mode_data_p[0], len);
1436+
if ((len = mode_load(&mode_data_p[0], usb_dev_handle, mnew)) > 0) {
1437+
mode_print(&mode_data_p[0], len);
1438+
}
13741439
}
13751440
break;
13761441

@@ -1379,6 +1444,10 @@ int main (int argc, char *argv[]) {
13791444
{
13801445
t_mode mnew = mode_COUNT;
13811446

1447+
// Initialise USB and mouse, detach kernel driver (if necessary)
1448+
// If we cannot, abort (caught at start of loop)
1449+
if ((ret = mouse_prime())) continue;
1450+
13821451
if (!optarg) {
13831452
elog("ERROR: Mode required for modify option\n");
13841453

@@ -1422,8 +1491,9 @@ int main (int argc, char *argv[]) {
14221491

14231492
mouse_editmode();
14241493

1425-
mode_load(&mode_data_l[0], usb_dev_handle, mode);
1426-
memcpy(&mode_data_s, &mode_data_l, 255);
1494+
if (mode_load(&mode_data_l[0], usb_dev_handle, mode) > 0) {
1495+
memcpy(&mode_data_s, &mode_data_l, 255);
1496+
}
14271497
}
14281498
break;
14291499

@@ -1523,7 +1593,7 @@ int main (int argc, char *argv[]) {
15231593
} // switch (c)
15241594
} // while (1)
15251595

1526-
if (optind < argc) {
1596+
if (ret == exit_none && optind < argc) {
15271597
char optout[255]
15281598
,*po = &optout[0];
15291599

@@ -1542,16 +1612,8 @@ int main (int argc, char *argv[]) {
15421612
mode = mode_COUNT;
15431613
}
15441614

1545-
1546-
// Re-attach kernel driver
1547-
printf("Attaching kernel driver...\n");
1548-
mouse_hid_attach_kernel(usb_interface_index);
1549-
1550-
// De-initialise mouse
1551-
mouse_deinit();
1552-
1553-
// De-initialise USB
1554-
usb_deinit();
1615+
// Re-attach kernel driver, de-initialise mouse and USB (if necessary)
1616+
mouse_unprime();
15551617

15561618
log_end();
15571619

0 commit comments

Comments
 (0)