void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
{
    if (record->event.pressed) {
        switch (id) {
            case AF_RGB_ON:
                rgb_on();
                break;
            case AF_RGB_OFF:
                rgb_off();
                break;
            case AF_RGB_TOGGLE:
                rgb_toggle();
                break;
            case AF_RGB_INCREASE:
                rgb_increase();
                break;
            case AF_RGB_DECREASE:
                rgb_decrease();
                break;
            case AF_RGB_FIXED:
                rgb_set(RGB_FIXED, opt);
                break;
            case AF_RGB_VARIABLE:
                rgb_set(RGB_VARIABLE, opt);
                break;
            case AF_RGB_STEP:
                rgb_step(opt);
                break;
        }
    }
}
Example #2
0
i2c_config ICACHE_FLASH_ATTR *rgb_init(uint8 *address, i2c_status *status) {
    i2c_config *config = NULL;

    *status = I2C_OK;
    if (*address == 0) {
        *address = MOD_RGB_DEFAULT_ADDR;
    }

    config = i2c_find_config(*address, MOD_RGB_ID);

    /* Check if there is device at address */
    if (i2c_check_device(*address) != I2C_OK) {
        *status = I2C_DEVICE_NOT_FOUND;
        return config;
    }

    uint8 id;

    /* Check if device is MOD-RGB */
    if (i2c_read_id(*address, &id) != I2C_OK) {
        *status = I2C_COMMUNICATION_FAILED;
        return config;
    }

    if (id != MOD_RGB_ID) {
        *status = I2C_DEVICE_ID_DONT_MATCH;
        return config;
    }

    os_delay_us(1000);
    if (rgb_on(*address) != I2C_OK) {
        *status = I2C_COMMUNICATION_FAILED;
        return config;
    }

    if (config == NULL) {
        config = i2c_add_config(*address, MOD_RGB_ID, (void *)os_zalloc(sizeof(rgb_config_data)));
    }

    return config;
}