diff --git a/cli.cpp b/cli.cpp index ce513fee..fb360180 100644 --- a/cli.cpp +++ b/cli.cpp @@ -28,6 +28,7 @@ using namespace std::chrono_literals; static std::string profile_save_filename = ""; const unsigned int brightness_percentage = 100; +const unsigned int speed_percentage = 100; enum { @@ -47,6 +48,7 @@ struct DeviceOptions int zone = -1; std::vector> colors; std::string mode; + unsigned int speed = 100; unsigned int brightness = 100; unsigned int size; bool random_colors = false; @@ -397,7 +399,8 @@ void OptionHelp() help_text += " If there are more LEDs than colors given, the last color will be applied to the remaining LEDs\n"; help_text += "-m, --mode [breathing | static | ...] Sets the mode to be applied, check --list-devices to see which modes are supported on your device\n"; help_text += "-b, --brightness [0-100] Sets the brightness as a percentage if the mode supports brightness\n"; - help_text += "-s, --size [0-N] Sets the new size of the specified device zone.\n"; + help_text += "-s, --speed [0-100] Sets the speed as a percentage if the mode supports speed\n"; + help_text += "-sz, --size [0-N] Sets the new size of the specified device zone.\n"; help_text += " Must be specified after specifying a zone.\n"; help_text += " If the specified size is out of range, or the zone does not offer resizing capability, the size will not be changed\n"; help_text += "-V, --version Display version and software build information\n"; @@ -718,6 +721,42 @@ bool OptionMode(std::vector* current_devices, std::string argumen return found; } +bool OptionSpeed(std::vector* current_devices, std::string argument, Options* options) +{ + if(argument.size() == 0) + { + std::cout << "Error: --speed passed with no argument" << std::endl; + return false; + } + + /*---------------------------------------------------------*\ + | If a device is not selected i.e. size() == 0 | + | then add speed to allDeviceOptions | + \*---------------------------------------------------------*/ + bool found = false; + DeviceOptions* currentDevOpts = &options->allDeviceOptions; + + if(current_devices->size() == 0) + { + currentDevOpts->speed = std::min(std::max(std::stoi(argument), 0),(int)speed_percentage); + currentDevOpts->hasOption = true; + found = true; + } + else + { + for(size_t i = 0; i < current_devices->size(); i++) + { + DeviceOptions* currentDevOpts = ¤t_devices->at(i); + + currentDevOpts->speed = std::min(std::max(std::stoi(argument), 0),(int)speed_percentage); + currentDevOpts->hasOption = true; + found = true; + } + } + + return found; +} + bool OptionBrightness(std::vector* current_devices, std::string argument, Options* options) { if(argument.size() == 0) @@ -956,9 +995,22 @@ int ProcessOptions(int argc, char* argv[], Options* options, std::vector& rgb_cont device->modes[mode].brightness = device->modes[mode].brightness_min + new_brightness; } + if((device->modes[mode].flags & MODE_FLAG_HAS_SPEED)) + { + unsigned int new_speed = device->modes[mode].speed_max - device->modes[mode].speed_min; + new_speed *= options.speed; + new_speed /= speed_percentage; + + device->modes[mode].speed = device->modes[mode].speed_min + new_speed; + } + /*---------------------------------------------------------*\ | Determine which color mode this mode uses and update | | colors accordingly | @@ -1160,7 +1221,8 @@ void ApplyOptions(DeviceOptions& options, std::vector& rgb_cont } else { - std::cout << "Wrong number of colors specified for mode" << std::endl; + std::cout << "Wrong number of colors specified for mode " + device->modes[mode].name << std::endl; + std::cout << "Please provide between " + std::to_string(device->modes[mode].colors_min) + " and " + std::to_string(device->modes[mode].colors_min) + " colors" << std::endl; exit(0); } break;