diff --git a/src/jslisten.c b/src/jslisten.c
index c59057e..30ee1a3 100644
--- a/src/jslisten.c
+++ b/src/jslisten.c
@@ -3,7 +3,7 @@
*
* Created by Nikolai Rinas on 27.03.15.
* Copyright (c) 2015 Nikolai Rinas. All rights reserved.
- *
+ *
* 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, either version 3 of the License, or
@@ -13,8 +13,8 @@
* 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
+ *
+ * You should have received a copy of the GNU General Public License
* along with this program. If not, see
*/
@@ -66,7 +66,7 @@
char iniFile[INI_BUFFERSIZE];
char myDevPath[NAME_LENGTH];
int joyFD;
-struct KeySet{
+struct KeySet {
// Set Default unassigned
long button1;
int button1Active;
@@ -93,7 +93,7 @@ int logLevel = LOG_NOTICE;
int buttonDefined(int val) {
if ( val > BUTTON_DEFINED_RANGE ) {
return true;
- }else{
+ } else {
return false;
}
}
@@ -120,12 +120,12 @@ int getConfigFile() {
strncpy(iniFile, myGlConfFile, INI_BUFFERSIZE-1);
rc = 0;
syslog(LOG_INFO, "reading config %s\n", iniFile);
- }else{
+ } else {
// Write a default file to the home dir
FILE *f = fopen(iniFile, "w");
if (f == NULL) {
syslog(LOG_ERR, "err: failed write config file %s\n", myConfFile);
- }else{
+ } else {
const char *defaultConfig = "[Generic]\nprogram=\nbutton1=\nbutton2=\nbutton3=\nbutton4=\n";
fprintf(f, "%s\n", defaultConfig);
syslog(LOG_ERR, "err: no config found. Please maintain all required values in %s\n", iniFile);
@@ -153,40 +153,40 @@ void readConfig(void) {
n = ini_gets(section, str, "dummy", myKeys[numHotkeys].swFilename, sizearray(myKeys[numHotkeys].swFilename), iniFile);
if ( n > 5 && strncmp("dummy", myKeys[numHotkeys].swFilename, 5) != 0 ) { // Value is not empty
syslog(LOG_INFO, "Filename: %s\n", myKeys[numHotkeys].swFilename);
- }
- }
+ }
+ }
if ( strncmp("button1", str, 7) == 0 ) { // Key found
l = ini_getl(section, str, BUTTON_DEFINED_RANGE, iniFile);
if ( buttonDefined(l) == true ) { // Value is not empty
syslog(LOG_INFO, "button1: %ld\n", l);
myKeys[numHotkeys].button1 = l;
myKeys[numHotkeys].activeButtons++;
- }
- }
+ }
+ }
if ( strncmp("button2", str, 7) == 0 ) { // Key found
l = ini_getl(section, str, BUTTON_DEFINED_RANGE, iniFile);
if ( buttonDefined(l) == true ) { // Value is not empty
syslog(LOG_INFO, "button2: %ld\n", l);
myKeys[numHotkeys].button2 = l;
myKeys[numHotkeys].activeButtons++;
- }
- }
+ }
+ }
if ( strncmp("button3", str, 7) == 0 ) { // Key found
l = ini_getl(section, str, BUTTON_DEFINED_RANGE, iniFile);
if ( buttonDefined(l) == true ) { // Value is not empty
syslog(LOG_INFO, "button3: %ld\n", l);
myKeys[numHotkeys].button3 = l;
myKeys[numHotkeys].activeButtons++;
- }
- }
+ }
+ }
if ( strncmp("button4", str, 7) == 0 ) { // Key found
l = ini_getl(section, str, BUTTON_DEFINED_RANGE, iniFile);
- if ( buttonDefined(l) == true ){ // Value is not empty
+ if ( buttonDefined(l) == true ) { // Value is not empty
syslog(LOG_INFO, "button4: %ld\n", l);
myKeys[numHotkeys].button4 = l;
myKeys[numHotkeys].activeButtons++;
- }
- }
+ }
+ }
} /* for */
}
numHotkeys++; // Remember how many sections we have
@@ -199,19 +199,19 @@ void readConfig(void) {
int checkConfig(void) {
int rc=0;
int i;
- for (i=0;i 0 && FD_ISSET(fd, &fds)) {
syslog(LOG_DEBUG,"\nselect() says there should be data\n");
-
+
/* Make the call to receive the device.
select() ensured that this will not block. */
dev = udev_monitor_receive_device(mon);
@@ -383,37 +383,37 @@ void listenJoy (void) {
devices = udev_enumerate_get_list_entry(enumerate);
udev_list_entry_foreach(dev_list_entry, devices) {
- const char* name;
+ const char* name;
const char* sysPath;
const char* devPath;
-
+
name = udev_list_entry_get_name(dev_list_entry);
mydev = udev_device_new_from_syspath(udev, name);
sysPath = udev_device_get_syspath(mydev);
devPath = udev_device_get_devnode(mydev);
if (sysPath != NULL && devPath != NULL && strstr(sysPath, myDevPath) != 0) {
- syslog(LOG_NOTICE, "Found Device: %s\n", devPath);
+ syslog(LOG_NOTICE, "Found Device: %s\n", devPath);
if ((joyFD = open(devPath, O_RDONLY)) < 0) { // Open the file descriptor
syslog(LOG_INFO, "error: failed to open fd\n");
}
}
udev_device_unref(mydev);
- }
+ }
/* cleanup */
udev_enumerate_unref(enumerate);
- }else{
+ } else {
if ( strncmp(udev_device_get_action(dev), "remove", 6) == 0 ) { // Device remove
if ( joyFD >= 0 ) {
- close(joyFD);
+ close(joyFD);
}
- joyFD = -1; // Reset
+ joyFD = -1; // Reset
}
}
- }else{
+ } else {
syslog(LOG_WARNING, "No Device from receive_device(). An error occured.\n");
- }
+ }
udev_device_unref(dev);
}
usleep(250*1000);
@@ -427,15 +427,14 @@ void listenJoy (void) {
}
//---------------------------------------------
-// Listen on the input and call the program
+// Listen on the input and call the program
//---------------------------------------------
int bindJoy(void) {
char *axis_names[ABS_MAX + 1] = { "X", "Y", "Z", "Rx", "Ry", "Rz", "Throttle", "Rudder",
- "Wheel", "Gas", "Brake", "?", "?", "?", "?", "?",
- "Hat0X", "Hat0Y", "Hat1X", "Hat1Y", "Hat2X", "Hat2Y", "Hat3X", "Hat3Y",
- "?", "?", "?", "?", "?", "?", "?",
- };
+ "Wheel", "Gas", "Brake", "?", "?", "?", "?", "?",
+ "Hat0X", "Hat0Y", "Hat1X", "Hat1Y", "Hat2X", "Hat2Y", "Hat3X", "Hat3Y",
+ "?", "?", "?", "?", "?", "?", "?",};
char *button_names[KEY_MAX - BTN_MISC + 1] = {
"Btn0", "Btn1", "Btn2", "Btn3", "Btn4", "Btn5", "Btn6", "Btn7", "Btn8", "Btn9", "?", "?", "?", "?", "?", "?",
@@ -464,7 +463,7 @@ int bindJoy(void) {
getbtnmap(joyFD, btnmap);
syslog(LOG_INFO, "Driver version is %d.%d.%d.\n",
- version >> 16, (version >> 8) & 0xff, version & 0xff);
+ version >> 16, (version >> 8) & 0xff, version & 0xff);
/* Determine whether the button map is usable. */
for (i = 0; btnmapok && i < buttons; i++) {
@@ -500,7 +499,7 @@ int bindJoy(void) {
while (1) {
while (read(joyFD, &js, sizeof(struct js_event)) == sizeof(struct js_event)) {
syslog(LOG_DEBUG, "Event: type %d, time %d, number %d, value %d\n",
- js.type, js.time, js.number, js.value);
+ js.type, js.time, js.number, js.value);
needTrigger = checkButtonPressed(js);
if ( needTrigger > -1 ) { // We have found one key section
syslog(LOG_INFO, "Swtching mode. ...\n");
@@ -508,7 +507,7 @@ int bindJoy(void) {
int rc = system(myKeys[needTrigger].swFilename);
if ( rc == 0 ) {
syslog(LOG_INFO, "Call succesfull\n");
- }else{
+ } else {
syslog(LOG_INFO, "Call failed\n");
}
// reset state, so we call only once
@@ -530,13 +529,13 @@ int bindJoy(void) {
// Exit function
//---------------------------------------------
void signal_callback_handler(int signum) {
- syslog(LOG_NOTICE, "Exit. Caught signal %d\n",signum);
- // Cleanup and close up stuff here
+ syslog(LOG_NOTICE, "Exit. Caught signal %d\n",signum);
+ // Cleanup and close up stuff here
- closelog();
+ closelog();
- // Terminate program
- exit(0);
+ // Terminate program
+ exit(0);
}
@@ -554,7 +553,7 @@ int main(int argc, char* argv[]) {
// Init Defaults
int i;
- for (i=0;i 1 ) {
- for (int i=1;i 1 ) {
- for (int i=1;i i+1 ) {
- if ( strlen(argv[i+1]) < NAME_LENGTH ){
+ if ( strlen(argv[i+1]) < NAME_LENGTH ) {
strncpy(myDevPath, argv[i+1], NAME_LENGTH-1);
- syslog(LOG_NOTICE, "Using device path %s\n", myDevPath);
+ syslog(LOG_NOTICE, "Using device path %s\n", myDevPath);
}
- }else{
+ } else {
syslog(LOG_NOTICE, "Missing device path parameter. Using default %s\n", myDevPath);
- }
+ }
}
}
}
@@ -613,13 +612,13 @@ int main(int argc, char* argv[]) {
if ( rc > 0 ) {
return rc;
}
-
+
// If everything is set up, run ...
if ( rc == 0 ) {
// Main endless loop
while (1) {
listenJoy(); // Find our joystick
- if ( joyFD > 0 ) {
+ if ( joyFD > 0 ) {
bindJoy(); // If found, use it and listen to the keys
}
}