The firmware of the Grove Node
Dependencies: BLE_API color_pixels mbed-src-nrf51822 nRF51822
Fork of BLE_LoopbackUART by
color_led_strip.cpp
00001 00002 #include "udriver.h" 00003 #include "mbed.h" 00004 #include "color_pixels.h" 00005 00006 int color_led_strip_init(void *obj, void *params) 00007 { 00008 int pin = *(int *)params; 00009 int num = *((int *)params + 2); 00010 if (num == 0) { 00011 num = 30; 00012 } 00013 ColorPixels *ptr = new ColorPixels(pin, num); 00014 *((ColorPixels **)obj) = ptr; 00015 00016 ptr->set_all_color(0, 0, 125); 00017 00018 return 0; 00019 } 00020 00021 00022 int color_led_strip_read(void *obj, void *data) 00023 { 00024 return 0; 00025 } 00026 00027 int color_led_strip_write(void *obj, void *data) 00028 { 00029 ColorPixels *pixels = *(ColorPixels **)obj; 00030 float *params = (float *)data; 00031 uint8_t red = params[0]; 00032 uint8_t green = params[1]; 00033 uint8_t blue = params[2]; 00034 uint8_t mode = params[3]; 00035 00036 // printf("r: %d, g: %d, b: %d, mode: %d\n", red, green, blue, mode); 00037 if (mode == 0) { 00038 pixels->set_all_color(red, green, blue); 00039 } else if (mode == 1) { 00040 pixels->rainbow(red, green, blue); 00041 } 00042 00043 return 0; 00044 } 00045 00046 int color_led_strip_fini(void *obj) 00047 { 00048 ColorPixels *ptr = *(ColorPixels **)obj; 00049 delete ptr; 00050 00051 return 0; 00052 } 00053 00054 driver_t color_led_strip_driver = 00055 { 00056 .init = color_led_strip_init, 00057 .read = color_led_strip_read, 00058 .write = color_led_strip_write, 00059 .fini = color_led_strip_fini, 00060 00061 .d = 4, 00062 };
Generated on Fri Jul 15 2022 20:43:51 by 1.7.2