[go: up one dir, main page]

Menu

[ac6419]: / config.c  Maximize  Restore  History

Download this file

156 lines (136 with data), 4.5 kB

  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
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "config.h"
#include "mapper.h"
char *current_config[CONFIG_MAX] = {
/* UINPUT_DEV */
"/dev/uinput",
/* EVENT_DEV */
"/dev/input/event",
NULL,
};
struct parameter {
char *name;
int has_value;
void (*handler)(void);
char *help;
};
void set_8bit_calibration(void) {
set_scale_factor(1, 256, 0);
}
void set_dynamic_calibration(void) {
set_dynamic_calibrate(1);
}
void set_background(void) {
set_daemonize(1);
}
void set_input_calibration(void) {
set_event_input_calibrate(1);
}
void kill_daemon(void) {
kill_running_joymap();
exit(0);
}
void skip_unused_axes(void) {
set_skip_unused();
}
void set_nolock(void) {
set_nograb();
}
void show_help(void);
struct parameter cmdline_arg[CONFIG_MAX] = {
/* UINPUT_DEV */
{"--uinput_dev", 1, NULL, "The location of the user input device (/dev/uinput)"},
/* EVENT_DEV */
{"--event_dev", 1, NULL, "The location of the event devices (/dev/input/event)"},
{"-s", 0, skip_unused_axes, "Don't register unused axes and buttons"},
{"--skip", 0, skip_unused_axes, "Don't register unused axes and buttons"},
{"-c", 0, set_input_calibration, "Use the information from the input event devices to calibrate axes to the range -32767 to 32767"},
{"-d", 0, set_dynamic_calibration, "Runtime recalibrate the output of virtual joysticks using the output values"},
{"--dynamic", 0, set_dynamic_calibration, "Runtime recalibrate the output of virtual joysticks using the output values"},
{"-8", 0, set_8bit_calibration, "Calibrate axes output to the range -127 to 127"},
{"-k", 0, kill_daemon, "Terminate any running loadmap processes and quit"},
{"--kill", 0, kill_daemon, "Terminate any running loadmap processes and quit"},
{"-b", 0, set_background, "After loading the config, run loadmap in the background"},
{"--background", 0, set_background, "After loading the config, run loadmap in the background"},
{"--daemon", 0, set_background, "After loading the config, run loadmap in the background"},
{"--nolock", 0, set_nolock, "Don't lock devices for joymap use"},
{"--ffconst", 0, set_fake_ff_constant, "Pretend to have force feedback constant, map it to periodic"},
{"-h", 0, show_help, "Show this help"},
{"--help", 0, show_help, "Show this help"},
{NULL, 0, NULL, NULL}
};
static char *pad(int len, int maxlen) {
static char padding[256];
int i;
for (i=0; i<maxlen-len; i++) {
padding[i] = ' ';
}
padding[maxlen-len] = '\0';
return padding;
}
void show_help(void) {
int i;
int len;
int maxlen = 0;
maxlen = strlen("filename.map");
i = 0;
while (cmdline_arg[i].name != NULL) {
len = strlen(cmdline_arg[i].name);
if (maxlen < len) maxlen = len;
i++;
}
printf("Usage: loadmap [options] filename.map\n");
len = strlen("filename.map");
printf(" filename.map %s The name of the map file to load\n", pad(len, maxlen));
i = 0;
while (cmdline_arg[i].name != NULL) {
len = strlen(cmdline_arg[i].name);
printf(" %s %s %s\n", cmdline_arg[i].name, pad(len, maxlen), cmdline_arg[i].help);
i++;
}
exit(0);
}
char *get_config(int key) {
if ((key >= CONFIG_MAX) || (key < 0)) {
fprintf(stderr, "ERR: Invalid config key in code: %d\n", key);
exit(1);
}
return current_config[key];
}
char *set_config(int key, char *value) {
char *old;
if ((key >= CONFIG_MAX) || (key < 0)) {
fprintf(stderr, "ERR: Invalid config key in code: %d\n", key);
exit(1);
}
old = current_config[key];
current_config[key] = value;
return old;
}
int match_config(char *arg) {
int i=0;
while (cmdline_arg[i].name != NULL) {
if (strcmp(cmdline_arg[i].name, arg) == 0)
return i;
i++;
}
return -1;
}
void cmdline_config(int argc, char *argv[]) {
int i, index;
for (i=0; i<argc; i++) {
index = match_config(argv[i]);
if (index >= 0) {
if (cmdline_arg[index].has_value) {
if (i + 1 >= argc) {
fprintf(stderr, "Missing argument for: %s\n", argv[i]);
}
current_config[index] = argv[++i];
} else {
cmdline_arg[index].handler();
}
}
}
}