Skip to content

Commit

Permalink
Linux/Shared: Compiles on Raspbian bullseye, fixes issue #4. Some GCC…
Browse files Browse the repository at this point in the history
… versions don't like defining variables inside switch blocks it turns out.
  • Loading branch information
Aviancer committed Mar 31, 2022
1 parent 47fe348 commit 52ecf39
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
10 changes: 4 additions & 6 deletions linux/src/amouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void showhelp(char *argv[]) {
"Usage: %s -m <mouse_input> -s <serial_output>\n\n" \
" -m <File> to read mouse input from (/dev/input/*)\n" \
" -s <File> to write to serial port with (/dev/tty*)\n" \
" -p <Proto> Select from available serial protocols (\'-p ?\' for list)\n" \
" -p <Proto num> Select from available serial protocols (\'-p ?\' for list)\n" \
" -e Disable exclusive access to mouse\n" \
" -i Immediate ident mode, disables waiting for CTS pin\n" \
" -l Swap left and right buttons\n" \
Expand All @@ -64,6 +64,7 @@ void showhelp(char *argv[]) {
void parse_opts(int argc, char **argv, struct linux_opts *options) {
int option_index = 0;
int quit = 0;
scan_int_t scan_i;

// Defaults
mouse_options.wheel = 1;
Expand All @@ -85,16 +86,13 @@ void parse_opts(int argc, char **argv, struct linux_opts *options) {
options->serialpath = strndup(optarg, 4096);
break;
case 'p':
scan_int_t scan_i;
uint num_protocols = sizeof mouse_protocol / sizeof mouse_protocol[0];

scan_i = scan_int((uint8_t*)optarg, 0, 2, 1); // Note: 0-9 only.
if(scan_i.found && scan_i.value < num_protocols) {
if(scan_i.found && scan_i.value < mouse_protocol_num) {
mouse_options.protocol = scan_i.value;
}
else {
fprintf(stderr, "Available mouse protocols\n");
for(int i=0; i < num_protocols; i++) {
for(int i=0; i < mouse_protocol_num; i++) { // < is 0-indexed
fprintf(stderr, " %i: %s\n", i, mouse_protocol[i].name);
}
exit(1);
Expand Down
2 changes: 1 addition & 1 deletion shared/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mouse_proto_t mouse_protocol[3] =
{"Logitech", "M3", 2, 3, false, 3}, // LOGITECH = 1, report is 3-4
{"MS wheeled", "MZ", 2, 3, true, 4} // MS_WHEELED = 2
};

uint mouse_protocol_num = sizeof mouse_protocol / sizeof mouse_protocol[0];

// Full Serial Mouse intro with PnP information (Microsoft IntelliMouse)
uint8_t pkt_intellimouse_intro[] = {0x4D,0x5A,0x40,0x00,0x00,0x00,0x08,0x01,0x24,0x2d,0x33,0x28,0x10,0x10,0x10,0x11,
Expand Down
1 change: 1 addition & 0 deletions shared/mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ typedef struct mouse_proto {
} mouse_proto_t;

extern mouse_proto_t mouse_protocol[3]; // Global options
extern uint mouse_protocol_num;

enum MOUSE_PROTOCOLS {
PROTO_MS2BUTTON = 0, // 2 buttons, 3 bytes
Expand Down

0 comments on commit 52ecf39

Please sign in to comment.