예제 #1
0
static void
init_settings(void)
{
    settings_init();
    settings_load();
    
    hotkey_t hk;
    settings_get(TRIGGER_KEY, &hk);
    INIT_KEY_SETTING(trigger);

    settings_get(ENG_KEY, &hk);
    INIT_KEY_SETTING(english);

    varchar colorstr;
    settings_get(PREEDIT_COLOR, colorstr);
    INIT_COLOR_SETTING(background_color_btn);

    settings_get(PREEDIT_FONT_COLOR, colorstr);
    INIT_COLOR_SETTING(font_color_btn);

    varchar fontstr;
    settings_get(PREEDIT_FONT, fontstr);
    gtk_font_button_set_font_name(font_btn, fontstr);

    double scale;
    settings_get(PREEDIT_OPACITY, &scale);
    gtk_adjustment_set_value(opacity_value, scale);

    int ncandi;
    settings_get(CANDIDATES_SIZE, &ncandi);
    gtk_adjustment_set_value(ncandidates, ncandi);
}
예제 #2
0
void vibrate_quarterly() {
  // load settings
  ElCidSettings *settings = settings_load();
    
  // don't vibrate if not set
  if(!settings->QuarterHourlyVibrate) {
    return;
  }
    
  // get hour from local time  
  time_t temp = time(NULL);
  struct tm *tick_time = localtime(&temp);
  
  // create pattern for vibration
  int minutes = tick_time->tm_min;
  
  // abort if not on the quarter hour
  if(minutes == 0 || minutes % 15 != 0) {
    return;
  }
  
  // get settings value after we know we need it
  u_short vibration_type = settings->QuarterHourVibrationType;
    
  // do pattern as configured
  if(1 == vibration_type) {
    vibes_short_pulse();
  } else if(2 == vibration_type) {
    vibes_long_pulse();
  } else if(3 == vibration_type) {
    vibes_double_pulse();
  } else if(4 == vibration_type) {
    vibrate_quarterly_pattern(minutes);
  }
}
예제 #3
0
void settings_menu_push(state_stack* stack, void* udata) {
	(void) udata;
	state_desc mm = {
		GAME_SETTINGS_MENU, nullptr,
		nullptr, nullptr,
		&_event,
		nullptr,
		&_draw,
		&_destroy,
		nullptr, nullptr, false,
	};
	
	_settings_menu *data = (_settings_menu*) malloc(sizeof(_settings_menu));
	
	menu *pMenu = menu_init(100, 50);
	menu_add_entry(pMenu, "Controls");
	menu_add_entry(pMenu, "");
	menu_add_entry(pMenu, STR_ARROWBIG_LEFT " Save Settings");
	menu_add_entry(pMenu, STR_ARROWBIG_LEFT " Discard Changes");
	menu_auto_resize(pMenu);
	data->m_menu = pMenu;
	
	data->m_settings = settings_init();
	input_config_settings(data->m_settings, g_keybinds);
	screen_config_settings(data->m_settings, nullptr);
	settings_load(data->m_settings, settings_file_path);
	
	mm.m_pData = data;
	table_append(stack, &mm);
}
예제 #4
0
void settings_default()
{
    timer.setDefault();
    strcpy((char*)conf.sysName, "           ");
    conf.warnTime = 2;
    conf.mirrorTime = 2;
    conf.cameraFPS = 33;
    conf.bulbMode = 0;
    conf.lcdColor = 0;
    conf.cameraMake = CANON;
    conf.settingsVersion = SETTINGS_VERSION;
    conf.shutterVersion = SHUTTER_VERSION;
    conf.lcdBacklightTime = 3;
    conf.sysOffTime = 12;
    conf.flashlightOffTime = 3;
    conf.devMode = 0;
    conf.auxPort = AUX_MODE_DISABLED;
    conf.btMode = BT_MODE_SLEEP;
    conf.halfPress = HALF_PRESS_ENABLED;
    conf.bulbOffset = 75;
    conf.interface = INTERFACE_AUTO;
    conf.brampMode = BRAMP_MODE_BULB_ISO;
    conf.autoRun = AUTO_RUN_OFF;
    conf.modeSwitch = USB_CHANGE_MODE_DISABLED;
    conf.dollyPulse = 100;
    conf.lcdContrast = 0xf;
    conf.lcdCoefficent = 0x7;
    conf.lcdBias = 0x4;
    conf.bulbMin = 56;
    conf.isoMax = 10;
    conf.apertureMax = 31;
    conf.apertureMin = 2;
    settings_save();
    settings_load();
}
예제 #5
0
void _event(state_stack* stack, SDL_Event *sdlEvent) {
	state_desc *top = (state_desc*) table_ind(stack, stack->m_len-1);
	_settings_menu *data = (_settings_menu*) top->m_pData;
	menu *pMenu = (menu*) data->m_menu;
	settings *pSettings = (settings*) data->m_settings;
	
	if (sdlEvent->type == SDL_QUIT) {
		state_stack_kill(stack);
		return;
	}
	
	switch (menu_input(pMenu, sdlEvent)) {
	case 0:
		// Controls
		top->m_fnPushChild = &_controls_push;
		break;
	case 1:
		// (empty)
		break;
	case 2:
		// < Save Settings
		settings_save(pSettings, settings_file_path);
		top->m_isDead = true;
		break;
	case 3:
		// < Discard Settings
		settings_load(pSettings, settings_file_path);
		top->m_isDead = true;
		break;
	default:
		break;
	}
}
예제 #6
0
int settings_get_sequence_number()
{
    Settings *s = settings_load();
    int ret = s->odl0_seq_num;
    settings_free(s);
    return ret;
}
예제 #7
0
void settings_default()
{
    timer.setDefault();
    strcpy((char*)conf.sysName, "           ");
    conf.warnTime = 2;
    conf.mirrorTime = 2;
    conf.lcdColor = 0;
    conf.settingsVersion = SETTINGS_VERSION;
    conf.shutterVersion = SHUTTER_VERSION;
    conf.lcdBacklightTime = 3;
    conf.sysOffTime = 12;
    conf.flashlightOffTime = 3;
    conf.devMode = 0;
    conf.auxPort = AUX_MODE_DISABLED;
    conf.btMode = BT_MODE_SLEEP;
    conf.brampMode = BRAMP_MODE_BULB_ISO;
    conf.autoRun = AUTO_RUN_OFF;
    conf.dollyPulse = 100;
    conf.dollyPulse2 = 100;
    conf.lcdContrast = 3;
    conf.lcdCoefficent = 0x7;
    conf.lcdBias = 0x3;
    conf.isoMax = 10;
    conf.apertureMax = 31;
    conf.apertureMin = 2;
    conf.debugEnabled = 0;
    conf.arbitraryBulb = 0;
    conf.menuWrap = 1;
    conf.extendedRamp = 0;
    strcpy((char*)conf.test, "Test       ");
    conf.lightIntegrationMinutes = 5;
    conf.pFactor = 10;
    conf.iFactor = 12;
    conf.dFactor = 12;
    conf.errorAlert = 0;
    conf.lightThreshold = 20;
    conf.linearInterpolation = 0;

    conf.camera.cameraFPS = 33;
    conf.camera.nikonUSB = 0;
    conf.camera.bulbEndOffset = 8;
    conf.camera.bulbMin = 56;
    conf.camera.bulbOffset = 75;
    conf.camera.negBulbOffset = 0;
    conf.camera.interface = INTERFACE_AUTO;
    conf.camera.cameraMake = CANON;
    conf.camera.bulbMode = 0;
    conf.camera.halfPress = HALF_PRESS_ENABLED;
    conf.camera.modeSwitch = USB_CHANGE_MODE_DISABLED;
    conf.camera.brampGap = 6;

    for(uint8_t i = 0; i < MAX_CAMERAS_SETTINGS; i++)
    {
        camera_settings_t cs;
        memset((void*)&cs, 0, sizeof(camera_settings_t));
        eeprom_write_block((const void*)&cs, &camera_settings_eep[i], sizeof(camera_settings_t));
    }
    settings_save();
    settings_load();
}
예제 #8
0
const char *settings_get_station_code()
{
    static char *station_code=NULL;
    if (!station_code) {
        Settings *s = settings_load();
        station_code = STRDUP(s->station_code);
        settings_free(s);
    }
    return station_code;
}
예제 #9
0
void settings_init()
{
  settings_load();
  if(eeprom_read_byte((const uint8_t *) &conf_eep) == 255 || conf.version != VERSION)
  {
    timer.setDefault();
    strcpy((char *)conf.sysName, "sys01");
    conf.warnTime = 2;
    conf.mirrorTime = 2;
    conf.cameraFPS = 34;
    conf.bulbMode = 0;
    conf.lcdColor = 0;
    conf.cameraMake = CANON;
    conf.version = VERSION;
    conf.lcdBacklightTime = 3;
    conf.sysOffTime = 12;
    conf.flashlightOffTime = 3;
    settings_save();
  }
  settings_load();
}
예제 #10
0
파일: web.c 프로젝트: hmflash/tikitank
static
void effects_get(struct mg_connection* conn) {
	int len;

	settings_load();

	len = effects_json(work_buf, sizeof(work_buf));

	mg_send_header(conn, CONTENT_TYPE, CONTENT_TYPE_JSON);
	mg_send_status(conn, 200);
	mg_send_data(conn, work_buf, len);
}
예제 #11
0
파일: web.c 프로젝트: hmflash/tikitank
static
void settings_post(struct mg_connection* conn) {
	int rc;
	int len;
	char buf[256];

	settings_load();

	len = mg_get_var(conn, BRIGHTNESS, buf, sizeof(buf));
	if (len > 0) {
		settings.brightness = strtol(buf, NULL, 10);
	}

	len = mg_get_var(conn, MANUAL_TICK, buf, sizeof(buf));
	if (len > 0) {
		settings.manual_tick = strtol(buf, NULL, 10);
	}

	len = mg_get_var(conn, IDLE_INTERVAL, buf, sizeof(buf));
	if (len > 0) {
		settings.idle_interval = strtol(buf, NULL, 10);
	}

	len = mg_get_var(conn, MANUAL_TOGGLE, buf, sizeof(buf));
	if (len > 0) {
		settings.manual_toggle = strtol(buf, NULL, 10);
	}

	len = mg_get_var(conn, SCREEN_SAVER_TOGGLE, buf, sizeof(buf));
	if (len > 0) {
		settings.screen_saver_toggle = strtol(buf, NULL, 10);
	}

	len = mg_get_var(conn, ALPHA, buf, sizeof(buf));
	if (len > 0) {
		settings.alpha = strtol(buf, NULL, 10);
	}

	rc = settings_save();
	if (rc) {
		mg_printf_data(conn, "Could not save " SETTINGS_FILE);
		mg_send_status(conn, 500);
		return;
	}

	len = settings_json(work_buf, sizeof(work_buf));

	mg_send_header(conn, CONTENT_TYPE, CONTENT_TYPE_JSON);
	mg_send_status(conn, 200);
	mg_send_data(conn, work_buf, len);
}
예제 #12
0
int settings_get_next_req_id(int request_type, const char *drf)
{
    Settings *s = settings_load();
    int id;
    switch (request_type) {
        case OBSERVATION_REQUEST:
        {
            const char *stn = settings_get_aadn_or_tdrs();
            if (strncmp_case(stn, "AADN", 4)==0) {
                id = s->obs_req_id_aadn;
            }
            else if (strncmp_case(stn, "TDRS", 4)==0) {
                id = s->obs_req_id_tdrs;
            }
            else {
                printf("[ID] Unexpected STN: %s\n", stn);
                id = s->obs_req_id_aadn;
            }
            break;
        }

        case ACQUISITION_REQUEST:
        {
            int found=FALSE, i;
            id = 1;
            for (i=0; i<MAX_STATIONS; ++i) {
                if (strncmp_case(drf, s->acq_req_stn_codes[i],
                        strlen(s->acq_req_stn_codes[i])) == 0)
                {
                    id = s->acq_req_ids[i];
                    found = TRUE;
                    break;
                }
            }
            if (!found) {
                printf("Unknown station code '%s' - using request id = 1.\n", drf);
            }
            break;
        }

        case ON_DEMAND_LEVEL_0:
            id = s->odl0_req_id;
            break;

        case UNSELECTED_REQUEST_TYPE:
            id = 0;
            break;
    }
    settings_free(s);
    return id;
}
예제 #13
0
bool settings_start() {
	if (!settings_load()) {
		return false;
	}
	scene.unload = &settings_unload;
	scene.update = &settings_update;
	scene.draw = &settings_draw;
	scene.showLetterbox = true;
	
	startPause(false);
	pauseTempo = 1;
	
	return true;
}
예제 #14
0
파일: settings.c 프로젝트: bobbyzhu/clink
//------------------------------------------------------------------------------
void* initialise_clink_settings()
{
    char settings_file[MAX_PATH];

    get_settings_file(settings_file, sizeof_array(settings_file));

    g_settings = settings_init(g_settings_decl, sizeof_array(g_settings_decl));

    if (!settings_load(g_settings, settings_file))
    {
        settings_save(g_settings, settings_file);
    }

    return g_settings;
}
예제 #15
0
파일: main.c 프로젝트: XueWei/sunpinyin
int 
main(int argc, char* argv[])
{
    if (argc == 2 && strcmp(argv[1], "-d") == 0) {
        int pid = fork();
        if (pid < 0)
            return -1;
        else if (pid > 0)
            return 0;
    }
    
    init_display(&argc, &argv);
    XSetErrorHandler (_xerror_handler);
    preedit_init();

    settings_init();
    settings_load();

    /* check if the codeset is utf-8 */
    if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
        printf("Can't use xim server with codeset %s.\n",
               nl_langinfo(CODESET));
        return -1;
    }

    /* guess the locale */
    char* locale = getenv("LC_CTYPE");
    if (locale == NULL) {
        locale = getenv("LANG");
        if (locale == NULL) {
            printf("Can't guess locale.\n");
            return -1;
        }
    }
    
    XIMHandle* hdl = create_xim_server(XIM_NAME, locale);
    preedit_set_handle(hdl);
    preedit_reload();

    signal(SIGUSR1, on_app_sig);
    signal(SIGHUP, on_app_sig);
    signal(SIGINT, on_app_sig);
    signal(SIGTERM, on_app_sig);

    gtk_main();
    
    return 0;
}
void settings_window_create(void)
{
    char *button_texts[] = { "1", //icon font
                "", "", "-", "3", "+", "-", "3", "+"};
    static UG_BUTTON buttons[16];
    static UG_OBJECT objects[16];
    int id = 0;
    int i = 0;
    int j = 0;

    UG_WindowCreate(&g_settings_window, objects, 16, settings_window_callback);
    UG_WindowSetStyle(&g_settings_window, WND_STYLE_2D);

    for (i = 0; i < 3; i++) {
        for (j = 0; j < 3; j++) {
            id = i * 3 + j;
            UG_ButtonCreate(&g_settings_window, buttons + id, id, 80 * j,
                    200 - i * 80, 80 * j + 79, 239 - i * 80);
            UG_ButtonSetFont(&g_settings_window, id, &FONT_SIZE20);
            UG_ButtonSetText(&g_settings_window, id,
                    button_texts[id]);
            UG_ButtonSetStyle(&g_settings_window, id,
                    BTN_STYLE_2D | BTN_STYLE_TOGGLE_COLORS
                            | BTN_STYLE_NO_BORDERS);
        }
    }

    UG_ButtonSetFont(&g_settings_window, 0, &FONT_ICON24);

    id++;
    UG_ButtonCreate(&g_settings_window, buttons + id, id, 0, 0, 239, 39);
    UG_ButtonSetFont(&g_settings_window, id, &FONT_SIZE20);
    UG_ButtonSetText(&g_settings_window, id, "Brightness");
    UG_ButtonSetStyle(&g_settings_window, id,
            BTN_STYLE_2D | BTN_STYLE_NO_BORDERS);
    UG_ButtonSetBackColor(&g_settings_window, id, 0);

    id++;
    UG_ButtonCreate(&g_settings_window, buttons + id, id, 0, 80, 239, 119);
    UG_ButtonSetFont(&g_settings_window, id, &FONT_SIZE20);
    UG_ButtonSetText(&g_settings_window, id, "Sound");
    UG_ButtonSetStyle(&g_settings_window, id,
            BTN_STYLE_2D | BTN_STYLE_NO_BORDERS);
    UG_ButtonSetBackColor(&g_settings_window, id, 0);

    settings_load();
}
예제 #17
0
파일: main.c 프로젝트: XueWei/sunpinyin
static void
on_app_sig(int sig)
{
    if (sig == SIGUSR1) {
        /* reload the settings */
        settings_load();
        preedit_reload();
    } else {
        preedit_finalize();
        icmgr_finalize();

        settings_save();
        settings_destroy();
    
        exit(0);
    }
}
예제 #18
0
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
        _cleanup_fclose_ FILE *f = NULL;
        _cleanup_(settings_freep) Settings *s = NULL;

        if (size == 0)
                return 0;

        f = fmemopen_unlocked((char*) data, size, "re");
        assert_se(f);

        /* We don't want to fill the logs with messages about parse errors.
         * Disable most logging if not running standalone */
        if (!getenv("SYSTEMD_LOG_LEVEL"))
                log_set_max_level(LOG_CRIT);

        (void) settings_load(f, "/dev/null", &s);

        return 0;
}
예제 #19
0
void settings_init()
{
    settings_load();
    uint8_t need_save = 0;
    if(conf.shutterVersion != SHUTTER_VERSION)
    {
        timer.setDefault();
        conf.shutterVersion = SHUTTER_VERSION;
        need_save = 1;
    }
    if(conf.settingsVersion != SETTINGS_VERSION)
    {
        settings_default();
        need_save = 0;
        settings_reset = 1;
        // This is where we'd put a setup wizard
    }
    if(need_save) settings_save();
}
예제 #20
0
파일: hap.c 프로젝트: andrei-tatar/HAP.esp
bool ICACHE_FLASH_ATTR hap_init()
{
    settings_load();
    httpd_register(index_httpd_request);
    static ETSTimer upTimeTimer;
	os_timer_disarm(&upTimeTimer);
	os_timer_setfn(&upTimeTimer, (os_timer_func_t *)uptimeIncrement, NULL);
	os_timer_arm(&upTimeTimer, 1000, 1);

	wifi_set_event_handler_cb(onWifiEvent);

    bool result;

    if (!settings_valid())
    {
        DEBUG_PRINT("[HAP]Settings not valid, using defaults, starting AP\n");

        settings.password[0] = 0;
        settings.ssid[0] = 0;

        strcpy(settings.serverName, "hap_server");
        strcpy(settings.mqttUser, "user");
        strcpy(settings.mqttPassword, "password");
        strcpy(settings.mqttTopic, "topic");
        settings.udpPort = 5100;

        char aux[20];
        os_sprintf(aux, "hap_%d", system_get_chip_id());
        result = setup_wifi_ap_mode(aux);
    }
    else
    {
        DEBUG_PRINT("[HAP]Settings valid, connecting to AP %s\n", settings.ssid);

        udp_init();
        result = setup_wifi_st_mode(settings.ssid, settings.password);
    }

    if (result) httpd_init(80);

    return result;
}
예제 #21
0
static void window_load() {
    // APP_LOG(APP_LOG_LEVEL_DEBUG, "inside window_load()");
    settings_load(window);
    // screen size 144 x 168
    watchface_load(window);

    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_bounds(window_layer);

    s_windshield_path = gpath_create(&WINDSHIELD_PATH_INFO);

    s_top_layer = layer_create(GRect(0, 0, bounds.size.w, 130));
    layer_set_update_proc(s_top_layer, windshield_proc);
    layer_add_child(window_layer,s_top_layer);

    s_grill_layer = layer_create(GRect(0, 57, bounds.size.w, 60));
    layer_set_update_proc(s_grill_layer, grill_proc);
    layer_add_child(window_layer,s_grill_layer);

    indicators_load(window);
}
예제 #22
0
void vibrate_hourly() {
  // load settings
  ElCidSettings *settings = settings_load();
 
  // don't vibrate if not set
  if(!settings->HourlyVibrate) {
    return;
  }

  u_short vibration_type = settings->HourVibrationType;
  
  // chose what type of vibration to do
  if(1 == vibration_type) {
    vibes_short_pulse();
  } else if(2 == vibration_type) {
    vibes_long_pulse();
  } else if(3 == vibration_type) {
    vibes_double_pulse();
  } else if(4 == vibration_type) {
    vibrate_hourly_pattern();
  }  
}
예제 #23
0
파일: toxic.c 프로젝트: gracchus163/toxic
int main(int argc, char *argv[])
{
    char *user_config_dir = get_user_config_dir();
    int config_err = 0;

    parse_args(argc, argv);

    /* Make sure all written files are read/writeable only by the current user. */
    umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);

    signal(SIGINT, catch_SIGINT);

    config_err = create_user_config_dir(user_config_dir);

    if (DATA_FILE == NULL ) {
        if (config_err) {
            DATA_FILE = strdup("data");

            if (DATA_FILE == NULL)
                exit_toxic_err("failed in main", FATALERR_MEMORY);
        } else {
            DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1);

            if (DATA_FILE == NULL)
                exit_toxic_err("failed in main", FATALERR_MEMORY);

            strcpy(DATA_FILE, user_config_dir);
            strcat(DATA_FILE, CONFIGDIR);
            strcat(DATA_FILE, "data");
        }
    }

    free(user_config_dir);

    /* init user_settings struct and load settings from conf file */
    user_settings_ = calloc(1, sizeof(struct user_settings));

    if (user_settings_ == NULL)
        exit_toxic_err("failed in main", FATALERR_MEMORY);

    char *p = arg_opts.config_path[0] ? arg_opts.config_path : NULL;
    int settings_err = settings_load(user_settings_, p);

    Tox *m = init_tox(arg_opts.use_ipv4);
    init_term();

    if (m == NULL)
        exit_toxic_err("failed in main", FATALERR_NETWORKINIT);

    if (!arg_opts.ignore_data_file)
        load_data(m, DATA_FILE);

    prompt = init_windows(m);
    prompt_init_statusbar(prompt, m);

    /* thread for ncurses stuff */
    if (pthread_mutex_init(&Winthread.lock, NULL) != 0)
        exit_toxic_err("failed in main", FATALERR_MUTEX_INIT);

    if (pthread_create(&Winthread.tid, NULL, thread_winref, (void *) m) != 0)
        exit_toxic_err("failed in main", FATALERR_THREAD_CREATE);

#ifdef _AUDIO

    av = init_audio(prompt, m);


    set_primary_device(input, user_settings_->audio_in_dev);
    set_primary_device(output, user_settings_->audio_out_dev);
#elif _SOUND_NOTIFY
    if ( init_devices() == de_InternalError )
        line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init devices");

#endif /* _AUDIO */
    
    init_notify(60, 3000);

#ifdef _SOUND_NOTIFY
    notify(prompt, self_log_in, 0);
#endif /* _SOUND_NOTIFY */
    
    const char *msg;

    if (config_err) {
        msg = "Unable to determine configuration directory. Defaulting to 'data' for a keyfile...";
        line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
    }

    if (settings_err == -1) {
        msg = "Failed to load user settings";
        line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
    }

    sort_friendlist_index();

    uint64_t last_save = (uint64_t) time(NULL);

    while (true) {
        update_unix_time();
        do_toxic(m, prompt);
        uint64_t cur_time = get_unix_time();

        if (timed_out(last_save, cur_time, AUTOSAVE_FREQ)) {
            pthread_mutex_lock(&Winthread.lock);
            store_data(m, DATA_FILE);
            pthread_mutex_unlock(&Winthread.lock);

            last_save = cur_time;
        }

        usleep(40000);
    }

    return 0;
}
예제 #24
0
void apply_saved_settings()
{
    Settings *s = settings_load();
    apply_settings_to_gui(s);
    settings_free(s);
}
예제 #25
0
파일: web.c 프로젝트: hmflash/tikitank
static
void effects_post(struct mg_connection* conn) {
	int len1;
	int len2;
	char kind[256];
	char arg1[256];
	char arg2[256];
	struct channel* channel;

	settings_load();

	len1 = mg_get_var(conn, KIND, kind, sizeof(kind));
	if (len1 < 0) {
		mg_printf_data(conn, "Missing field: " KIND);
		mg_send_status(conn, 400);
		return;
	}

	if(!strncmp(kind, "treads", sizeof(kind))) {
		channel = &channel_treads;
	} else if(!strncmp(kind, "barrel", sizeof(kind))) {
		channel = &channel_barrel;
	} else if(!strncmp(kind, "panels", sizeof(kind))) {
		channel = &channel_panels;
	} else {
		mg_printf_data(conn, "Invalid kind");
		mg_send_status(conn, 400);
		return;
	}
	
	len1 = mg_get_var(conn, ACTIVE, arg1, sizeof(arg1));
	if (len1 > 0) {
		long idx;

		LOG(("selectEffect: kind=%s active=%s\n", kind, arg1));

		idx = strntol(arg1, len1, 10);
		if (idx >= 0 && idx < channel->num_effects) {
			channel->active = idx;
			effects_post_reply(conn);
			return;
		}

		mg_printf_data(conn, "Invalid effect");
		mg_send_status(conn, 400);
		return;
	}

	len1 = mg_get_var(conn, IS_SSAVER, arg1, sizeof(arg1));
	if (len1 > 0) {
		LOG(("setEffectScreenSaver: %s\n", arg1));
		if (!strncmp(arg1, "true", sizeof(arg1))) {
			channel->effects[channel->active]->screen_saver = 1;
		} else {
			channel->effects[channel->active]->screen_saver = 0;
		}
		effects_post_reply(conn);
		return;
	}

	len1 = mg_get_var(conn, COLOR, arg1, sizeof(arg1));
	len2 = mg_get_var(conn, ARGUMENT, arg2, sizeof(arg2));

	if (len1 > 0 && len2 > 0) {
		long idx = strntol(arg2, len2, 10);
		long color = strntol(arg1+1, len1-1, 16);
		LOG(("setEffectParameters: %ld, %lx\n", idx, color));
		if (idx < NUM_PANELS/3) {
			channel->effects[channel->active]->color_arg.colors[idx].value = color;
		}
		effects_post_reply(conn);
		return;
	} else if (len1 > 0) {
		long color = strntol(arg1+1, len1-1, 16);
		LOG(("setEffectColor: %lx\n", color));
		channel->effects[channel->active]->color_arg.color.value = color;
		effects_post_reply(conn);
		return;
	} else if (len2 > 0) {
		long value = strntol(arg2, len2, 10);
		LOG(("setEffectArgument: %ld\n", value));
		channel->effects[channel->active]->argument = value;
		effects_post_reply(conn);
		return;
	}

	mg_printf_data(conn, "Invalid data");
	mg_send_status(conn, 400);
}
예제 #26
0
void settings_update()
{
  eeprom_write_block((const void *) &conf, &conf_eep, sizeof(settings));
  settings_load();
}
예제 #27
0
int main(int argc, char *argv[])
{
bool inhibit_loadfade = false;
bool error = false;
bool freshstart;
	
	SetLogFilename("debug.txt");
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
	{
		staterr("ack, sdl_init failed: %s.", SDL_GetError());
		return 1;
	}
	atexit(SDL_Quit);
	
	// start up inputs first thing because settings_load may remap them
	input_init();
	
	// load settings, or at least get the defaults,
	// so we know the initial screen resolution.
	settings_load();
	
	if (Graphics::init(settings->resolution)) { staterr("Failed to initialize graphics."); return 1; }
	if (font_init()) { staterr("Failed to load font."); return 1; }
	
	//speed_test();
	//return 1;
	
	#ifdef CONFIG_DATA_EXTRACTOR
	if (!settings->files_extracted)
	{
		if (extract_main())
		{
			Graphics::close();
			font_close();
			return 0;
		}
		else
		{
			settings->files_extracted = true;
			settings_save();
		}
	}
	#endif
	
	if (check_data_exists())
	{
		return 1;
	}
	
	Graphics::ShowLoadingScreen();
	if (sound_init()) { fatal("Failed to initialize sound."); return 1; }
	if (trig_init()) { fatal("Failed trig module init."); return 1; }
	
	if (tsc_init()) { fatal("Failed to initialize script engine."); return 1; }
	if (textbox.Init()) { fatal("Failed to initialize textboxes."); return 1; }
	if (Carets::init()) { fatal("Failed to initialize carets."); return 1; }
	
	if (game.init()) return 1;
	game.setmode(GM_NORMAL);
	// set null stage just to have something to do while we go to intro
	game.switchstage.mapno = 0;
	
	//#define REPLAY
	#ifdef REPLAY
		game.switchstage.mapno = START_REPLAY;
		//Replay::set_ffwd(6000);
		//Replay::set_stopat(3500);
		game.switchstage.param = 1;
	#else
		//game.switchstage.mapno = LOAD_GAME;
		//game.pause(GP_OPTIONS);
		
		if (settings->skip_intro && file_exists(GetProfileName(settings->last_save_slot)))
			game.switchstage.mapno = LOAD_GAME;
		else
			game.setmode(GM_INTRO);
	#endif
	
	// for debug
	if (game.paused) { game.switchstage.mapno = 0; game.switchstage.eventonentry = 0; }
	if (game.switchstage.mapno == LOAD_GAME) inhibit_loadfade = true;
	
	game.running = true;
	freshstart = true;
	
	stat("Entering main loop...");
	#ifdef __SDLSHIM__
		set_console_visible(false);
	#endif
	
	//speed_test();
	//return 1;
	
	while(game.running)
	{
		// SSS/SPS persists across stage transitions until explicitly
		// stopped, or you die & reload. It seems a bit risky to me,
		// but that's the spec.
		if (game.switchstage.mapno >= MAPNO_SPECIALS)
		{
			StopLoopSounds();
		}
		
		// enter next stage, whatever it may be
		if (game.switchstage.mapno == LOAD_GAME || \
			game.switchstage.mapno == LOAD_GAME_FROM_MENU)
		{
			if (game.switchstage.mapno == LOAD_GAME_FROM_MENU)
				freshstart = true;
			
			stat("= Loading game =");
			if (game_load(settings->last_save_slot))
			{
				fatal("savefile error");
				goto ingame_error;
			}
			
			Replay::OnGameStarting();
			
			if (!inhibit_loadfade) fade.Start(FADE_IN, FADE_CENTER);
			else inhibit_loadfade = false;
		}
		else if (game.switchstage.mapno == START_REPLAY)
		{
			stat(">> beginning replay '%s'", GetReplayName(game.switchstage.param));
			
			StopScripts();
			if (Replay::begin_playback(GetReplayName(game.switchstage.param)))
			{
				fatal("error starting playback");
				goto ingame_error;
			}
		}
		else
		{
			if (game.switchstage.mapno == NEW_GAME || \
				game.switchstage.mapno == NEW_GAME_FROM_MENU)
			{
				bool show_intro = (game.switchstage.mapno == NEW_GAME_FROM_MENU);
				InitNewGame(show_intro);
			}
			
			// slide weapon bar on first intro to Start Point
			if (game.switchstage.mapno == STAGE_START_POINT && \
				game.switchstage.eventonentry == 91)
			{
				freshstart = true;
			}
			
			// switch maps
			if (load_stage(game.switchstage.mapno)) goto ingame_error;
			
			player->x = (game.switchstage.playerx * TILE_W) << CSF;
			player->y = (game.switchstage.playery * TILE_H) << CSF;
		}
		
		// start the level
		if (game.initlevel()) return 1;
		
		if (freshstart)
			weapon_introslide();
		
		gameloop();
		game.stageboss.OnMapExit();
		freshstart = false;
	}
	
shutdown: ;
	Replay::close();
	game.close();
	Carets::close();
	
	Graphics::close();
	input_close();
	font_close();
	sound_close();
	tsc_close();
	textbox.Deinit();
	return error;
	
ingame_error: ;
	stat("");
	stat(" ************************************************");
	stat(" * An in-game error occurred. Game shutting down.");
	stat(" ************************************************");
	error = true;
	goto shutdown;
}
예제 #28
0
파일: toxic.c 프로젝트: dardevelin/toxic
int main(int argc, char *argv[])
{
    init_signal_catchers();
    parse_args(argc, argv);

    /* Make sure all written files are read/writeable only by the current user. */
    umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
    int config_err = init_data_files();

    /* init user_settings struct and load settings from conf file */
    user_settings_ = calloc(1, sizeof(struct user_settings));

    if (user_settings_ == NULL)
        exit_toxic_err("failed in main", FATALERR_MEMORY);

    char *p = arg_opts.config_path[0] ? arg_opts.config_path : NULL;
    int settings_err = settings_load(user_settings_, p);

    Tox *m = init_tox();
    init_term();

    /* enable stderr for debugging */
    if (!arg_opts.debug)
        freopen("/dev/null", "w", stderr);

    if (m == NULL)
        exit_toxic_err("failed in main", FATALERR_NETWORKINIT);

    if (!arg_opts.ignore_data_file)
        load_data(m, DATA_FILE);

    prompt = init_windows(m);
    prompt_init_statusbar(prompt, m);

    /* thread for ncurses stuff */
    if (pthread_mutex_init(&Winthread.lock, NULL) != 0)
        exit_toxic_err("failed in main", FATALERR_MUTEX_INIT);

    if (pthread_create(&Winthread.tid, NULL, thread_winref, (void *) m) != 0)
        exit_toxic_err("failed in main", FATALERR_THREAD_CREATE);

#ifdef _AUDIO

    av = init_audio(prompt, m);


    set_primary_device(input, user_settings_->audio_in_dev);
    set_primary_device(output, user_settings_->audio_out_dev);
#elif _SOUND_NOTIFY
    if ( init_devices() == de_InternalError )
        line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init devices");

#endif /* _AUDIO */
    
    init_notify(60, 3000);

#ifdef _SOUND_NOTIFY
//     sound_notify(prompt, self_log_in, 0, NULL);
#endif /* _SOUND_NOTIFY */
    
    const char *msg;
    
    if (config_err) {
        msg = "Unable to determine configuration directory. Defaulting to 'data' for data file...";
        line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
    }

    if (settings_err == -1)
        line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to load user settings");

    if (arg_opts.use_proxy && !arg_opts.force_tcp) {
        msg = "* WARNING: Using a proxy without disabling UDP may leak your real IP address.";
        line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, "%s", msg);
        msg = "  Use the -t option to disable UDP.";
        line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, "%s", msg);
    }

    uint64_t last_save = (uint64_t) time(NULL);
    uint64_t looptimer = last_save;
    useconds_t msleepval = 40000;
    uint64_t loopcount = 0;

    while (true) {
        update_unix_time();
        do_toxic(m, prompt);
        uint64_t cur_time = get_unix_time();

        if (timed_out(last_save, cur_time, AUTOSAVE_FREQ)) {
            pthread_mutex_lock(&Winthread.lock);
            store_data(m, DATA_FILE);
            pthread_mutex_unlock(&Winthread.lock);

            last_save = cur_time;
        }

        msleepval = optimal_msleepval(&looptimer, &loopcount, cur_time, msleepval);
        usleep(msleepval);
    }

    return 0;
}
예제 #29
0
int main(int argc, char **argv)
{
    parse_args(argc, argv);

    /* Use the -b flag to enable stderr */
    if (!arg_opts.debug)
        freopen("/dev/null", "w", stderr);

    if (arg_opts.encrypt_data && arg_opts.unencrypt_data) {
        arg_opts.encrypt_data = 0;
        arg_opts.unencrypt_data = 0;
        queue_init_message("Warning: Using --unencrypt-data and --encrypt-data simultaneously has no effect");
    }

    /* Make sure all written files are read/writeable only by the current user. */
    umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);

    init_default_data_files();

    bool datafile_exists = file_exists(DATA_FILE);

    if (!datafile_exists && !arg_opts.unencrypt_data)
        first_time_encrypt("Creating new data file. Would you like to encrypt it? Y/n (q to quit)");
    else if (arg_opts.encrypt_data)
        first_time_encrypt("Encrypt existing data file? Y/n (q to quit)");


    /* init user_settings struct and load settings from conf file */
    user_settings = calloc(1, sizeof(struct user_settings));

    if (user_settings == NULL)
        exit_toxic_err("failed in main", FATALERR_MEMORY);

    const char *p = arg_opts.config_path[0] ? arg_opts.config_path : NULL;

    if (settings_load(user_settings, p) == -1) {
        queue_init_message("Failed to load user settings");
    }

    int curl_init = curl_global_init(CURL_GLOBAL_ALL);
    int nameserver_ret = name_lookup_init(curl_init);

    if (nameserver_ret == -1) {
        queue_init_message("curl failed to initialize; name lookup service is disabled.");
    } else if (nameserver_ret == -2) {
        queue_init_message("Name lookup server list could not be found.");
    } else if (nameserver_ret == -3) {
        queue_init_message("Name lookup server list does not contain any valid entries.");
    }

#ifdef X11

    if (init_xtra(DnD_callback) == -1)
        queue_init_message("X failed to initialize");

#endif

    Tox *m = load_toxic(DATA_FILE);

    if (arg_opts.encrypt_data && !datafile_exists)
        arg_opts.encrypt_data = 0;


    init_term();

    prompt = init_windows(m);
    prompt_init_statusbar(prompt, m);

    /* thread for ncurses stuff */
    if (pthread_mutex_init(&Winthread.lock, NULL) != 0)
        exit_toxic_err("failed in main", FATALERR_MUTEX_INIT);

    if (pthread_create(&Winthread.tid, NULL, thread_winref, (void *) m) != 0)
        exit_toxic_err("failed in main", FATALERR_THREAD_CREATE);

    /* thread for message queue */
    if (pthread_create(&cqueue_thread.tid, NULL, thread_cqueue, (void *) m) != 0)
        exit_toxic_err("failed in main", FATALERR_THREAD_CREATE);

#ifdef AUDIO

    av = init_audio(prompt, m);

#ifdef VIDEO
    init_video(prompt, m);

#endif /* VIDEO */

    /* AV thread */
    if (pthread_create(&av_thread.tid, NULL, thread_av, (void *) av) != 0)
        exit_toxic_err("failed in main", FATALERR_THREAD_CREATE);

    set_primary_device(input, user_settings->audio_in_dev);
    set_primary_device(output, user_settings->audio_out_dev);

#elif SOUND_NOTIFY

    if ( init_devices() == de_InternalError )
        queue_init_message("Failed to init audio devices");

#endif /* AUDIO */

    init_notify(60, 3000);

    /* screen/tmux auto-away timer */
    if (init_mplex_away_timer(m) == -1)
        queue_init_message("Failed to init mplex auto-away.");

    int nodeslist_ret = load_DHT_nodeslist();

    if (nodeslist_ret != 0) {
        queue_init_message("DHT nodeslist failed to load (error %d)", nodeslist_ret);
    }

    pthread_mutex_lock(&Winthread.lock);
    print_init_messages(prompt);
    pthread_mutex_unlock(&Winthread.lock);

    cleanup_init_messages();

    /* set user avatar from config file. if no path is supplied tox_unset_avatar is called */
    char avatarstr[MAX_STR_SIZE];
    snprintf(avatarstr, sizeof(avatarstr), "/avatar \"%s\"", user_settings->avatar_path);
    execute(prompt->chatwin->history, prompt, m, avatarstr, GLOBAL_COMMAND_MODE);

    time_t last_save = get_unix_time();

    while (true) {
        do_toxic(m);

        time_t cur_time = get_unix_time();

        if (timed_out(last_save, AUTOSAVE_FREQ)) {
            pthread_mutex_lock(&Winthread.lock);

            if (store_data(m, DATA_FILE) != 0)
                line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, "WARNING: Failed to save to data file");

            pthread_mutex_unlock(&Winthread.lock);

            last_save = cur_time;
        }

        usleep(tox_iteration_interval(m) * 1000);
    }

    return 0;
}
예제 #30
0
void settings_set_next_req_id_and_incr_req_num(int req_id, int request_type,
                                               const char *drf)
{
    Settings *s = settings_load();

    switch (request_type) {
        case OBSERVATION_REQUEST:
        {
            const char *stn = settings_get_aadn_or_tdrs();
            if (strncmp_case(stn, "AADN", 4)==0) {
                if (req_id <= s->obs_req_id_aadn)
                    printf("*** New observation request id is smaller!?\n");
                s->obs_req_id_aadn = req_id;
                ++s->obs_req_num;
            }
            else if (strncmp_case(stn, "TDRS", 4)==0) {
                if (req_id <= s->obs_req_id_tdrs)
                    printf("*** New observation request id is smaller!?\n");
                s->obs_req_id_tdrs = req_id;
                ++s->obs_req_num;
            }
            else {
                printf("[NUM] Unexpected STN: %s\n", stn);
            }
            break;
        }

        case ACQUISITION_REQUEST:
        {
            int found=FALSE, i;
            for (i=0; i<MAX_STATIONS; ++i) {
                if (strncmp_case(drf, s->acq_req_stn_codes[i],
                    strlen(s->acq_req_stn_codes[i])) == 0)
                {
                    if (req_id <= s->acq_req_ids[i])
                        printf("*** New acquisition request id for %s is smaller!?\n",
                            drf);
                    s->acq_req_ids[i] = req_id;
                    found = TRUE;
                    break;
                }
            }
            if (!found) {
                printf("Unknown station code '%s' - can't increment request id.\n", drf);
            }
            ++s->acq_req_num;
            break;
        }

        case ON_DEMAND_LEVEL_0:
            if (req_id <= s->odl0_req_id)
                printf("*** New on-demand level 0 request id is smaller!?\n");
            s->odl0_req_id = req_id;
            break;

        case UNSELECTED_REQUEST_TYPE:
            printf("This should never happen!!\n");
            break;
    }
    settings_save(s);
    apply_settings_to_gui(s);

    settings_free(s);
    update_output_file();
}