int main() { board_init(); uart_init(); esc_init(); rgbled_init(); rgbled_set(0xFF8000, 100); spektrum_init(); rgbled_set(0xFF8000, 100); xbee_init(); i2c_init(); alt_init(); mag_init(); mpu_init(); sonar_init(); ins_init(); inscomp_init(); altitude_init(); controller_init(); basestation_init(); flight_init(); controlpanel_run(); }
static int handle_post_rgb(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo) { coap_responsecode_t resp = COAP_RSPCODE_CHANGED; const char *str = (const char *) inpkt->payload.p; if (str[0] == '#') { color_str2rgb(&str[1], &rgb); rgbled_set(&led, &rgb); } return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->token, resp, COAP_CONTENTTYPE_TEXT_PLAIN, false); }
static int cmd_col(int argc, char **argv) { color_rgb_t col; if (argc < 4) { printf("usage: %s <r> <g> <b>\n", argv[0]); return 1; } col.r = (uint8_t)atoi(argv[1]); col.g = (uint8_t)atoi(argv[2]); col.b = (uint8_t)atoi(argv[3]); rgbled_set(&led, &col); return 0; }
int main(int argc, char* argv[]) { // Check if values for all colors where supplied if(argc != 4 and argc != 5) { std::cerr << "Usage: " << argv[0] << " RED GREEN BLUE [PORT]" << std::endl << std::endl << " RED, GREEN and BLUE must in the range of 0 to 255" << std::endl << " PORT is optional and defaults to /dev/ttyS0" << std::endl; return 1; } // Parse input int red_value = atoi(argv[1]); int green_value = atoi(argv[2]); int blue_value = atoi(argv[3]); // Check if port was specified const char* port = (argc == 5 ? argv[4] : "/dev/ttyS0"); // Check if input is valid if(red_value < 0 or red_value > 255 or green_value < 0 or green_value > 255 or blue_value < 0 or blue_value > 255) { std::cerr << "Error: Color values must be in the range of 0 to 255!"; return 1; } // Connect to led and change color. rgb_led_t led; if(rgbled_connect(&led, port) != 0) { std::cerr << "Error #" << errno << " while connecting to " << port << " : " << strerror(errno) << std::endl; return 1; } rgbled_set(&led, red_value, green_value, blue_value); if(rgbled_disconnect(&led) != 0) { std::cerr << "Error #" << errno << " while disconnecting from " << port << " : " << strerror(errno) << std::endl; return 1; } return 0; }
void led_thread(void) { msg_t msg; int ret; color_hsv_t hsv_0; color_hsv_t hsv_1; color_rgb_t rgb; float step_h = 1.0f; float step_s = 0.02f; float step_v = 0.02f; int step = 0; int state = 1; int limit = 1; color_rgb_t *sequ = cd_sequ; rgbled_t led; /* initialize RGB-LED */ rgbled_init(&led, PWM_0, 0, 1, 2); while (1) { /* see if something has come up */ if (state == limit) { notify_done(); ++state; } if (state >= limit) { ret = msg_receive(&msg); } else { ret = msg_try_receive(&msg); } /* if message was receive, act on it */ if (ret == 1) { printf("led: got message %i\n", msg.type); if (msg.type != last_cmd) { switch (msg.type) { case MSG_GAME_START: puts("led: starting game"); sequ = cd_sequ; state = 1; limit = GAME_LED_COUNTDOWN_LEN; last_cmd = msg.type; break; case MSG_GAME_SCORE: printf("led: displaying score: %i\n", (unsigned int)msg.content.value); if (PLAYER == msg.content.value) { puts("led: WIN sequence"); sequ = win_sequ; limit = GAME_LED_WIN_LEN; } else if (msg.content.value == GAME_STATE_DRAW) { puts("led: DRAW sequence"); sequ = draw_sequ; limit = GAME_LED_DRAW_LEN; } else { puts("led: LOSE sequence"); sequ = lose_sequ; limit = GAME_LED_LOSE_LEN; } state = 1; last_cmd = msg.type; break; } } } if (state < limit) { /* update color */ if (step == 0) { printf("led: setting color fr 0x%02x 0x%02x 0x%02x\n", sequ[state - 1].r, sequ[state - 1].g, sequ[state - 1].b); printf("led: setting color to 0x%02x 0x%02x 0x%02x\n", sequ[state].r, sequ[state].g, sequ[state].b); color_rgb2hsv(&sequ[state - 1], &hsv_0); color_rgb2hsv(&sequ[state ], &hsv_1); step_h = (hsv_0.h - hsv_1.h) / STEPS; step_s = (hsv_0.s - hsv_1.s) / STEPS; step_v = (hsv_0.v - hsv_1.v) / STEPS; printf("led: steps are h+= %i s+= %i v+= %i\n", (int)(step_h * 100),(int)(step_s * 100), (int)(step_v * 100)); } /* set color */ color_hsv2rgb(&hsv_0, &rgb); rgbled_set(&led, &rgb); ++step; hsv_0.h += step_h; hsv_0.s += step_s; hsv_0.v += step_v; /* check if transition is finished */ if (step == STEPS) { step = 0; ++state; } } /* wait for next step */ vtimer_usleep(PAUSE); } }