예제 #1
0
static int ini_handler(void* user, const char* section, const char* name, const char* value)
{
    struct Transmitter *t = (struct Transmitter *)user;

    s32 value_int = atoi(value);
    if (section[0] == '\0') {
        if (MATCH_KEY(CURRENT_MODEL)) {
            t->current_model = value_int;
            return 1;
        }
        if (MATCH_KEY(LANGUAGE)) {
            t->language = value_int;
            return 1;
        }
	if (MATCH_KEY(MUSIC_SHUTD)) {
            t->music_shutdown = atoi(value);
            return 1;
        }
        if (MATCH_KEY(MODE)) {
            t->mode = atoi(value);
            return 1;
        }
        if (MATCH_KEY(BRIGHTNESS)) {
            t->brightness = atoi(value);
            return 1;
        }
        if (MATCH_KEY(CONTRAST)) {
            t->contrast = atoi(value);
            return 1;
        }
        if (MATCH_KEY(VOLUME)) {
            t->volume = atoi(value);
            return 1;
        }
        if (MATCH_KEY(VIBRATION)) {
            t->vibration_state = atoi(value);
            return 1;
        }
        if (MATCH_KEY(POWER_ALARM)) {
            t->power_alarm = atoi(value);
            return 1;
        }
        if (MATCH_KEY(BATT_ALARM)) {
            t->batt_alarm = atoi(value);
            return 1;
        }
        if (MATCH_KEY(BATT_CRITICAL)) {
            t->batt_critical = atoi(value);
            return 1;
        }
	if (MATCH_KEY(BATT_WARNING_INTERVAL)) {
            t->batt_warning_interval = atoi(value);
            return 1;
        }
	if (MATCH_KEY(SPLASH_DELAY)) {
            t->splash_delay = atoi(value);
            return 1;
        }
    #if HAS_RTC
        if (MATCH_KEY(TIME_FORMAT)) {
            t->rtcflags = (t->rtcflags & ~TIMEFMT) | (atoi(value) & TIMEFMT);
            return 1;
        }
        if (MATCH_KEY(DATE_FORMAT)) {
            t->rtcflags = (t->rtcflags & ~DATEFMT) | ((atoi(value) << 4) & DATEFMT);
            return 1;
        }
    #endif
    }
    if(MATCH_START(section, SECTION_CALIBRATE) && strlen(section) >= sizeof(SECTION_CALIBRATE)) {
        uint8_t idx = atoi(section + sizeof(SECTION_CALIBRATE)-1);
        if (idx == 0) {
            printf("%s: Unknown Calibration\n", section);
            return 0;
        }
        if (idx > INP_HAS_CALIBRATION) {
            printf("%s: Only %d calibrations are supported\n", section, INP_HAS_CALIBRATION);
            return 1;
        }
        idx--;
        if (MATCH_KEY(CALIBRATE_MAX)) {
            t->calibration[idx].max = value_int;
            return 1;
        }
        if (MATCH_KEY(CALIBRATE_MIN)) {
            t->calibration[idx].min = value_int;
            return 1;
        }
        if (MATCH_KEY(CALIBRATE_ZERO)) {
            t->calibration[idx].zero = value_int;
            return 1;
        }
    }
    if (MATCH_SECTION(SECTION_TOUCH)) {
        if (MATCH_KEY(TOUCH_XSCALE)) {
            t->touch.xscale = value_int;
            return 1;
        }
        if (MATCH_KEY(TOUCH_YSCALE)) {
            t->touch.yscale = value_int;
            return 1;
        }
        if (MATCH_KEY(TOUCH_XOFFSET)) {
            t->touch.xoffset = value_int;
            return 1;
        }
        if (MATCH_KEY(TOUCH_YOFFSET)) {
            t->touch.yoffset = value_int;
            return 1;
        }
    }
    if (MATCH_SECTION(SECTION_AUTODIMMER)) {
        if (MATCH_KEY(AUTODIMMER_TIME)) {
            t->auto_dimmer.timer = value_int;
            return 1;
        }
        if (MATCH_KEY(AUTODIMMER_DIMVALUE)) {
            t->auto_dimmer.backlight_dim_value = value_int;
            return 1;
        }
    }
    if (MATCH_SECTION(SECTION_TIMERSETTINGS)) {
        if (MATCH_KEY(TIMERSETTINGS_PREALERT_TIME)) {
            t->countdown_timer_settings.prealert_time = value_int;
            return 1;
        }
        if (MATCH_KEY(TIMERSETTINGS_PREALERT_INTERVAL)) {
            t->countdown_timer_settings.prealert_interval = value_int;
            return 1;
        }
        if (MATCH_KEY(TIMERSETTINGS_TIMEUP_INTERVAL)) {
            t->countdown_timer_settings.timeup_interval = value_int;
            return 1;
        }
    }
    if (MATCH_SECTION(SECTION_TELEMETRY)) {
        if (MATCH_KEY(TELEM_TEMP)) {
            if(strcasecmp(TELEM_TEMP_VAL[1], value) == 0)
                t->telem |= TELEMUNIT_FAREN;
            return 1;
        }
        if (MATCH_KEY(TELEM_LENGTH)) {
            if(strcasecmp(TELEM_LENGTH_VAL[1], value) == 0)
                t->telem |= TELEMUNIT_FEET;
            return 1;
        }
    }
    printf("Unknown values section: %s key: %s\n", section, name);
    return 0;
}
예제 #2
0
int ini_file_handler (void* pconfig, const char* section,
        const char* key, const char* value)
{
#define MATCH_SECTION(s) strcmp(section, s) == 0
#define MATCH_KEY(s) strcmp(key,s) == 0
    configuration* config = (configuration*)pconfig;
    int handled = 1;
    if (MATCH_SECTION("listen")) {
        if (MATCH_KEY("ip")) {
            config->listen_ip = strdup(value);
        } else if (MATCH_KEY("port")) {
            config->listen_port = atoi(value);
        } else if (MATCH_KEY("visible")) {
            config->listen_visible = atoi(value);
        } else if (MATCH_KEY("debuginfo")) {
            config->listen_debuginfo = atoi(value);
        } else {
            handled = 0;
        }
    } else if (MATCH_SECTION("gae")) {
        if (MATCH_KEY("appid")) {
            config->gae_appid = strdup(value);
        } else if (MATCH_KEY("password")) {
            config->gae_password = strdup(value);
        } else if (MATCH_KEY("path")) {
            config->gae_path = strdup(value);
        } else if (MATCH_KEY("profile")) {
            config->gae_profile = strdup(value);
        } else if (MATCH_KEY("crlf")) {
            config->gae_crlf = atoi(value);
        } else if (MATCH_KEY("validate")) {
            config->gae_validate = atoi(value);
        } else {
            handled = 0;
        }
    } else if (strstr(section,"google_") == section) {
        profile* p = find_profile(section,config,1);
        if (MATCH_KEY("mode")) {
            p->mode = strdup(value);
        } else if (MATCH_KEY("window")) {
            p->window = atoi(value);
        } else if (MATCH_KEY("hosts")) {
            p->hosts = strdup(value);
        } else if (MATCH_KEY("sites")) {
            p->sites = strdup(value);
        } else if (MATCH_KEY("forcehttps")) {
            p->forcehttps = strdup(value);
        } else if (MATCH_KEY("withgae")) {
            p->withgae = strdup(value);
        } else if (MATCH_KEY("withdns")) {
            p->withdns = strdup(value);
        } else {
            handled = 0;
        }
    } else if (MATCH_SECTION("crlf")) {
        if (MATCH_KEY("enable")) {
            config->crlf_enable = atoi(value);
        } else if (MATCH_KEY("dns")) {
            config->crlf_dns = strdup(value);
        } else if (MATCH_KEY("sites")) {
            config->crlf_sites = strdup(value);
        }
    }
    if (!handled) {
        fprintf(stderr,"Unrecognized section:%s key:%s\r\n", section, key);
    }
    return 1;
}