void init_lirc (void) { int flags; if ((lirc_fd = lirc_init ("audacious", 1)) == -1) { fprintf (stderr, _("%s: could not init LIRC support\n"), plugin_name); return; } if (lirc_readconfig (NULL, &config, NULL) == -1) { lirc_deinit (); fprintf (stderr, _("%s: could not read LIRC config file\n" "%s: please read the documentation of LIRC\n" "%s: how to create a proper config file\n"), plugin_name, plugin_name, plugin_name); return; } input_tag = g_io_add_watch (g_io_channel_unix_new (lirc_fd), G_IO_IN, lirc_input_callback, NULL); fcntl (lirc_fd, F_SETOWN, getpid ()); flags = fcntl (lirc_fd, F_GETFL, 0); if (flags != -1) { fcntl (lirc_fd, F_SETFL, flags | O_NONBLOCK); } fflush (stdout); }
int mp_input_lirc_init(void) { int lirc_sock; int mode; mp_msg(MSGT_LIRC, MSGL_V, "Setting up LIRC support...\n"); if((lirc_sock=lirc_init("mplayer",1))==-1){ mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCopenfailed); return -1; } mode = fcntl(lirc_sock, F_GETFL); if (mode < 0 || fcntl(lirc_sock, F_SETFL, mode | O_NONBLOCK) < 0) { mp_msg(MSGT_LIRC, MSGL_ERR, "setting non-blocking mode failed: %s\n", strerror(errno)); lirc_deinit(); return -1; } if(lirc_readconfig( lirc_configfile,&lirc_config,NULL )!=0 ){ mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCcfgerr, lirc_configfile == NULL ? "~/.lircrc" : lirc_configfile); lirc_deinit(); return -1; } return lirc_sock; }
void layout_image_lirc_init(LayoutWindow *lw) { gint flags; gboolean lirc_verbose = (get_debug_level() >= 2); lirc_fd = lirc_init(GQ_APPNAME_LC, lirc_verbose); if (lirc_fd == -1) { DEBUG_1("Initializing LIRC... failed"); return; } DEBUG_1("Initializing LIRC... OK"); if (lirc_readconfig(NULL, &config, NULL) == -1) { lirc_deinit(); g_fprintf(stderr, _("could not read LIRC config file\n" "please read the documentation of LIRC to \n" "know how to create a proper config file\n")); fflush(stderr); DEBUG_1("Failed to read LIRC config file"); return; } if (lirc_verbose) fflush(stderr); gio_chan = g_io_channel_unix_new(lirc_fd); input_tag = g_io_add_watch(gio_chan, G_IO_IN, lirc_input_callback, lw); fcntl(lirc_fd, F_SETOWN, getpid()); flags = fcntl(lirc_fd, F_GETFL, 0); if (flags != -1) fcntl(lirc_fd, F_SETFL, flags|O_NONBLOCK); }
int LircClient::Init(const QString &config_file, const QString &program, bool ignoreExtApp) { int fd; /* Connect the unix socket */ fd = lirc_init((char *)program.latin1(), 1); if (fd == -1) { VERBOSE(VB_IMPORTANT, QString("lirc_init failed for %1, see preceding messages") .arg(program)); return -1; } /* parse the config file */ if (lirc_readconfig((char *)config_file.latin1(), &lircConfig, NULL)) { VERBOSE(VB_IMPORTANT, QString("Failed to read lirc config %1 for %2") .arg(config_file).arg(program)); lirc_deinit(); return -1; } if (!ignoreExtApp) external_app = gContext->GetSetting("LircKeyPressedApp", ""); VERBOSE(VB_GENERAL, QString("lirc init success using configuration file: %1") .arg(config_file)); return 0; }
int mp_input_lirc_init(void) { int lirc_sock; int mode; mp_tmsg(MSGT_LIRC,MSGL_V,"Setting up LIRC support...\n"); if((lirc_sock=lirc_init("mpv",0))==-1){ mp_tmsg(MSGT_LIRC,MSGL_V,"Failed to open LIRC support. You will not be able to use your remote control.\n"); return -1; } mode = fcntl(lirc_sock, F_GETFL); if (mode < 0 || fcntl(lirc_sock, F_SETFL, mode | O_NONBLOCK) < 0) { mp_msg(MSGT_LIRC, MSGL_ERR, "setting non-blocking mode failed: %s\n", strerror(errno)); lirc_deinit(); return -1; } if(lirc_readconfig( lirc_configfile,&lirc_config,NULL )!=0 ){ mp_tmsg(MSGT_LIRC,MSGL_ERR,"Failed to read LIRC config file %s.\n", lirc_configfile == NULL ? "~/.lircrc" : lirc_configfile); lirc_deinit(); return -1; } return lirc_sock; }
void CLirc::Process() { m_profileId = CServiceBroker::GetProfileManager().GetCurrentProfileId(); m_irTranslator.Load("Lircmap.xml"); // make sure work-around (CheckDaemon) uses the same socket path as lirc_init const char* socket_path = getenv("LIRC_SOCKET_PATH"); socket_path = socket_path ? socket_path : "/var/run/lirc/lircd"; setenv("LIRC_SOCKET_PATH", socket_path, 0); while (!m_bStop) { { CSingleLock lock(m_critSection); // lirc_client is buggy because it does not close socket, if connect fails // work around by checking if daemon is running before calling lirc_init if (!CheckDaemon()) { CSingleExit lock(m_critSection); Sleep(1000); continue; } m_fd = lirc_init(const_cast<char*>("kodi"), 0); if (m_fd <= 0) { CSingleExit lock(m_critSection); Sleep(1000); continue; } } char *code; while (!m_bStop) { int ret = lirc_nextcode(&code); if (ret < 0) { lirc_deinit(); Sleep(1000); break; } if (code != nullptr) { if (m_profileId != CServiceBroker::GetProfileManager().GetCurrentProfileId()) { m_profileId = CServiceBroker::GetProfileManager().GetCurrentProfileId(); m_irTranslator.Load("Lircmap.xml"); } ProcessCode(code); free(code); } } } lirc_deinit(); }
int main (int argc, const char *argv[]) { int fd; struct lirc_config *config; char *code; if ((fd = lirc_init("lirc", 1)) == -1) { fprintf(stderr, "cannot init lirc\n"); exit(EXIT_FAILURE); } fprintf(stdout, "LIRC FD = %d\n", fd); fflush(stdout); #if 0 // XXX test non-block socket (for integration with tcdr) if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK) == -1) { fprintf(stderr, "cannot make socket as non block\n"); exit(EXIT_FAILURE); } #endif if (lirc_readconfig(NULL, &config, NULL) == 0) { while (lirc_nextcode(&code) == 0) { if (!code) continue; if (strstr(code, "KEY_MENU")) { fprintf(stdout, "MENU\n"); fflush(stdout); } else if (strstr(code, "KEY_PLAYPAUSE")) { fprintf(stdout, "PLAY\n"); fflush(stdout); } else if (strstr(code, "KEY_FORWARD")) { fprintf(stdout, "FWRD\n"); fflush(stdout); } else if (strstr(code, "KEY_REWIND")) { fprintf(stdout, "RWND\n"); fflush(stdout); } else if (strstr(code, "KEY_VOLUMEUP")) { fprintf(stdout, "VLUP\n"); fflush(stdout); } else if (strstr(code, "KEY_VOLUMEDOWN")) { fprintf(stdout, "VLDN\n"); fflush(stdout); } else { fprintf(stderr, "UNKN\n"); } free(code); } lirc_freeconfig(config); } lirc_deinit(); return 0; }
int pa__init(pa_module*m) { pa_modargs *ma = NULL; struct userdata *u; pa_volume_t volume_limit = PA_CLAMP_VOLUME(PA_VOLUME_NORM*3/2); pa_volume_t volume_step = PA_VOLUME_NORM/20; pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments"); goto fail; } if (pa_modargs_get_value_u32(ma, "volume_limit", &volume_limit) < 0) { pa_log("Failed to parse volume limit"); goto fail; } if (pa_modargs_get_value_u32(ma, "volume_step", &volume_step) < 0) { pa_log("Failed to parse volume step"); goto fail; } m->userdata = u = pa_xnew(struct userdata, 1); u->module = m; u->io = NULL; u->config = NULL; u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL)); u->lirc_fd = -1; u->mute_toggle_save = 0; u->volume_limit = PA_CLAMP_VOLUME(volume_limit); u->volume_step = PA_CLAMP_VOLUME(volume_step); if ((u->lirc_fd = lirc_init((char*) pa_modargs_get_value(ma, "appname", "pulseaudio"), 1)) < 0) { pa_log("lirc_init() failed."); goto fail; } if (lirc_readconfig((char*) pa_modargs_get_value(ma, "config", NULL), &u->config, NULL) < 0) { pa_log("lirc_readconfig() failed."); goto fail; } u->io = m->core->mainloop->io_new(m->core->mainloop, u->lirc_fd, PA_IO_EVENT_INPUT|PA_IO_EVENT_HANGUP, io_callback, u); pa_modargs_free(ma); return 0; fail: if (ma) pa_modargs_free(ma); pa__done(m); return -1; }
void lircStart(void) { if((g_lircfd = lirc_init("mupen64plus", 1)) != -1) { g_config = NULL; if(lirc_readconfig(NULL, &g_config, NULL) == 0) DebugMessage(M64MSG_INFO, "LIRC input system started successfully"); else DebugMessage(M64MSG_WARNING, "LIRC disabled: Error reading lircrc!"); } else DebugMessage(M64MSG_WARNING, "LIRC disabled: Error contacting daemon!"); }
static void *thread_func(void *arg) { struct lirc_config *config; int sock, flags; if ((sock = lirc_init("gmu", 1)) != -1) { fcntl(sock, F_SETOWN, getpid()); flags = fcntl(sock, F_GETFL, 0); if (flags != -1) fcntl(sock, F_SETFL, flags|O_NONBLOCK); if (lirc_readconfig(NULL, &config, NULL) == 0) { char *code, *c; int ret = 0; while (run && lirc_nextcode(&code) == 0) { if (code != NULL) { if ((ret = lirc_code2char(config, code, &c)) == 0 && c != NULL) { wdprintf(V_DEBUG, "lirc_frontend", "Got button press.\n"); if (strcmp(c, "play") == 0) gmu_core_play(); else if (strcmp(c, "pause") == 0) gmu_core_pause(); else if (strcmp(c, "stop") == 0) gmu_core_stop(); else if (strcmp(c, "toggle_pause") == 0) gmu_core_play_pause(); else if (strcmp(c, "toggle_play_pause") == 0) gmu_core_play_pause(); else if (strcmp(c, "next") == 0) gmu_core_next(); else if (strcmp(c, "prev") == 0) gmu_core_previous(); else if (strcmp(c, "volume_up") == 0) gmu_core_set_volume(gmu_core_get_volume()+1); else if (strcmp(c, "volume_down") == 0) gmu_core_set_volume(gmu_core_get_volume()-1); else wdprintf(V_WARNING, "lirc_frontend", "Unknown command: %s\n", c); c = NULL; } } usleep(400); free(code); if (ret == -1) break; } wdprintf(V_INFO, "lirc_frontend", "Exitting.\n"); lirc_freeconfig(config); } lirc_deinit(); } return NULL; }
/* Try to open a connection to lircd if suppor is enabled ** if it fails, disable support, print a message and continue */ void init_lirc(void) { if (using_lirc) { using_lirc = false; if ((lirc_fd = lirc_init("squeezeslave",1)) > 0) { if (lirc_readconfig(lircrc, &lircconfig, NULL)==0) { using_lirc = true; setNonblocking(lcd_fd); } else { using_lirc = true; close_lirc(); } } if (!using_lirc ) fprintf(stderr, "Failed to init LIRC\n"); } }
master_irda::master_irda(thread_data *my_data) { buttonTimer = millis(); buttonMENU = 0; my_data2 = my_data; //Initiate LIRC. Exit on failure if(lirc_init("lirc",1)==-1) exit(EXIT_FAILURE); std::cout << " jestem po uruchominiu lirc \n"; //// tu chyba sa glupoty zle }
static struct lirc_config * mex_lirc_init (const gchar *name) { int lirc_fd, res; gchar *tmp; lirc_fd = lirc_init ((char *)name, 1); if (lirc_fd == -1) g_warning (G_STRLOC ": LIRC initialisation failed"); else { struct lirc_config *config = NULL; /* Load the default config */ tmp = g_build_filename (mex_get_data_dir (), "mex-lircrc", NULL); res = lirc_readconfig (tmp, &config, NULL); g_free (tmp); if (res == 0) { int flags; GIOChannel *channel; /* Set non-blocking flag */ flags = fcntl (lirc_fd, F_GETFL); fcntl (lirc_fd, F_SETFL, flags | O_NONBLOCK); /* Create IOChannel to do non-blocking reads */ channel = g_io_channel_unix_new (lirc_fd); g_io_add_watch (channel, G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_NVAL | G_IO_HUP, (GIOFunc)mex_lirc_read_cb, config); return config; } else { g_warning (G_STRLOC ": Error reading LIRC config"); lirc_deinit (); } } return NULL; }
/***************************************************************************** * Open: initialize interface *****************************************************************************/ static int Open( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_sys_t *p_sys; /* Allocate instance and initialize some members */ p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) ); if( p_sys == NULL ) return VLC_ENOMEM; p_sys->i_fd = lirc_init( "vlc", 1 ); if( p_sys->i_fd == -1 ) { msg_Err( p_intf, "lirc initialisation failed" ); goto error; } /* We want polling */ fcntl( p_sys->i_fd, F_SETFL, fcntl( p_sys->i_fd, F_GETFL ) | O_NONBLOCK ); /* Read the configuration file */ char *psz_file = var_InheritString( p_intf, "lirc-file" ); int val = lirc_readconfig( psz_file, &p_sys->config, NULL ); free( psz_file ); if( val != 0 ) { msg_Err( p_intf, "failure while reading lirc config" ); lirc_deinit(); goto error; } if( vlc_clone( &p_sys->thread, Run, p_intf, VLC_THREAD_PRIORITY_LOW ) ) { lirc_freeconfig( p_sys->config ); lirc_deinit(); goto error; } return VLC_SUCCESS; error: free( p_sys ); return VLC_EGENERIC; }
void lircclient::init() { if (!_initialized) { int socket_flags; _socket = lirc_init(const_cast<char *>(_client_name.c_str()), msg::level() == msg::DBG ? 1 : 0); if (_socket == -1) { throw exc(_("Cannot initialize LIRC.")); } if ((socket_flags = fcntl(_socket, F_GETFL)) < 0 || fcntl(_socket, F_SETFL, socket_flags | O_NONBLOCK) < 0) { lirc_deinit(); throw exc(_("Cannot set LIRC socket properties.")); } if (_conf_files.size() == 0) { if (lirc_readconfig(NULL, &_config, NULL) != 0) { lirc_deinit(); throw exc(_("Cannot read LIRC default configuration.")); } } else { _config = NULL; for (size_t i = 0; i < _conf_files.size(); i++) { if (lirc_readconfig(const_cast<char *>(_conf_files[i].c_str()), &_config, NULL) != 0) { if (_config) { lirc_freeconfig(_config); } lirc_deinit(); throw exc(str::asprintf(_("Cannot read LIRC configuration file %s."), _conf_files[i].c_str())); } } } _initialized = true; } }
static void impl_activate (PeasActivatable *bplugin) { int fd; char *path; RBLircPlugin *plugin = RB_LIRC_PLUGIN (bplugin); RBShell *shell; g_object_get (plugin, "object", &shell, NULL); g_object_get (shell, "shell-player", &plugin->shell_player, NULL); rb_debug ("Activating lirc plugin"); fd = lirc_init ("Rhythmbox", 1); if (fd < 0) { rb_debug ("Couldn't initialize lirc"); g_object_unref (shell); return; } /* Load the default Rhythmbox setup */ path = rb_find_plugin_data_file (G_OBJECT (plugin), "rhythmbox_lirc_default"); if (path == NULL || lirc_readconfig (path, &plugin->lirc_config, NULL) == -1) { g_free (path); close (fd); rb_debug ("Couldn't read lirc configuration"); g_object_unref (shell); return; } g_free (path); lirc_readconfig (NULL, &plugin->lirc_config, NULL); plugin->lirc_channel = g_io_channel_unix_new (fd); g_io_channel_set_encoding (plugin->lirc_channel, NULL, NULL); g_io_channel_set_buffered (plugin->lirc_channel, FALSE); g_io_add_watch (plugin->lirc_channel, G_IO_IN | G_IO_ERR | G_IO_HUP, (GIOFunc) rb_lirc_plugin_read_code, plugin); g_object_unref (shell); }
static void module_init(Enna_Module *em) { struct lirc_config *config; int fd; if (!em) return; mod = calloc(1, sizeof(Enna_Module_Lirc)); if (!mod) return; mod->em = em; em->mod = mod; // initialize lirc if ((fd = lirc_init("enna", 1)) == -1) // TODO need to close this? or ecore_fd_hand_del is enoght? { enna_log(ENNA_MSG_ERROR, ENNA_MODULE_NAME, "could not initialize LIRC support"); return; } if (lirc_readconfig(NULL, &config, NULL) != 0) { lirc_deinit(); enna_log(ENNA_MSG_ERROR, ENNA_MODULE_NAME, "could not find Lirc config file"); return; } mod->lirc_config = config; // connect to the lirc socket fcntl(fd, F_SETFL, O_NONBLOCK); fcntl(fd, F_SETFD, FD_CLOEXEC); mod->fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, _lirc_code_received, NULL, NULL, NULL); #if 0 // register the configuration panel _config_panel = enna_config_panel_register(_("Remote"), "icon/music", lirc_panel_show, lirc_panel_hide, NULL); #endif }
/***************************************************************************** * Open: initialize interface *****************************************************************************/ static int Open( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_sys_t *p_sys; char *psz_file; /* Allocate instance and initialize some members */ p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) ); if( p_sys == NULL ) return VLC_ENOMEM; p_intf->pf_run = Run; p_sys->i_fd = lirc_init( "vlc", 1 ); if( p_sys->i_fd == -1 ) { msg_Err( p_intf, "lirc initialisation failed" ); goto exit; } /* We want polling */ fcntl( p_sys->i_fd, F_SETFL, fcntl( p_sys->i_fd, F_GETFL ) | O_NONBLOCK ); /* Read the configuration file */ psz_file = var_CreateGetNonEmptyString( p_intf, "lirc-file" ); if( lirc_readconfig( psz_file, &p_sys->config, NULL ) != 0 ) { msg_Err( p_intf, "failure while reading lirc config" ); free( psz_file ); goto exit; } free( psz_file ); return VLC_SUCCESS; exit: if( p_sys->i_fd != -1 ) lirc_deinit(); free( p_sys ); return VLC_EGENERIC; }
static gboolean impl_activate (TotemPlugin *plugin, TotemObject *totem, GError **error) { TotemLircPlugin *pi = TOTEM_LIRC_PLUGIN (plugin); char *path; int fd; pi->totem = g_object_ref (totem); fd = lirc_init ("Totem", 0); if (fd < 0) { g_set_error_literal (error, TOTEM_PLUGIN_ERROR, TOTEM_PLUGIN_ERROR_ACTIVATION, _("Couldn't initialize lirc.")); return FALSE; } /* Load the default Totem setup */ path = totem_plugin_find_file (plugin, "totem_lirc_default"); if (path == NULL || lirc_readconfig (path, &pi->lirc_config, NULL) == -1) { g_free (path); g_set_error_literal (error, TOTEM_PLUGIN_ERROR, TOTEM_PLUGIN_ERROR_ACTIVATION, _("Couldn't read lirc configuration.")); close (fd); return FALSE; } g_free (path); /* Load the user config, doesn't matter if it's not there */ lirc_readconfig (NULL, &pi->lirc_config, NULL); pi->lirc_channel = g_io_channel_unix_new (fd); g_io_channel_set_encoding (pi->lirc_channel, NULL, NULL); g_io_channel_set_buffered (pi->lirc_channel, FALSE); g_io_add_watch (pi->lirc_channel, G_IO_IN | G_IO_ERR | G_IO_HUP, (GIOFunc) totem_lirc_read_code, pi); return TRUE; }
int main(int argc, char **argv) { int retcode; /** Init **/ if (lirc_init("lircE161",1)==-1) exit(EXIT_FAILURE); /* Init lirc_client */ if (lirc_readconfig( lirc_configfile, &lirc_config, NULL) !=0 ){ lirc_deinit(); return EXIT_FAILURE; } /* Get the command to run on command_buf */ strcpy(command_buf, getcommand(lirc_config)); /* build up the arguments in arf_buf at every key press */ while(1){ retcode = getnextlircinput(); if (retcode == LIRCE161_ERROR) goto out; if (retcode == LIRCE161_DONE) /* done, let get out and run */ break; } /* Put the command together */ sprintf(composite_buf, (const char *)command_buf, arg_buf); #ifdef DEBUG printf("Command is %s\n", command_buf); printf("Arguments are %s\n", arg_buf); printf("Composite Command is %s\n", composite_buf); #endif system(composite_buf); /* finish up */ out: lirc_freeconfig(lirc_config); lirc_deinit(); return EXIT_SUCCESS; }
int lirc_fbi_init() { int fd; if (-1 == (fd = lirc_init("fbi",debug))) { if (debug) fprintf(stderr,"lirc: no infrared remote support available\n"); return -1; } if (0 != lirc_readconfig(NULL,&config,NULL)) { config = NULL; } if (debug) fprintf(stderr, "lirc: ~/.lircrc file %sfound\n", config ? "" : "not "); fcntl(fd,F_SETFL,O_NONBLOCK); fcntl(fd,F_SETFD,FD_CLOEXEC); if (debug) fprintf(stderr,"lirc: init ok\n"); return fd; }
/***************************************************************************** * Open: initialize interface *****************************************************************************/ static int Open( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; int i_fd; /* Allocate instance and initialize some members */ p_intf->p_sys = malloc( sizeof( intf_sys_t ) ); if( p_intf->p_sys == NULL ) { msg_Err( p_intf, "out of memory" ); return 1; } p_intf->pf_run = Run; i_fd = lirc_init( "vlc", 1 ); if( i_fd == -1 ) { msg_Err( p_intf, "lirc_init failed" ); free( p_intf->p_sys ); return 1; } /* We want polling */ fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK ); if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 ) { msg_Err( p_intf, "lirc_readconfig failed" ); lirc_deinit(); free( p_intf->p_sys ); return 1; } p_intf->p_sys->p_input = NULL; return 0; }
static void save_list(GtkWidget *widget, GtkCList *clist) { int i; char *data[2]; GList *channellist = NULL; if (channels) { for(i=0;channels[i];i++) free(channels[i]); free(channels); } if (clist->rows) channels = (Channel**)malloc(sizeof(Channel*)*(clist->rows+1)); for (i=0;i<clist->rows;i++) { channels[i] = (Channel*)malloc(sizeof(Channel)); gtk_clist_get_text(clist, i, 0, &data[0]); gtk_clist_get_text(clist, i, 1, &data[1]); sprintf(channels[i]->name, data[0]); channels[i]->frequency = atoi(data[1]); } if (clist->rows) channels[clist->rows] = NULL; if (channels) { for (i=0;channels[i];i++) channellist = g_list_append(channellist, channels[i]->name); } if (channellist && channelcombo) { gtk_combo_set_popdown_strings (GTK_COMBO (channelcombo), channellist); } #ifdef HAVE_LIRC for (i=0;i<RC_NUM_KEYS;i++) remote_buttons[i] = g_strdup(gtk_entry_get_text(GTK_ENTRY(rc_entry[i]))); if (strcmp(lirc_dev, gtk_entry_get_text(GTK_ENTRY(lirc_device_entry)))) { lirc_dev = g_strdup(gtk_entry_get_text(GTK_ENTRY(lirc_device_entry))); lirc_init(); } #endif #ifdef OSS if (strcmp(mixer_dev, gtk_entry_get_text(GTK_ENTRY(mixer_device_entry)))) { mixer_dev = g_strdup(gtk_entry_get_text(GTK_ENTRY(mixer_device_entry))); sound_init(); } for (i=0;(uint)i<g_list_length(audio_src_list);i++) { if (!strcmp((char *)g_list_nth_data(audio_src_list, i), gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(audio_src_combo)->entry)))) { audio_src = i; } } #endif if (port != atoi(gtk_entry_get_text(GTK_ENTRY(v4lxv_port_entry)))) { port = atoi(gtk_entry_get_text(GTK_ENTRY(v4lxv_port_entry))); gtk_tvplug_set(tv, "port", port); } for (i=0;(uint)i<g_list_length(GTK_TVPLUG(tv)->encoding_list);i++) { if (!strcmp(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(v4lxv_encoding_combo)->entry)), (char *) g_list_nth_data(GTK_TVPLUG(tv)->encoding_list, i))) { gtk_tvplug_set(tv, "encoding", i); encoding_id = i; } } save_options(); }
/* This is our thread function. It is like main(), but for a thread*/ void *threadFunc(void *arg) { struct lirc_config *config; int buttonTimer = millis(); char *code; char *c; //Initiate LIRC. Exit on failure if(lirc_init("lirc",1)==-1) exit(EXIT_FAILURE); //Read the default LIRC config at /etc/lirc/lircd.conf This is the config for your remot$ if(lirc_readconfig(NULL,&config,NULL)==0) { //Do stuff while LIRC socket is open 0=open -1=closed. while(lirc_nextcode(&code)==0) { //If code = NULL, meaning nothing was returned from LIRC socket, //then skip lines below and start while loop again. if(code==NULL) continue; { if (millis() - buttonTimer > 400) { //Check to see if the string "KEY_#" appears anywhere within the string $ if(strstr (code,"KEY_F")) { printf("MATCH on KEY_F\n"); sLED(0,200,0,0); buttonTimer = millis(); } else if(strstr (code,"KEY_G")) { printf("MATCH on KEY_G\n"); MODE = 2; buttonTimer = millis(); } else if(strstr (code,"KEY_H")) { printf("MATCH on KEY_H\n"); MODE = 1; buttonTimer = millis(); } else if(strstr (code,"KEY_E")) { printf("MATCH on KEY_E\n"); sLED(0,0,100,0); buttonTimer = millis(); } else if(strstr (code,"KEY_A")) { printf("MATCH on KEY_A\n"); sLED(0,0,0,0); buttonTimer = millis(); } } } //Need to free up code before the next loop free(code); } //Frees the data structures associated with config. lirc_freeconfig(config); } //lirc_deinit() closes the connection to lircd and does some internal clean-up stuff. lirc_deinit(); //exit(EXIT_SUCCESS); return NULL; }
int main(int argc, char* argv[]) { char keyname[128]; int pointer_button, pointer_x, pointer_y; char windowname[64]; struct lirc_config* config; char* config_file = NULL; int c; unsigned int WindowID; while ((c = getopt_long(argc, argv, "dhV", long_options, NULL)) != EOF) { switch (c) { case 'd': bDaemon = 1; continue; case 'h': printf("Usage: %s [option]... [config file]\n" " -d --daemon fork and run in background\n" " -h --help display usage summary\n" " -V --version display version\n", prog); return EXIT_SUCCESS; case 'V': printf("%s %s\n", prog, VERSION); return EXIT_SUCCESS; case '?': fprintf(stderr, "unrecognized option: -%c\n", optopt); fprintf(stderr, "Try `%s --help' for more information.\n", prog); return EXIT_FAILURE; } } if (argc == optind + 1) { config_file = argv[optind]; } else if (argc > optind + 1) { fprintf(stderr, "%s: incorrect number of arguments.\n", prog); fprintf(stderr, "Try `%s --help' for more information.\n", prog); return EXIT_FAILURE; } dpy = XOpenDisplay(NULL); if (dpy == NULL) { fprintf(stderr, "Can't open DISPLAY.\n"); exit(1); } root = RootWindow(dpy, DefaultScreen(dpy)); // windows may get closed at wrong time. Override default error handler... XSetErrorHandler(errorHandler); if (lirc_init("irxevent", 1) == -1) exit(EXIT_FAILURE); if (lirc_readconfig(config_file, &config, check) == 0) { char* ir; char* c; int ret; if (bDaemon) { if (daemon(1, 0) < 0) { perror("Failed to run as daemon"); exit(EXIT_FAILURE); } } while (lirc_nextcode(&ir) == 0) { if (ir == NULL) continue; while ((ret = lirc_code2char(config, ir, &c)) == 0 && c != NULL) { log_debug("Received code: %s Sending:\n", ir); bInError = 0; // reset error state, want to see error msg *windowname = 0; if (2 == sscanf(c, "Key %s Focus WindowID %i", keyname, &WindowID) || 4 == sscanf(c, "Button %d %d %d Focus WindowID %i", &pointer_button, &pointer_x, &pointer_y, &WindowID) || 4 == sscanf(c, "xy_Key %d %d %s Focus WindowID %i", &pointer_x, &pointer_y, keyname, &WindowID) || 2 == sscanf(c, "Key %s Focus %s", keyname, windowname) || 4 == sscanf(c, "Button %d %d %d Focus %s", &pointer_button, &pointer_x, &pointer_y, windowname) || 4 == sscanf(c, "xy_Key %d %d %s Focus %s", &pointer_x, &pointer_y, keyname, windowname)) { log_debug("Focus\n"); /* focussed ? */ if (*windowname) { WindowID = find_window_focused(root, windowname); if (!WindowID) { log_debug("target window '%s' doesn't have focus\n", windowname); continue; } log_debug("focused: %s\n", windowname); } else { Window cur; int tmp; XGetInputFocus(dpy, &cur, &tmp); if (WindowID != cur) { log_debug("target window '0x%x' doesn't have focus\n", WindowID); continue; } log_debug("focused: 0x%x\n", WindowID); } } else if (2 == sscanf(c, "Key %s WindowID %i", keyname, &WindowID) || 4 == sscanf(c, "Button %d %d %d WindowID %i", &pointer_button, &pointer_x, &pointer_y, &WindowID) || 4 == sscanf(c, "xy_Key %d %d %s WindowID %i", &pointer_x, &pointer_y, keyname, &WindowID)) { log_debug("WindowID: 0x%x\n", WindowID); /* WindowID passed */ } else if (2 == sscanf(c, "Key %s %s", keyname, windowname) || 4 == sscanf(c, "Button %d %d %d %s", &pointer_button, &pointer_x, &pointer_y, windowname) || 4 == sscanf(c, "xy_Key %d %d %s %s\n", &pointer_x, &pointer_y, keyname, windowname)) { log_debug("name: %s\n", windowname); WindowID = find_window(root, windowname); if (WindowID == 0) { log_debug("target window '%s' not found\n", windowname); continue; } } switch (c[0]) { case 'K': // Key log_debug("keyname: %s \t WindowID: 0x%x\n", keyname, WindowID); log_debug("%s\n", c); sendkey(keyname, 1, 1, (Window)WindowID, 0); break; case 'B': // Button case 'x': // xy_Key subw = find_sub_window(root, windowname, &pointer_x, &pointer_y); if (subw) { if (WindowID == subw) subw = 0; log_debug("%s\n", c); switch (c[0]) { case 'B': /* FIXME: pointer_button potentially uninititalzed. */ sendbutton(pointer_button, pointer_x, pointer_y, WindowID, subw); break; case 'x': sendkey(keyname, pointer_x, pointer_y, WindowID, subw); break; } } break; } } free(ir); if (ret == -1) break; } lirc_freeconfig(config); } lirc_deinit(); exit(0); }
int main(int argc, char* argv[]) { int fd_io; int fd_cmd; const char* socketpath; char path[128]; int c; while ((c = getopt_long(argc, argv, "hl:p:t:v", opts, NULL)) != EOF) { switch (c) { case 'l': opt_lircrc = optarg; break; case 'p': opt_prog = optarg; break; case 't': opt_testdata = optarg; break; case 'h': puts(USAGE); return EXIT_SUCCESS; case 'v': printf("%s\n", "irtestcase " VERSION); return EXIT_SUCCESS; case '?': fprintf(stderr, "unrecognized option: -%c\n", optopt); fputs("Try `irtestcase --help'.\n", stderr); return EXIT_FAILURE; } } if (argc > optind + 1) { fputs("irtestcase: Too many arguments (max one).\n", stderr); fputs("Try `irtestcase --help'.\n", stderr); return EXIT_FAILURE; } if (strcmp(opt_prog, DEFAULT_PROG) != 0 && opt_lircrc == NULL) { fputs("--prog requires --lircrc/-l. Giving up.\n", stderr); return EXIT_FAILURE; } if (opt_lircrc != NULL && strcmp(opt_prog, DEFAULT_PROG) == 0) { fputs("--lircrc requires --prog/-p. Giving up.\n", stderr); return EXIT_FAILURE; } init_testdir(); fd_cmd = lirc_get_local_socket(NULL, 1); if (fd_cmd < 0) { fputs("Cannot open lircd socket.\n", stderr); exit(3); } set_devicelog(fd_cmd, DEVICE_LOG); if (opt_testdata != NULL) send_later(fd_cmd, opt_testdata); lirc_log_get_clientlog("irtestcase", path, sizeof(path)); lirc_log_set_file(path); lirc_log_open("irtestcase", 1, LIRC_NOTICE); socketpath = argc == optind + 1 ? argv[optind] : LIRCD; setenv("LIRC_SOCKET_PATH", socketpath, 0); fd_io = lirc_init(opt_prog, 1); if (fd_io < 0) { fputs("Cannot run lirc_init.\n", stderr); exit(3); } return irtestcase(fd_io, fd_cmd); }
//Main function int main(int argc, char* argv[]) { //LIRC Variables struct lirc_config *config; //HTTP Variables char *host = "10.0.0.2"; char *http_request_format = "POST /php/remote_control_api.php HTTP/1.1\n" "Host: 10.0.0.2\n" "Content-Type: application/x-www-form-urlencoded\n" "Content-Length: 10\n\n" "function=%s\n"; char http_request[MAX_HTTP_REQUEST_LEN]; char http_response[MAX_HTTP_RESPONSE_LEN]; //Socket Variables int sockfd, error; struct addrinfo hints, *addrinfo_list, *addrinfo; //Misc Variables int valid_key = 0; struct timeval tv; gettimeofday(&tv, NULL); time_t start_time = tv.tv_sec, end_time, time_delay; //Outputs usage and exits if given more than one file path in arguments if (argc>2) { fprintf(stderr, "Usage: %s <config file>\n", argv[0]); return -1; } //Initializes LIRC and exits if unsuccessful, called at start of execution if (lirc_init("lirc",1)==-1) { fprintf(stderr, "lirc_init: failed to initialize lirc\n"); return -1; } //Clears hints structure and set appropriately for call to getaddrinfo() memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; //Gets the linked list of possible addrinfo structures if (error = getaddrinfo(host, PORT, &hints, &addrinfo_list) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(error)); return -1; } //Iterate through linked list of possible addrinfo structures and attempts to create socket to connect to for (addrinfo = addrinfo_list; addrinfo != NULL; addrinfo = addrinfo->ai_next) { //Creates a socket if ((sockfd = socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol)) == -1) { continue; } //Connect to socket if (connect(sockfd, addrinfo->ai_addr, addrinfo->ai_addrlen) == -1) { close(sockfd); continue; } //Break out of loop if calls to socket() and connect() are both successful break; } //If none of the addrinfo structures in the linked list works, then exit program if (addrinfo == NULL) { fprintf(stderr, "failed to connect to %s\n", host); return -1; } fprintf(stdout, "connection to %s was successful\n\n", host); close(sockfd); //Read in configuration file from either argument or default path if (lirc_readconfig(argc==2 ? argv[1]:NULL, &config, NULL) == 0) { char *code; //Used to store the key code of the remote //Blocks the program until an IR signal is recieved from key press while (lirc_nextcode(&code)==0) { //Handle logic key press, if any if (code==NULL) continue; { gettimeofday(&tv, NULL); end_time = tv.tv_sec; printf("Starttime=%ld\tEndtime=%ld\n\n", start_time, end_time); if (end_time - start_time > DELAY) { //Clears request and response buffer memset(&http_request, 0, sizeof http_request); memset(&http_response, 0, sizeof http_response); if (strstr(code,"KEY_POWER")) { if ((valid_key = handle_key_power(http_request, http_request_format)) == -1) { return -1; } } else if (strstr(code,"KEY_STOP")) { if ((valid_key = handle_key_stop(http_request, http_request_format)) == -1) { return -1; } } else if (strstr(code,"KEY_PAUSE")) { if ((valid_key = handle_key_pause(http_request, http_request_format)) == -1) { return -1; } } else if (strstr(code,"KEY_PLAY")) { if ((valid_key = handle_key_play(http_request, http_request_format)) == -1) { return -1; } } else if (strstr(code,"KEY_REWIND")) { if ((valid_key = handle_key_rewind(http_request, http_request_format)) == -1) { return -1; } } else if (strstr(code,"KEY_FORWARD")) { if ((valid_key = handle_key_forward(http_request, http_request_format)) == -1) { return -1; } } if (valid_key) { //Creates socket if ((sockfd = socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol)) == -1) { return -1; } //Connect to socket if (connect(sockfd, addrinfo->ai_addr, addrinfo->ai_addrlen) == -1) { close(sockfd); return -1; } if (send_http_request(sockfd, http_request) == -1) { fprintf(stderr, "An error has occur while sending the HTTP request\n"); } else { fprintf(stdout, "HTTP request has been sent successfully.\n" "--------------------------------------------------\n" "%s\n\n", http_request); } if (receive_http_response(sockfd, http_response) == -1) { fprintf(stderr, "An error has occur while receiving the HTTP response\n"); } else { fprintf(stdout, "HTTP response has been received successfully.\n" "--------------------------------------------------\n" "%s\n\n", http_response); } close(sockfd); } gettimeofday(&tv, NULL); start_time = tv.tv_sec; } } free(code); //Free allocated memory for code after key press is handled } lirc_freeconfig(config); //Free allocated memory for configuration structure } //Deallocate memory from linked list of addrinfo structures freeaddrinfo(addrinfo_list); lirc_deinit(); //Deinitializes LIRC, called at end of program execution return 0; //EXIT_SUCCESS } //end of main()
int main(int argc, char *argv[]) { int p=0, w=0, h=0, x=-1000000, y=-1000000; //GdkGeometry geom; channels = NULL; current_channel = -1; previous_channel = -1; lirc_dev = NULL; channelcombo = NULL; gtk_init(&argc, &argv); if (!parse_command_line_options(&argc, &argv, &p, &w, &h, &x, &y)) return 1; load_options(w?NULL:&w, h?NULL:&h, x!=-1000000?NULL:&x, y!=-1000000?NULL:&y); if (p) port = p; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (delete_event), NULL); gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (destroy), NULL); gtk_window_set_policy(GTK_WINDOW(window), 1, 1, 0); gtk_window_set_title (GTK_WINDOW (window), "Linux Video Studio TV"); gtk_container_set_border_width (GTK_CONTAINER (window), 0); tv = gtk_tvplug_new(port); if (!tv) { g_print("ERROR: no suitable video4linux device found\n"); g_print("Please supply a video4linux Xv-port manually (\'stv -p <num>\')\n"); return 1; } if (channels) { int i; for(i=0;channels[i];i++) if (channels[i]->frequency == (int)GTK_TVPLUG(tv)->frequency_adj->value) { current_channel = i; break; } } if (!port) port = GTK_TVPLUG(tv)->port; GTK_WIDGET_SET_FLAGS(tv, GTK_CAN_FOCUS); /* key press events */ gtk_container_add (GTK_CONTAINER (window), tv); gtk_widget_show(tv); set_background_color(tv, 0, 0, 0); gtk_signal_connect(GTK_OBJECT(tv), "button_press_event", GTK_SIGNAL_FUNC(tv_clicked), NULL); gtk_signal_connect(GTK_OBJECT(window), "key_press_event", GTK_SIGNAL_FUNC(tv_typed), NULL); gtk_signal_connect(GTK_OBJECT(window), "focus_in_event", GTK_SIGNAL_FUNC(focus_in_event), NULL); gtk_signal_connect(GTK_OBJECT(window), "focus_out_event", GTK_SIGNAL_FUNC(focus_out_event), NULL); set_background_color(window, 0, 0, 0); input_init(); #if 0 geom.min_width = GTK_TVPLUG(tv)->width_best/16; geom.min_height = GTK_TVPLUG(tv)->height_best/16; geom.max_width = GTK_TVPLUG(tv)->width_best; geom.max_height = GTK_TVPLUG(tv)->height_best; geom.width_inc = GTK_TVPLUG(tv)->width_best/16; geom.height_inc = GTK_TVPLUG(tv)->height_best/16; geom.min_aspect = GTK_TVPLUG(tv)->height_best / GTK_TVPLUG(tv)->width_best - 0.05; geom.max_aspect = GTK_TVPLUG(tv)->height_best / GTK_TVPLUG(tv)->width_best + 0.05; gtk_window_set_geometry_hints(GTK_WINDOW(window), window, &geom, GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_ASPECT | GDK_HINT_RESIZE_INC); if (w>0 && h>0) gtk_widget_set_usize(window, w, h); if (x!=-1000000 && y!=-1000000) gtk_widget_set_uposition(window, x, y); #endif #ifdef HAVE_LIRC lirc_init(); #endif #ifdef OSS sound_init(); #endif gtk_widget_show(window); gtk_main(); return 0; }
int main(int argc, char* argv[]) { int fdm, c, ignoreeof, interactive, noecho, verbose; pid_t pid; char* config; char slave_name[20]; struct termios orig_termios; struct winsize size; int flags; interactive = isatty(STDIN_FILENO); ignoreeof = 0; noecho = 0; verbose = 0; config = NULL; while ((c = getopt_long(argc, argv, "hVs:einv", long_options, NULL)) != EOF) { switch (c) { case 'h': printf("Usage: %s [options] config_file -- program [args ...]\n", argv[0]); printf("\t -h --help \t\tdisplay usage summary\n"); printf("\t -V --version \t\tdisplay version\n"); printf("\t -e --no-echo \t\tdisable echo\n"); printf("\t -i --ignore-eof \tignore EOF\n"); printf("\t -n --non-interactive \tforce non-interactive mode\n"); printf("\t -v --verbose \t\tverbose mode\n"); return EXIT_SUCCESS; case 'V': printf("irpty %s\n", VERSION); return EXIT_SUCCESS; case 'e': noecho = 1; break; case 'i': ignoreeof = 1; break; case 'n': interactive = 0; break; case 'v': verbose = 1; break; case '?': die("unrecognized option: -%c\n", optopt); } } if (optind + 1 >= argc) die("usage: irpty [ -s server -einv ] cfg program [ arg ... ]\n"); config = argv[optind++]; if ((lsock = lirc_init("irpty", 1)) == -1) exit(EXIT_FAILURE); flags = fcntl(lsock, F_GETFL, 0); if (flags != -1) fcntl(lsock, F_SETFL, flags | FASYNC | O_NONBLOCK); if (lirc_readconfig(config, &lconfig, NULL) != 0) exit(EXIT_FAILURE); if (interactive) { if (tcgetattr(STDIN_FILENO, &orig_termios) < 0) die("tcgetattr error on stdin\n"); if (ioctl(STDIN_FILENO, TIOCGWINSZ, (char*)&size) < 0) die("TIOCGWINSZ error\n"); pid = pty_fork(&fdm, slave_name, &orig_termios, &size); } else { pid = pty_fork(&fdm, slave_name, NULL, NULL); } if (pid < 0) { die("fork error\n"); } else if (!pid) { /* child */ if (noecho) set_noecho(STDIN_FILENO); /* stdin is slave pty */ if (execvp(argv[optind], &argv[optind]) < 0) die("can't execute: %s\n", argv[optind]); } if (verbose) { fprintf(stderr, "slave name = %s\n", slave_name); if (config) fprintf(stderr, "config file = %s\n", config); } if (interactive) { if (tty_raw(STDIN_FILENO) < 0) /* user's tty to raw mode */ die("tty_raw error"); if (atexit(tty_atexit) < 0) /* reset user's tty on exit */ die("atexit error"); } copy_loop(fdm, ignoreeof); exit(0); }
int main(int argc, char *argv[]) { struct lirc_config *config; int daemonize=0; progname="irexec-" VERSION; while(1) { int c; static struct option long_options[] = { {"help",no_argument,NULL,'h'}, {"version",no_argument,NULL,'v'}, #ifdef DAEMONIZE {"daemon",no_argument,NULL,'d'}, #endif {0, 0, 0, 0} }; c = getopt_long(argc,argv,"hvd",long_options,NULL); if(c==-1) break; switch (c) { case 'h': printf("Usage: %s [options] [config_file]\n",argv[0]); printf("\t -h --help\t\tdisplay this message\n"); printf("\t -v --version\t\tdisplay version\n"); #ifdef DAEMONIZE printf("\t -d --daemon\t\trun in background\n"); #endif return(EXIT_SUCCESS); case 'v': printf("%s\n",progname); return(EXIT_SUCCESS); #ifdef DAEMONIZE case 'd': daemonize=1; break; #endif default: printf("Usage: %s [options] [config_file]\n",argv[0]); return(EXIT_FAILURE); } } if (optind < argc-1) { fprintf(stderr,"%s: too many arguments\n",progname); return(EXIT_FAILURE); } if(lirc_init("irexec",daemonize ? 0:1)==-1) exit(EXIT_FAILURE); if(lirc_readconfig(optind!=argc ? argv[optind]:NULL,&config,NULL)==0) { char *code; char *c; int ret; #ifdef DAEMONIZE if(daemonize) { if(daemon(0,0)==-1) { fprintf(stderr,"%s: can't daemonize\n", progname); perror(progname); lirc_freeconfig(config); lirc_deinit(); exit(EXIT_FAILURE); } } #endif while(lirc_nextcode(&code)==0) { if(code==NULL) continue; while((ret=lirc_code2char(config,code,&c))==0 && c!=NULL) { #if defined(DAEMONIZE) && defined(DEBUG) if(!daemonize) { printf("Execing command \"%s\"\n",c); } #endif system(c); } free(code); if(ret==-1) break; } lirc_freeconfig(config); } lirc_deinit(); exit(EXIT_SUCCESS); }