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; } } }
void ICACHE_FLASH_ATTR mod_rgb_handler( struct espconn *pConnection, request_method method, char *url, char *data, uint16 data_len, uint32 content_len, char *response, uint16 response_len ) { i2c_status status; i2c_config *config = i2c_init_handler(MOD_RGB, MOD_RGB_URL, rgb_init, url, response); if (config == NULL) { return; } rgb_config_data *config_data = (rgb_config_data *)config->data; struct jsonparse_state parser; int type; if (method == POST && data != NULL && data_len != 0) { jsonparse_setup(&parser, data, data_len); while ((type = jsonparse_next(&parser)) != 0) { if (type == JSON_TYPE_PAIR_NAME) { if (jsonparse_strcmp_value(&parser, "R") == 0) { jsonparse_next(&parser); jsonparse_next(&parser); config_data->red = jsonparse_get_value_as_int(&parser); } else if (jsonparse_strcmp_value(&parser, "G") == 0) { jsonparse_next(&parser); jsonparse_next(&parser); config_data->green = jsonparse_get_value_as_int(&parser); } else if (jsonparse_strcmp_value(&parser, "B") == 0) { jsonparse_next(&parser); jsonparse_next(&parser); config_data->blue = jsonparse_get_value_as_int(&parser); } } } } char address_str[MAX_I2C_ADDRESS]; json_i2c_address(address_str, config->address); status = rgb_set(config); if (status == I2C_OK) { char data_str[WEBSERVER_MAX_VALUE]; json_data( response, MOD_RGB, OK_STR, json_sprintf( data_str, "\"R\" : %d, \"G\" : %d, \"B\" : %d", config_data->red, config_data->green, config_data->blue ), address_str ); } else { json_error(response, MOD_RGB, i2c_status_str(status), address_str); } }
int main() { LPC_GPIO1->FIODIR = 1 << 18 | 1 << 27; LPC_GPIO0->FIODIR = 1 << 4 | 1 << 5 | 1 << 6; rgb_setup(); rgb_set(0x00,0xFF,00); motor_setup(); receiver_setup(); servo_setup(); //Initialize servo servo_steer(0); rgb_set(0xFF,0,0); int throttle = 0; int steering = 0; int rudder = 0; int elevator = 0; int speed = 0; int servo_position = .5; int stop = 0; while(1){ throttle = radio_data[0]; steering = radio_data[1]; rudder = radio_data[2]; elevator = radio_data[3]; if(throttle > 48000){ throttle = 48000; } if(throttle < 24000){ stop = 1; throttle = 24000; } else { stop = 0; } steering = clip(steering); rudder = clip(rudder); elevator = clip(elevator); speed = (throttle-24000) / 2400; servo_position = (steering-24000) / 2400; printf("1:["); int i = 0; while(i < 11){ if(i == speed){ printf("|"); } else { printf(" "); } i++; } printf("] 2:["); i = 0; while(i < 11){ if(i == servo_position){ printf("o"); } else { printf(" "); } i++; } printf("] 3:["); i = 0; while(i < 11){ if(i == (rudder-24000) / 2400){ printf("|"); } else { printf(" "); } i++; } printf("] 4:["); i = 0; while(i < 11){ if(i == (elevator-24000) / 2400){ printf("|"); } else { printf(" "); } i++; } if(radio_data[4] < 32000){ printf("][v]"); } else if(radio_data[4] < 40000){ printf("][-]"); } else { printf("][^]"); } if(radio_data[5] < 32000){ printf("[v]"); } else if(radio_data[5] < 40000){ printf("[-]"); } else { printf("[^]"); } if(radio_data[6] < 32000){ printf("[v]"); } else if(radio_data[6] < 40000){ printf("[-]"); } else { printf("[^]"); } if(radio_data[7] < 32000){ printf("[v]"); } else if(radio_data[7] < 40000){ printf("[-]"); } else { printf("[^]"); } printf("\r\n"); delay_ms(5); } return 0; }