assign button profiles
This commit is contained in:
parent
0e327a5f96
commit
a792bab2d7
|
@ -4,5 +4,7 @@ project(g35d)
|
|||
include_directories(include)
|
||||
link_directories(../libs)
|
||||
|
||||
set(CMAKE_C_FLAGS "-g -Wall")
|
||||
|
||||
add_executable(g35d g35d.c g35config.c)
|
||||
target_link_libraries(g35d g35 pthread confuse)
|
||||
|
|
47
g35config.c
47
g35config.c
|
@ -26,18 +26,20 @@
|
|||
|
||||
cfg_t *g35d_cfg = 0;
|
||||
|
||||
cfg_opt_t sec_opt_keymap[] = {
|
||||
CFG_INT("G1", KEY_NEXTSONG, CFGF_NONE),
|
||||
CFG_INT("G2", KEY_PLAYPAUSE, CFGF_NONE),
|
||||
CFG_INT("G3", KEY_PREVIOUS, CFGF_NONE),
|
||||
CFG_INT("VOL_DOWN", KEY_VOLUMEDOWN, CFGF_NONE),
|
||||
CFG_INT("VOL_UP", KEY_VOLUMEUP, CFGF_NONE),
|
||||
static cfg_opt_t sec_opt_keymap[] = {
|
||||
CFG_INT("G1", DEFAULT_G1_KEY, CFGF_NONE),
|
||||
CFG_INT("G2", DEFAULT_G2_KEY, CFGF_NONE),
|
||||
CFG_INT("G3", DEFAULT_G3_KEY, CFGF_NONE),
|
||||
CFG_INT("VOL_DOWN", DEFAULT_VOLDOWN_KEY, CFGF_NONE),
|
||||
CFG_INT("VOL_UP", DEFAULT_VOLUP_KEY, CFGF_NONE),
|
||||
CFG_END()
|
||||
};
|
||||
|
||||
cfg_opt_t opt_g35d[] = {
|
||||
CFG_BOOL("daemon", cfg_false, CFGF_NONE),
|
||||
CFG_STR("pidfile", "/var/run/g35d.pid", CFGF_NONE),
|
||||
CFG_BOOL("daemon", DEFAULT_DAEMON, CFGF_NONE),
|
||||
CFG_STR("pidfile", DEFAULT_PIDFILE, CFGF_NONE),
|
||||
CFG_STR("uinput", DEFAULT_UINPUT, CFGF_NONE),
|
||||
CFG_STR("profile", 0, CFGF_NODEFAULT),
|
||||
CFG_SEC("keymap", sec_opt_keymap, CFGF_MULTI | CFGF_TITLE),
|
||||
CFG_END()
|
||||
};
|
||||
|
@ -48,9 +50,36 @@ int read_config(const char *filename)
|
|||
int ret;
|
||||
|
||||
cfg_free(g35d_cfg);
|
||||
|
||||
|
||||
g35d_cfg = cfg_init(opt_g35d, CFGF_NOCASE);
|
||||
ret = cfg_parse(g35d_cfg, filename);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void read_keymap_profile(unsigned int *keymap, const char *profile)
|
||||
{
|
||||
cfg_t *keyprofile = NULL;
|
||||
int i;
|
||||
|
||||
if (profile) {
|
||||
for (i = 0; i < cfg_size(g35d_cfg, "keymap"); ++i) {
|
||||
keyprofile = cfg_getnsec(g35d_cfg, "keymap", i);
|
||||
if (keyprofile) {
|
||||
if (!strncmp(cfg_title(keyprofile), profile, 255)) {
|
||||
keymap[0] = cfg_getint(keyprofile, "G1");
|
||||
keymap[1] = cfg_getint(keyprofile, "G2");
|
||||
keymap[2] = cfg_getint(keyprofile, "G3");
|
||||
keymap[3] = cfg_getint(keyprofile, "VOL_DOWN");
|
||||
keymap[4] = cfg_getint(keyprofile, "VOL_UP");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void close_config()
|
||||
{
|
||||
cfg_free(g35d_cfg);
|
||||
}
|
||||
|
|
12
g35config.h
12
g35config.h
|
@ -20,8 +20,20 @@
|
|||
#ifndef _G35CONFIG_H_
|
||||
#define _G35CONFIG_H_
|
||||
|
||||
#define DEFAULT_DAEMON cfg_false
|
||||
#define DEFAULT_PIDFILE "/var/run/g35d.pid"
|
||||
#define DEFAULT_UINPUT "/dev/uinput"
|
||||
|
||||
#define DEFAULT_G1_KEY KEY_NEXTSONG
|
||||
#define DEFAULT_G2_KEY KEY_PLAYPAUSE
|
||||
#define DEFAULT_G3_KEY KEY_PREVIOUSSONG
|
||||
#define DEFAULT_VOLUP_KEY KEY_VOLUMEDOWN
|
||||
#define DEFAULT_VOLDOWN_KEY KEY_VOLUMEUP
|
||||
|
||||
extern cfg_t *g35d_cfg;
|
||||
|
||||
int read_config(const char *filename);
|
||||
void read_keymap_profile(unsigned int *keymap, const char *profile);
|
||||
void close_config();
|
||||
|
||||
#endif /* _G35CONFIG_H_ */
|
||||
|
|
47
g35d.c
47
g35d.c
|
@ -36,11 +36,13 @@
|
|||
|
||||
#define DAEMON_NAME "G35"
|
||||
|
||||
static char *config_filename = "../g35d.rc";
|
||||
static char *config_filename = "/etc/g35d.rc";
|
||||
|
||||
static int seenDaemonFlag = 0;
|
||||
static int doDaemon = 0;
|
||||
static char *pid_file = "/var/run/g35d.pid";
|
||||
static char *uinput_dev = "/dev/uinput";
|
||||
static char *pid_file = NULL;
|
||||
static char *uinput_dev = NULL;
|
||||
static char *profile_name = NULL;
|
||||
|
||||
pthread_t keypress_thread;
|
||||
|
||||
|
@ -52,6 +54,7 @@ static void exit_g35d(int exit_code)
|
|||
|
||||
g35_uinput_destroy();
|
||||
g35_destroy();
|
||||
close_config();
|
||||
|
||||
syslog(LOG_INFO, "daemon shuttdown");
|
||||
|
||||
|
@ -63,8 +66,13 @@ void signal_handler(int sig)
|
|||
{
|
||||
switch (sig) {
|
||||
case SIGHUP:
|
||||
syslog(LOG_INFO, "%s daemon reload configuration", DAEMON_NAME);
|
||||
read_config(config_filename);
|
||||
profile_name = cfg_getstr(g35d_cfg, "profile");
|
||||
read_keymap_profile(keymap, profile_name);
|
||||
g35_uinput_update_keymap(keymap);
|
||||
|
||||
syslog(LOG_INFO, "profiles reloaded");
|
||||
signal(SIGHUP, signal_handler);
|
||||
break;
|
||||
case SIGABRT:
|
||||
case SIGTERM:
|
||||
|
@ -131,14 +139,15 @@ int main(int argc, char **argv)
|
|||
int ret;
|
||||
|
||||
struct option longopts[] = {
|
||||
{"config", required_argument, 0, 'c'},
|
||||
{"daemon", no_argument , 0, 'd'},
|
||||
{"uinput", required_argument, 0, 'u'},
|
||||
{"config", required_argument, 0, 'c'},
|
||||
{"daemon", no_argument , 0, 'd'},
|
||||
{"profile", required_argument, 0, 'p'},
|
||||
{"uinput", required_argument, 0, 'u'},
|
||||
{0}
|
||||
};
|
||||
int longidx, opt;
|
||||
|
||||
while ((opt = getopt_long(argc, argv, "c:du:", longopts,
|
||||
while ((opt = getopt_long(argc, argv, "c:dp:u:", longopts,
|
||||
&longidx)) != -1) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
|
@ -146,6 +155,10 @@ int main(int argc, char **argv)
|
|||
break;
|
||||
case 'd':
|
||||
doDaemon = 1;
|
||||
seenDaemonFlag = 1;
|
||||
break;
|
||||
case 'p':
|
||||
profile_name = optarg;
|
||||
break;
|
||||
case 'u':
|
||||
uinput_dev = optarg;
|
||||
|
@ -156,7 +169,15 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
read_config(config_filename);
|
||||
ret = read_config(config_filename);
|
||||
if (!pid_file)
|
||||
pid_file = cfg_getstr(g35d_cfg, "pidfile");
|
||||
if (!seenDaemonFlag)
|
||||
doDaemon = cfg_getbool(g35d_cfg, "daemon") ? 1 : 0;
|
||||
if (!uinput_dev)
|
||||
uinput_dev = cfg_getstr(g35d_cfg, "uinput");
|
||||
if (!profile_name)
|
||||
profile_name = cfg_getstr(g35d_cfg, "profile");
|
||||
|
||||
setlogmask(LOG_UPTO(LOG_INFO));
|
||||
openlog(DAEMON_NAME, LOG_CONS, LOG_USER);
|
||||
|
@ -172,7 +193,6 @@ int main(int argc, char **argv)
|
|||
pid = daemonize();
|
||||
syslog(LOG_INFO, "daemon pid is %d", pid);
|
||||
}
|
||||
fprintf(stderr, "g35d pid %d\n", pid);
|
||||
|
||||
if (g35_init()) {
|
||||
syslog(LOG_ERR, "daemon failed to claim G35 HID interface");
|
||||
|
@ -180,14 +200,15 @@ int main(int argc, char **argv)
|
|||
}
|
||||
syslog(LOG_INFO, "successfully initilised libg35");
|
||||
|
||||
ret = g35_uinput_init(uinput_dev);
|
||||
if (ret < 0) {
|
||||
read_keymap_profile(keymap, profile_name);
|
||||
ret = g35_uinput_init(uinput_dev, keymap);
|
||||
|
||||
if (ret) {
|
||||
syslog(LOG_ERR, "failed to open uinput device `%s'", uinput_dev);
|
||||
exit_g35d(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (pthread_create(&keypress_thread, 0, keypress_event_thread, 0) != 0) {
|
||||
perror("pthread_create");
|
||||
syslog(LOG_ERR, "pthread_create failed");
|
||||
exit_g35d(EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* G35 Daemon for Linux
|
||||
* Copyright (C) 2012 Julian Knauer <jpk-at-goatpr0n.de>
|
||||
*
|
||||
* 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 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _G35_H_
|
||||
#define _G35_H_
|
||||
|
||||
static unsigned int keymap[G35_MAX_KEYS];
|
||||
|
||||
#endif /* _G35_H_ */
|
19
g35d.rc
19
g35d.rc
|
@ -1,19 +1,20 @@
|
|||
daemon = false
|
||||
pidfile = "/tmp/g35d.pid"
|
||||
uinput = "/dev/uinput"
|
||||
profile = "Profile1"
|
||||
|
||||
keymap Profile1 {
|
||||
G1 = 163
|
||||
G2 = 164
|
||||
G3 = 165
|
||||
VOL_DOWN = 114
|
||||
VOL_UP = 115
|
||||
}
|
||||
|
||||
keymap Profile2 {
|
||||
G1 = 59
|
||||
G2 = 60
|
||||
G3 = 61
|
||||
VOL_DOWN = 114
|
||||
VOL_UP = 115
|
||||
}
|
||||
|
||||
keymap Profile2 {
|
||||
G1 = 62
|
||||
G2 = 63
|
||||
G3 = 64
|
||||
VOL_DOWN = 114
|
||||
VOL_UP = 115
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue