controlWhiteLedValue method

Future<bool> controlWhiteLedValue({
  1. int? whiteValue,
  2. int? timeValue,
  3. int? modeValue,
  4. int timeout = 5,
})

Implementation

Future<bool> controlWhiteLedValue(
    {int? whiteValue,
    int? timeValue,
    int? modeValue,
    int timeout = 5}) async {
  if (whiteValue == null && timeValue == null && modeValue == null) {
    return false;
  }

  bool? ret;

  if (whiteValue != null && timeValue == null && modeValue == null) {
    ret = await _command.writeCgi(
        "set_whiteled_value.cgi?whiteled=$whiteValue&",
        timeout: timeout);
  }

  if (whiteValue == null && timeValue != null && modeValue == null) {
    ret = await _command.writeCgi(
        "set_whiteled_value.cgi?ledtimes=$timeValue&",
        timeout: timeout);
  }

  if (whiteValue == null && timeValue == null && modeValue != null) {
    ret = await _command.writeCgi("set_whiteled_value.cgi?mode=$modeValue&",
        timeout: timeout);
  }

  if (whiteValue != null && timeValue != null && modeValue == null) {
    ret = await _command.writeCgi(
        "set_whiteled_value.cgi?whiteled=$whiteValue&ledtimes=$timeValue&",
        timeout: timeout);
  }

  if (whiteValue == null && timeValue != null && modeValue != null) {
    ret = await _command.writeCgi(
        "set_whiteled_value.cgi?ledtimes=$timeValue&mode=$modeValue&",
        timeout: timeout);
  }

  if (whiteValue != null && timeValue == null && modeValue != null) {
    ret = await _command.writeCgi(
        "set_whiteled_value.cgi?whiteled=$whiteValue&mode=$modeValue&",
        timeout: timeout);
  }

  if (whiteValue != null && timeValue != null && modeValue != null) {
    ret = await _command.writeCgi(
        "set_whiteled_value.cgi?whiteled=$whiteValue&ledtimes=$timeValue&mode=$modeValue&",
        timeout: timeout);
  }

  if (ret ?? false) {
    CommandResult result =
        await _command.waitCommandResult((int cmd, Uint8List data) {
      return true;
    }, timeout);
    if (result.isSuccess == true) {
      Map data = result.getMap();
      return data["result"] == "0";
    }
  }
  return false;
}