Exemple #1
0
// Read specified config file.
enum fsqlf_status fsqlf_kwmap_conffile_read(struct fsqlf_kw_conf *kwall, const char *file)
{
    FILE *config_file = fopen(file, "r");
    if (!config_file) {
        return FSQLF_FAIL;
    }

    char line[FSQLF_CONFFILE_LINELENGTH+1];
    char setting_name[FSQLF_CONFFILE_LINELENGTH+1];

    while (fgets(line, FSQLF_CONFFILE_LINELENGTH, config_file)) {
        // Lines starting with '#' are comments: skip them.
        // If line doesn't fit into buffer, it is invalid: skip it.
        if (line[0] == '#' || !strchr(line, '\n')) {
            do {
                // Skip chunks until new line is found
                if (!fgets(line, FSQLF_CONFFILE_LINELENGTH, config_file)) break;
            } while (!strchr(line, '\n'));
            // Skip that also, as it is continuation
            // of same line that we want to skip
            continue;
        }

        size_t llen = strlen(line);

        // Read setting name.
        char *space_ptr = strchr(line, ' ');
        if (!space_ptr) continue;
        space_ptr[0] = '\0';
        strncpy(setting_name, line, FSQLF_CONFFILE_LINELENGTH);

        // Read numeric setting values.
        // nl before, tab before, space before, nl after, tab after, space after
        char *pos = space_ptr + 1; // Skip \0 char.
        llen -= pos - line;
        const int VALUE_COUNT = 8;
        int setting_values[VALUE_COUNT];
        size_t cnt = FSQLF_read_int_array(pos, llen, VALUE_COUNT, setting_values);
        if (cnt == 0) {
            continue;
        }
        set_from_array(kwall, setting_name, setting_values);
    }

    fclose(config_file);
    return FSQLF_OK;
}
/*
 * This sets up the auto-cycling features of the controllers to make a
 * semi-random pattern of slowly fading colors. This is interesting only
 * because it doesn't require any effort from the EC.
*/
void lb_start_builtin_cycle(void)
{
	int r = scale(255, MAX_RED);
	int g = scale(255, MAX_BLUE);
	int b = scale(255, MAX_GREEN);
	struct initdata_s pulse_vals[] = {
		{0x11, 0xce},
		{0x12, 0x67},
		{0x13, 0xef},
		{0x15, b},
		{0x16, r},
		{0x17, g},
		{0x18, b},
		{0x19, r},
		{0x1a, g},
	};

	set_from_array(pulse_vals, ARRAY_SIZE(pulse_vals));
	controller_write(1, 0x13, 0xcd);	/* this one's different */
}
/* Initialize the controller ICs after reset */
void lb_init(void)
{
	CPRINTS("LB_init_vals");
	set_from_array(init_vals, ARRAY_SIZE(init_vals));
	memset(current, 0, sizeof(current));
}