ssize_t settings_read_by_name(const char *name_p, void *dst_p, size_t size) { ASSERTN(name_p != NULL, EINVAL); ASSERTN(dst_p != NULL, EINVAL); ASSERTN(size > 0, EINVAL); const FAR struct setting_t *setting_p; /* Find the setting in the settings array. */ setting_p = &settings[0]; while (setting_p->name_p != NULL) { if (std_strcmp(name_p, setting_p->name_p) == 0) { if (size > setting_p->size) { return (-1); } return (settings_read(dst_p, setting_p->address, size)); } setting_p++; } return (-1); }
int main(int argc, char *argv[]) { if(argc > 1 && strcmp(argv[1], "-v") == 0) { puts("mmkeyosd "VERSION); exit(0); } if(chdir(getenv("HOME")) == -1) die("chdir: %s\n", strerror(errno)); config = config_read(".mmkeyosd/keys"); settings = settings_read(".mmkeyosd/settings"); fontstrbig = settings_find_str( settings, "fontbig", "Dejavu Sans-15"); fontstrsmall = settings_find_str( settings, "fontsmall", "Dejavu Sans-10"); fgcolor = settings_find_str( settings, "fgcolor", "white"); bgcolor = settings_find_str( settings, "bgcolor", "black"); errcolor = settings_find_str( settings, "errcolor", "red"); bw = settings_find_int( settings, "borderwidth", 0); ww = settings_find_int( settings, "windowwidth", 300); wh = settings_find_int( settings, "windowheight", 150); barw = settings_find_int( settings, "barwidth", 150); barh = settings_find_int( settings, "barheight", 15); opacity = settings_find_double(settings, "opacity", 0.8); wtimeout = settings_find_int( settings, "windowtimeout", 2000); shell = settings_find_str( settings, "shell", "/bin/sh"); setup(); run(); return 0; }
void CBaseMonster::settings_load(LPCSTR section) { SMonsterSettings data; settings_read (pSettings, section, data); u32 crc = crc32(&data,sizeof(SMonsterSettings)); m_base_settings.create (crc,1,&data); }
void CBaseMonster::settings_overrides() { SMonsterSettings *data; data = *m_base_settings; if (spawn_ini() && spawn_ini()->section_exist("settings_overrides")) { settings_read (spawn_ini(),"settings_overrides", (*data)); } u32 crc = crc32(data,sizeof(SMonsterSettings)); m_current_settings.create (crc,1,data); }
void DialogMisc::changeEvent(QEvent *e) { QDialog::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: m_ui->retranslateUi(this); /* translation cause listbox to set to default * just re-read value again */ settings_read(); break; default: break; } }
/* init and read settings */ void settings_init() { if (gbl_settings) settings_free(); gbl_settings = malloc(sizeof(global_settings)); gbl_settings->last_sample_dir = strdup(getenv("HOME")); gbl_settings->last_bank_dir = strdup(getenv("HOME")); gbl_settings->filename = (char*) g_build_filename( g_get_user_config_dir(), g_get_prgname(), SETTINGS_BASENAME, NULL); gbl_settings->log_lines = DEFAULT_LOG_LINES; /* gbl_settings->abs_max_sample_size = DEFAULT_ABS_MAX_SAMPLE; gbl_settings->max_sample_size = DEFAULT_MAX_SAMPLE; */ settings_read((char*) gbl_settings->filename); }
int main(int argc, char **argv) { gc_attach(main_gc); /* Catch all exit signals for gc */ gc_catch(); log_shell_enable(); log_level_set(LOG_NOTICE); struct options_t *options = NULL; struct hardware_t *hardware = NULL; char *args = NULL; char *stmp = NULL; int duration = 0; int i = 0; int y = 0; int z = 0; steps_t state = CAPTURE; steps_t pState = WAIT; int recording = 1; int bit = 0; int raw[255] = {0}; int pRaw[255] = {0}; int code[255] = {0}; int onCode[255] = {0}; int offCode[255] = {0}; int allCode[255] = {0}; int unit1Code[255] = {0}; int unit2Code[255] = {0}; int unit3Code[255] = {0}; int binary[255] = {0}; int pBinary[255] = {0}; int onBinary[255] = {0}; int offBinary[255] = {0}; int allBinary[255] = {0}; int unit1Binary[255] = {0}; int unit2Binary[255] = {0}; int unit3Binary[255] = {0}; int loop = 1; unsigned short match = 0; int temp[75] = {-1}; int footer = 0; int pulse = 0; int onoff[75] = {-1}; int all[75] = {-1}; int unit[75] = {-1}; int rawLength = 0; int binaryLength = 0; memset(onoff, -1, 75); memset(unit, -1, 75); memset(all, -1, 75); memset(temp, -1, 75); settingsfile = malloc(strlen(SETTINGS_FILE)+1); strcpy(settingsfile, SETTINGS_FILE); progname = malloc(16); strcpy(progname, "pilight-learn"); options_add(&options, 'H', "help", no_value, 0, NULL); options_add(&options, 'V', "version", no_value, 0, NULL); options_add(&options, 'S', "settings", has_value, 0, NULL); while (1) { int c; c = options_parse(&options, argc, argv, 1, &args); if(c == -1 || c == -2) break; switch (c) { case 'H': printf("Usage: %s [options]\n", progname); printf("\t -H --help\t\tdisplay usage summary\n"); printf("\t -V --version\t\tdisplay version\n"); printf("\t -S --settings\t\tsettings file\n"); return (EXIT_SUCCESS); break; case 'V': printf("%s %s\n", progname, VERSION); return (EXIT_SUCCESS); break; case 'S': if(access(args, F_OK) != -1) { settingsfile = realloc(settingsfile, strlen(args)+1); strcpy(settingsfile, args); settings_set_file(args); } else { fprintf(stderr, "%s: the settings file %s does not exists\n", progname, args); return EXIT_FAILURE; } break; default: printf("Usage: %s [options]\n", progname); return (EXIT_FAILURE); break; } } options_delete(options); if(access(settingsfile, F_OK) != -1) { if(settings_read() != 0) { return EXIT_FAILURE; } } if(settings_find_string("hw-mode", &stmp) == 0) { hw_mode = stmp; } hardware_init(); struct hardwares_t *htmp = hardwares; match = 0; while(htmp) { if(strcmp(htmp->listener->id, hw_mode) == 0) { hardware = htmp->listener; match = 1; break; } htmp = htmp->next; } if(match == 1 && hardware->init) { hardware->init(); printf("Please make sure the daemon is not running when using this debugger.\n\n"); } if(match == 0 || !hardware->receive || strcmp(hw_mode, "none") == 0) { printf("The hw-mode \"%s\" isn't compatible with %s\n", hw_mode, progname); main_gc(); return EXIT_SUCCESS; } while(loop && match == 1 && hardware->receive) { switch(state) { case CAPTURE: printf("1. Please send and hold one of the OFF buttons."); break; case ON: /* Store the previous OFF button code */ for(i=0;i<binaryLength;i++) { offBinary[i] = binary[i]; } printf("2. Please send and hold the ON button for the same device\n"); printf(" as for which you send the previous OFF button."); break; case OFF: /* Store the previous ON button code */ for(i=0;i<binaryLength;i++) { onBinary[i] = binary[i]; } for(i=0;i<rawLength;i++) { onCode[i] = code[i]; } z=0; /* Compare the ON and OFF codes and save bit that are different */ for(i=0;i<binaryLength;i++) { if(offBinary[i] != onBinary[i]) { onoff[z++]=i; } } for(i=0;i<rawLength;i++) { offCode[i] = code[i]; } printf("3. Please send and hold (one of the) ALL buttons.\n"); printf(" If you're remote doesn't support turning ON or OFF\n"); printf(" all devices at once, press the same OFF button as in\n"); printf(" the beginning."); break; case ALL: z=0; memset(temp,-1,75); /* Store the ALL code */ for(i=0;i<binaryLength;i++) { allBinary[i] = binary[i]; if(allBinary[i] != onBinary[i]) { temp[z++] = i; } } for(i=0;i<rawLength;i++) { allCode[i] = code[i]; } /* Compare the ALL code to the ON and OFF code and store the differences */ y=0; for(i=0;i<binaryLength;i++) { if(allBinary[i] != offBinary[i]) { all[y++] = i; } } if((unsigned int)z < y) { for(i=0;i<z;i++) { all[z]=temp[z]; } } printf("4. Please send and hold the ON button with the lowest ID."); break; case UNIT1: /* Store the lowest unit code */ for(i=0;i<binaryLength;i++) { unit1Binary[i] = binary[i]; } for(i=0;i<rawLength;i++) { unit1Code[i] = code[i]; } printf("5. Please send and hold the ON button with the second to lowest ID."); break; case UNIT2: /* Store the second to lowest unit code */ for(i=0;i<binaryLength;i++) { unit2Binary[i] = binary[i]; } for(i=0;i<rawLength;i++) { unit2Code[i] = code[i]; } printf("6. Please send and hold the ON button with the highest ID."); break; case PROCESSUNIT: z=0; /* Store the highest unit code and compare the three codes. Store all bit that are different */ for(i=0;i<binaryLength;i++) { unit3Binary[i] = binary[i]; if((unit2Binary[i] != unit1Binary[i]) || (unit1Binary[i] != unit3Binary[i]) || (unit2Binary[i] != unit3Binary[i])) { unit[z++]=i; } } for(i=0;i<rawLength;i++) { unit3Code[i] = code[i]; } state=STOP; break; case WAIT: case STOP: default:; } fflush(stdout); if(state!=WAIT) pState=state; if(state==STOP) loop = 0; else state=WAIT; duration = hardware->receive(); /* If we are recording, keep recording until the next footer has been matched */ if(recording == 1) { if(bit < 255) { raw[bit++] = duration; } else { bit = 0; recording = 0; } } /* First try to catch code that seems to be a footer. If a real footer has been recognized, start using that as the new footer */ if((duration > 4440 && footer == 0) || ((footer-(footer*0.1)<duration) && (footer+(footer*0.1)>duration))) { recording = 1; pulse_length = duration/PULSE_DIV; /* Check if we are recording similar codes */ for(i=0;i<(bit-1);i++) { if(!(((pRaw[i]-(pRaw[i]*0.3)) < raw[i]) && ((pRaw[i]+(pRaw[i]*0.3)) > raw[i]))) { y=0; z=0; recording=0; } pRaw[i]=raw[i]; } y++; /* Continue if we have 2 matches */ if(y>2) { /* If we are certain we are recording similar codes. Save the raw code length */ if(footer>0) { if(rawLength == 0) rawLength=bit; } if(rawLength == 0 || rawLength == bit) { /* Try to catch the footer, and the low and high values */ for(i=0;i<bit;i++) { if((i+1)<bit && i > 2 && footer > 0) { if((raw[i]/pulse_length) >= 2) { pulse=raw[i]; } } if(duration > 5000 && duration < 100000) footer=raw[i]; } /* If we have gathered all data, stop with the loop */ if(footer > 0 && pulse > 0 && rawLength > 0) { /* Convert the raw code into binary code */ for(i=0;i<rawLength;i++) { if((unsigned int)raw[i] > (pulse-pulse_length)) { code[i]=1; } else { code[i]=0; } } for(i=2;i<rawLength; i+=4) { if(code[i+1] == 1) { binary[i/4]=1; } else { binary[i/4]=0; } } if(binaryLength == 0) binaryLength = (int)((float)i/4); /* Check if the subsequent binary code matches to check if the same button was still held */ if(binaryLength == (i/4)) { for(i=0;i<binaryLength;i++) { if(pBinary[i] != binary[i]) { z=1; } } /* If we are capturing a different button continue to the next step */ if(z==1 || state == CAPTURE) { switch(pState) { case CAPTURE: state=ON; break; case ON: state=OFF; break; case OFF: state=ALL; break; case ALL: state=UNIT1; break; case UNIT1: state=UNIT2; break; case UNIT2: state=PROCESSUNIT; break; case PROCESSUNIT: state=STOP; break; case WAIT: case STOP: default:; } printf(" Done.\n\n"); pState=WAIT; } } } } } bit=0; } /* Reset the button repeat counter */ if(z==1) { z=0; for(i=0;i<binaryLength;i++) { pBinary[i]=binary[i]; } } } rmDup(all, onoff); rmDup(unit, onoff); rmDup(all, unit); /* Print everything */ printf("--[RESULTS]--\n"); printf("\n"); printf("pulse:\t\t%d\n",normalize(pulse)); printf("rawlen:\t\t%d\n",rawLength); printf("binlen:\t\t%d\n",binaryLength); printf("plslen:\t\t%d\n",pulse_length); printf("\n"); printf("on-off bit(s):\t"); z=0; while(onoff[z] > -1) { printf("%d ",onoff[z++]); } printf("\n"); printf("all bit(s):\t"); z=0; while(all[z] > -1) { printf("%d ",all[z++]); } printf("\n"); printf("unit bit(s):\t"); z=0; while(unit[z] > -1) { printf("%d ",unit[z++]); } printf("\n\n"); printf("Raw code:\n"); for(i=0;i<rawLength;i++) { printf("%d ",normalize(raw[i])*pulse_length); } printf("\n"); printf("Raw simplified:\n"); printf("On:\t"); for(i=0;i<rawLength;i++) { printf("%d",onCode[i]); } printf("\n"); printf("Off:\t"); for(i=0;i<rawLength;i++) { printf("%d",offCode[i]); } printf("\n"); printf("All:\t"); for(i=0;i<rawLength;i++) { printf("%d",allCode[i]); } printf("\n"); printf("Unit 1:\t"); for(i=0;i<rawLength;i++) { printf("%d",unit1Code[i]); } printf("\n"); printf("Unit 2:\t"); for(i=0;i<rawLength;i++) { printf("%d",unit2Code[i]); } printf("\n"); printf("Unit 3:\t"); for(i=0;i<rawLength;i++) { printf("%d",unit3Code[i]); } printf("\n"); printf("Binary code:\n"); printf("On:\t"); for(i=0;i<binaryLength;i++) { printf("%d",onBinary[i]); } printf("\n"); printf("Off:\t"); for(i=0;i<binaryLength;i++) { printf("%d",offBinary[i]); } printf("\n"); printf("All:\t"); for(i=0;i<binaryLength;i++) { printf("%d",allBinary[i]); } printf("\n"); printf("Unit 1:\t"); for(i=0;i<binaryLength;i++) { printf("%d",unit1Binary[i]); } printf("\n"); printf("Unit 2:\t"); for(i=0;i<binaryLength;i++) { printf("%d",unit2Binary[i]); } printf("\n"); printf("Unit 3:\t"); for(i=0;i<binaryLength;i++) { printf("%d",unit3Binary[i]); } printf("\n"); return (EXIT_SUCCESS); }
void start_up() { // Check and create our 400PLUS folder status.folder_exists = check_create_folder(); // Recover persisting information persist_read(); // Read settings from file settings_read(); // If configured, start debug mode if (settings.debug_on_poweron) start_debug_mode(); // If configured, restore AEB if (settings.persist_aeb) send_to_intercom(IC_SET_AE_BKT, persist.aeb); // Enable IR remote // i'm not sure where to call this? perhaps this isn't the right place. if (settings.remote_enable) remote_on(); // Enable extended ISOs // Enable (hidden) CFn.8 for ISO H send_to_intercom(IC_SET_CF_EXTEND_ISO, 1); // Enable realtime ISO change send_to_intercom(IC_SET_REALTIME_ISO_0, 0); send_to_intercom(IC_SET_REALTIME_ISO_1, 0); // Set current language enqueue_action(lang_pack_init); // Read custom modes configuration from file enqueue_action(cmodes_read); // And optionally apply a custom mode enqueue_action(cmode_recall); // turn off the blue led after it was lighten by our hack_task_MainCtrl() eventproc_EdLedOff(); #ifdef MEMSPY debug_log("starting memspy task"); CreateTask("memspy", 0x1e, 0x1000, memspy_task, 0); #endif #if 0 debug_log("=== DUMPING DDD ==="); printf_DDD_log( (void*)(int)(0x00007604+0x38) ); debug_log("maindlg @ 0x%08X, handler @ 0x%08X", hMainDialog, hMainDialog->event_handler); debug_log("dumping"); long *addr = (long*) 0x7F0000; int file = FIO_OpenFile("A:/dump.bin", O_CREAT | O_WRONLY , 644); if (file != -1) { FIO_WriteFile(file, addr, 0xFFFF); FIO_CloseFile(file); beep(); } #endif }
int main(int argc, char **argv) { gc_attach(main_gc); /* Catch all exit signals for gc */ gc_catch(); log_shell_enable(); log_file_disable(); log_level_set(LOG_NOTICE); struct options_t *options = NULL; char *args = NULL; char *hwfile = NULL; pid_t pid = 0; if(!(settingsfile = malloc(strlen(SETTINGS_FILE)+1))) { logprintf(LOG_ERR, "out of memory"); exit(EXIT_FAILURE); } strcpy(settingsfile, SETTINGS_FILE); if(!(progname = malloc(12))) { logprintf(LOG_ERR, "out of memory"); exit(EXIT_FAILURE); } strcpy(progname, "pilight-raw"); options_add(&options, 'H', "help", OPTION_NO_VALUE, 0, JSON_NULL, NULL, NULL); options_add(&options, 'V', "version", OPTION_NO_VALUE, 0, JSON_NULL, NULL, NULL); options_add(&options, 'S', "settings", OPTION_HAS_VALUE, 0, JSON_NULL, NULL, NULL); while (1) { int c; c = options_parse(&options, argc, argv, 1, &args); if(c == -1) break; if(c == -2) c = 'H'; switch (c) { case 'H': printf("Usage: %s [options]\n", progname); printf("\t -H --help\t\tdisplay usage summary\n"); printf("\t -V --version\t\tdisplay version\n"); printf("\t -S --settings\t\tsettings file\n"); return (EXIT_SUCCESS); break; case 'V': printf("%s %s\n", progname, VERSION); return (EXIT_SUCCESS); break; case 'S': if(access(args, F_OK) != -1) { settingsfile = realloc(settingsfile, strlen(args)+1); if(!settingsfile) { logprintf(LOG_ERR, "out of memory"); exit(EXIT_FAILURE); } strcpy(settingsfile, args); settings_set_file(args); } else { fprintf(stderr, "%s: the settings file %s does not exists\n", progname, args); return EXIT_FAILURE; } break; default: printf("Usage: %s [options]\n", progname); return (EXIT_FAILURE); break; } } options_delete(options); char pilight_daemon[] = "pilight-daemon"; char pilight_learn[] = "pilight-learn"; char pilight_debug[] = "pilight-debug"; if((pid = findproc(pilight_daemon, NULL)) > 0) { logprintf(LOG_ERR, "pilight-daemon instance found (%d)", (int)pid); return (EXIT_FAILURE); } if((pid = findproc(pilight_learn, NULL)) > 0) { logprintf(LOG_ERR, "pilight-learn instance found (%d)", (int)pid); return (EXIT_FAILURE); } if((pid = findproc(pilight_debug, NULL)) > 0) { logprintf(LOG_ERR, "pilight-debug instance found (%d)", (int)pid); return (EXIT_FAILURE); } if(access(settingsfile, F_OK) != -1) { if(settings_read() != 0) { return EXIT_FAILURE; } } hardware_init(); if(settings_find_string("hardware-file", &hwfile) == 0) { hardware_set_file(hwfile); if(hardware_read() == EXIT_FAILURE) { goto clear; } } /* Start threads library that keeps track of all threads used */ threads_create(&pth, NULL, &threads_start, (void *)NULL); struct conf_hardware_t *tmp_confhw = conf_hardware; while(tmp_confhw) { if(tmp_confhw->hardware->init() == EXIT_FAILURE) { logprintf(LOG_ERR, "could not initialize %s hardware mode", tmp_confhw->hardware->id); goto clear; } threads_register(tmp_confhw->hardware->id, &receive_code, (void *)tmp_confhw->hardware, 0); tmp_confhw = tmp_confhw->next; } while(main_loop) { sleep(1); } clear: main_gc(); return (EXIT_FAILURE); }
/** main function */ int main(void) { // SPCR &= ~(1<<SPE); // TIMSK0 &= ~(1<<TOIE1); wdt_disable(); /* Clear WDRF in MCUSR */ MCUSR &= ~(1<<WDRF); /* Write logical one to WDCE and WDE */ /* Keep old prescaler setting to prevent unintentional time-out */ WDTCSR |= (1<<WDCE) | (1<<WDE); /* Turn off WDT */ WDTCSR = 0x00; //volatile long l; // for(l=0;l<1000000;l++); DDR_CONFIG_IN(CONFIG1); PIN_SET(CONFIG1); wdt_enable(WDTO_2S); wdt_reset(); volatile unsigned long l; for(l=0;l<10;l++); if( !PIN_HIGH(CONFIG1) ){ global.config = 30; }else{ global.config = 21; } leds_init(); wdt_reset(); if( global.config == 21 ){ DDR_CONFIG_IN(JUMPER1C1); PIN_SET(JUMPER1C1); }else if( global.config == 30 ){ DDR_CONFIG_IN(JUMPER1C2); PIN_SET(JUMPER1C2); adc_init(); uint16_t bat = adc_getChannel(6); if( bat < ADC_MINBATIDLE ){ //global.flags.lowbat = 1; } } wdt_reset(); init_pwm(); #if SERIAL_UART uart1_init( UART_BAUD_SELECT(UART_BAUDRATE,F_CPU)); stdout = &mystdout; #endif #if RC5_DECODER rc5_init(); #endif wdt_reset(); #if STATIC_SCRIPTS init_script_threads(); #endif settings_read(); //if((global.config == 21 && !PIN_HIGH(JUMPER1C1)) || (global.config== 30 && !PIN_HIGH(JUMPER1C2))) // interfaces_setEnabled(IFACE_RF,0); control_init(); wdt_reset(); #if RS485_CTRL rs485_init(); zbus_core_init(); #endif //rf_init(); packet_init(idbuf[0],0); wdt_reset(); srandom(random_seed); random_seed = random(); /* enable interrupts globally */ sei(); // global.state = STATE_RUNNING; // global.state = STATE_PAUSE; // global.flags.running = 0; while (1) { wdt_reset(); //leds_main(); #if 1 packet_tick(); #else if(packetbase ){//> 32){ packetbase = 0; packet_tick(); //if(main_reset++ > 16000) // jump_to_bootloader(); //uint16_t bat = adc_getChannel(6); /*if( bat < ADC_MINBATIDLE ){ global.flags.lowbat = 1; }*/ } #endif //if( global.flags.lowbat ){ // control_lowbat(); //} if( global.flags.timebase ){ //control_tick(); global.flags.timebase=0; } /* after the last pwm timeslot, rebuild the timeslot table */ //if (global.flags.last_pulse) { // global.flags.last_pulse = 0; //if(global.flags.running) //update_pwm_timeslots(); //} /* at the beginning of each pwm cycle, call the fading engine and * execute all script threads */ if (global.flags.new_cycle) { global.flags.new_cycle = 0; if(control_faderunning) update_brightness(); if(global.flags.running){ #if STATIC_SCRIPTS // execute_script_threads(); #endif } //continue; } #if RC5_DECODER #endif #if RS485_CTRL rs485_process(); #endif #if SERIAL_UART //serial_process(); #endif } }
int main(int argc, char **argv) { struct timespec timeout = {SELECT_TIMEOUT_SECONDS, 0}; struct sigaction sigact; sigset_t select_sigset; int exitval = EXIT_FAILURE; int syslog_options = LOG_ODELAY | LOG_PERROR; int settings_retval; parse_args(argc, argv); openlog(program_invocation_short_name, syslog_options, LOG_DAEMON); syslog(LOG_INFO, "starting"); memset(&sigact, 0, sizeof(struct sigaction)); sigact.sa_handler = &sigterm_handler; if (sigfillset(&sigact.sa_mask) == -1) { syslog(LOG_ERR, "sigfillset: %s", strerror(errno)); goto out; } if (sigaction(SIGTERM, &sigact, NULL) == -1) { syslog(LOG_ERR, "sigaction SIGTERM: %s", strerror(errno)); goto out; } if (!is_daemon && sigaction(SIGINT, &sigact, NULL) == -1) { syslog(LOG_ERR, "sigaction SIGINT: %s", strerror(errno)); goto out; } if (sigemptyset(&select_sigset) == -1) { syslog(LOG_ERR, "sigemptyset: %s", strerror(errno)); goto out; } if (sigaddset(&select_sigset, SIGTERM) == -1) { syslog(LOG_ERR, "sigaddset SIGTERM: %s", strerror(errno)); goto out; } if (!is_daemon && sigaddset(&select_sigset, SIGINT) == -1) { syslog(LOG_ERR, "sigaddset SIGINT: %s", strerror(errno)); goto out; } settings_retval = settings_read(&settings); switch (settings_retval) { case 0: break; case -1: syslog(LOG_ERR, "settings_read: %s", strerror(errno)); goto out; default: syslog(LOG_ERR, "settings_read: %s", settings_strerror(settings_retval)); goto out; } if ((monitor_fd = open_evdev_by_name(settings.monitor_name)) == -1) { syslog(LOG_ERR, "open monitor %s: %s", settings.monitor_name, strerror(errno)); goto out; } if ((filter_fd = open_evdev_by_name(settings.filter_name)) == -1) { syslog(LOG_ERR, "open filter %s: %s", settings.filter_name, strerror(errno)); goto out; } if (ioctl(filter_fd, EVIOCGRAB, 1) == -1) { syslog(LOG_ERR, "grab filter: %s", strerror(errno)); goto out; } if ((clone_fd = clone_evdev(filter_fd, &settings.clone_id, settings.clone_name)) == -1) { syslog(LOG_ERR, "clone_evdev: %s", strerror(errno)); goto out; } if (is_daemon && daemonize() == -1) { syslog(LOG_ERR, "daemonize: %s", strerror(errno)); goto out; } syslog(LOG_INFO, "started"); while (is_running) { fd_set rfds; FD_ZERO(&rfds); FD_SET(monitor_fd, &rfds); FD_SET(filter_fd, &rfds); switch (pselect(filter_fd + 1, &rfds, NULL, NULL, &timeout, &select_sigset)) { case 0: break; case -1: syslog(LOG_ERR, "select: %s", strerror(errno)); goto out; default: if (FD_ISSET(filter_fd, &rfds)) { if (handle_filter() == -1) { goto out; } } else if (FD_ISSET(monitor_fd, &rfds)) { if (handle_monitor() == -1) { goto out; } } break; } } syslog(LOG_INFO, "stopped"); syslog(LOG_INFO, "terminating"); exitval = EXIT_SUCCESS; out: settings_free(&settings); if (clone_fd != -1) { if (ioctl(clone_fd, UI_DEV_DESTROY) == -1) { syslog(LOG_ERR, "destroy clone: %s", strerror(errno)); exitval = EXIT_FAILURE; } if (close(clone_fd) == -1) { syslog(LOG_ERR, "close clone: %s", strerror(errno)); exitval = EXIT_FAILURE; } } if (filter_fd != -1) { if (ioctl(filter_fd, EVIOCGRAB, 0) == -1) { syslog(LOG_ERR, "release filter: %s", strerror(errno)); exitval = EXIT_FAILURE; } if (close(filter_fd) == -1) { syslog(LOG_ERR, "close filter: %s", strerror(errno)); exitval = EXIT_FAILURE; } } if (monitor_fd != -1) { if (close(monitor_fd) == -1) { syslog(LOG_ERR, "close monitor: %s", strerror(errno)); exitval = EXIT_FAILURE; } } syslog(LOG_INFO, "terminated"); return exitval; }
static int cmd_list_cb(int argc, const char *argv[], void *chout_p, void *chin_p, void *arg_p, void *call_arg_p) { const FAR struct setting_t *setting_p; int i; int8_t int8; int16_t int16; int32_t int32; char buf[32]; size_t size; /* Print the header. */ std_fprintf(chout_p, FSTR("NAME TYPE SIZE VALUE\r\n")); /* Print all settings. */ setting_p = &settings[0]; while (setting_p->name_p != NULL) { /* Print the name. */ if (std_strlen(setting_p->name_p) >= sizeof(buf)) { continue; } std_strcpy(buf, setting_p->name_p); std_fprintf(chout_p, FSTR("%-20s "), buf); size = setting_p->size; switch (setting_p->type) { case setting_type_int8_t: int8 = 0; settings_read(&int8, setting_p->address, size); std_fprintf(chout_p, FSTR("int8_t 1 %d\r\n"), (int)int8); break; case setting_type_int16_t: int16 = 0; settings_read(&int16, setting_p->address, size); std_fprintf(chout_p, FSTR("int16_t 2 %d\r\n"), (int)int16); break; case setting_type_int32_t: int32 = 0; settings_read(&int32, setting_p->address, size); std_fprintf(chout_p, FSTR("int32_t 4 %ld\r\n"), (long)int32); break; case setting_type_string_t: std_fprintf(chout_p, FSTR("string %4u "), (int)size); for (i = 0; i < size; i++) { settings_read(&buf[0], setting_p->address + i, 1); if (buf[0] == '\0') { break; } std_fprintf(chout_p, FSTR("%c"), buf[0]); } std_fprintf(chout_p, FSTR("\r\n")); break; default: std_fprintf(chout_p, FSTR("bad setting type %d\r\n"), setting_p->type); } setting_p++; } return (0); }
static int cmd_read_cb(int argc, const char *argv[], void *chout_p, void *chin_p, void *arg_p, void *call_arg_p) { const FAR struct setting_t *setting_p; int i; int8_t int8; int16_t int16; int32_t int32; char buf[1]; if (argc != 2) { std_fprintf(chout_p, FSTR("Usage: %s <name>\r\n"), argv[0]); return (-1); } /* Find the setting in the settings array. */ setting_p = &settings[0]; while (setting_p->name_p != NULL) { if (std_strcmp(argv[1], setting_p->name_p) == 0) { switch (setting_p->type) { case setting_type_int8_t: int8 = 0; settings_read(&int8, setting_p->address, setting_p->size); std_fprintf(chout_p, FSTR("%d\r\n"), (int)int8); break; case setting_type_int16_t: int16 = 0; settings_read(&int16, setting_p->address, setting_p->size); std_fprintf(chout_p, FSTR("%d\r\n"), (int)int16); break; case setting_type_int32_t: int32 = 0; settings_read(&int32, setting_p->address, setting_p->size); std_fprintf(chout_p, FSTR("%ld\r\n"), (long)int32); break; case setting_type_string_t: for (i = 0; i < setting_p->size; i++) { buf[0] = '\0'; settings_read(&buf[0], setting_p->address + i, 1); if (buf[0] == '\0') { break; } std_fprintf(chout_p, FSTR("%c"), buf[0]); } std_fprintf(chout_p, FSTR("\r\n")); break; default: std_fprintf(chout_p, FSTR("bad setting type %d\r\n"), setting_p->type); } return (0); } setting_p++; } std_fprintf(chout_p, FSTR("%s: setting not found\r\n"), argv[1]); return (-1); }