diff --git a/RGBController/E131ControllerDetect.cpp b/RGBController/E131ControllerDetect.cpp index 03a1a3fb0..266394136 100644 --- a/RGBController/E131ControllerDetect.cpp +++ b/RGBController/E131ControllerDetect.cpp @@ -15,6 +15,11 @@ #include #endif +#ifndef WIN32 +#define LPSTR char * +#define strtok_s strtok_r +#endif + /******************************************************************************************\ * * * DetectE131Controllers * @@ -35,30 +40,19 @@ void DetectE131Controllers(std::vector &rgb_controllers) #ifdef WIN32 GetModuleFileName(NULL, filename, 2048); strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str()); - strcat(filename, "\\settings.txt"); + strcat(filename, "\\e131.txt"); #else snprintf(arg1, 64, "/proc/%d/exe", getpid()); readlink(arg1, filename, 1024); strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str()); - strcat(filename, "/settings.txt"); + strcat(filename, "/e131.txt"); #endif E131Device dev; - - dev.name = "Test"; - dev.type = ZONE_TYPE_SINGLE; - dev.num_leds = 50; - dev.start_universe = 20; - dev.start_channel = 1; - std::vector devices; - - devices.push_back(dev); - new_controller = new RGBController_E131(devices); - rgb_controllers.push_back(new_controller); + bool new_device = false; -#if 0 //Open settings file infile.open(filename); @@ -66,10 +60,17 @@ void DetectE131Controllers(std::vector &rgb_controllers) { for (std::string line; std::getline(infile, line); ) { + if (new_device) + { + dev.name = line; + new_device = false; + } + if (line == "") { continue; } + if ((line[0] != ';') && (line[0] != '#') && (line[0] != '/')) { char * argument; @@ -85,15 +86,85 @@ void DetectE131Controllers(std::vector &rgb_controllers) if(argument) { - if (strcmp(argument, "ledstrip") == 0) + if (strcmp(argument, "e131_device_start") == 0) { - new_controller = new RGBController_LEDStrip(new_ledstrip); - rgb_controllers.push_back(new_controller); + new_device = true; + } + else if(strcmp(argument, "num_leds") == 0) + { + dev.num_leds = atoi(value); + } + else if(strcmp(argument, "start_universe") == 0) + { + dev.start_universe = atoi(value); + } + else if(strcmp(argument, "start_channel") == 0) + { + dev.start_channel = atoi(value); + } + else if(strcmp(argument, "rgb_order") == 0) + { + if(strcmp(value, "RGB") == 0) + { + dev.rgb_order = E131_RGB_ORDER_RGB; + } + else if(strcmp(value, "RBG") == 0) + { + dev.rgb_order = E131_RGB_ORDER_RBG; + } + else if(strcmp(value, "GRB") == 0) + { + dev.rgb_order = E131_RGB_ORDER_GRB; + } + else if(strcmp(value, "GBR") == 0) + { + dev.rgb_order = E131_RGB_ORDER_GBR; + } + else if(strcmp(value, "BRG") == 0) + { + dev.rgb_order = E131_RGB_ORDER_BRG; + } + else if(strcmp(value, "BGR") == 0) + { + dev.rgb_order = E131_RGB_ORDER_BGR; + } + else + { + dev.rgb_order = atoi(value); + } + } + else if(strcmp(argument, "type") == 0) + { + if(strcmp(value, "SINGLE") == 0) + { + dev.type = ZONE_TYPE_SINGLE; + } + else if(strcmp(value, "LINEAR") == 0) + { + dev.type = ZONE_TYPE_LINEAR; + } + else if(strcmp(value, "MATRIX") == 0) + { + dev.type = ZONE_TYPE_MATRIX; + } + else + { + dev.type = atoi(value); + } + } + else if(strcmp(argument, "e131_device_end") == 0) + { + devices.push_back(dev); } } } } + + if(devices.size() > 0) + { + new_controller = new RGBController_E131(devices); + rgb_controllers.push_back(new_controller); + } } -#endif } /* DetectLEDStripControllers() */ \ No newline at end of file diff --git a/RGBController/RGBController_E131.cpp b/RGBController/RGBController_E131.cpp index 78afcf8b1..5baa3dd4c 100644 --- a/RGBController/RGBController_E131.cpp +++ b/RGBController/RGBController_E131.cpp @@ -21,6 +21,8 @@ RGBController_E131::RGBController_E131(std::vector device_list) led_mode.name = "Custom"; modes.push_back(led_mode); + sockfd = e131_socket(); + for (int i = 0; i < devices.size(); i++) { /*-----------------------------------------*\ @@ -126,8 +128,6 @@ void RGBController_E131::SetLED(int led, RGBColor color) void RGBController_E131::UpdateLEDs() { - int sockfd = e131_socket(); - for(int device_idx = 0; device_idx < devices.size(); device_idx++) { unsigned int total_universes = ceil( ( ( devices[device_idx].num_leds * 3 ) + devices[device_idx].start_channel ) / 512.0f ); diff --git a/RGBController/RGBController_E131.h b/RGBController/RGBController_E131.h index b5193a354..fac3d3256 100644 --- a/RGBController/RGBController_E131.h +++ b/RGBController/RGBController_E131.h @@ -50,4 +50,5 @@ private: std::vector packets; std::vector dest_addrs; std::vector universes; + int sockfd; }; \ No newline at end of file