how to get battery level of the dji remote controller in android app (built using android studio – java)?

huangapple go评论69阅读模式
英文:

how to get battery level of the dji remote controller in android app (built using android studio - java)?

问题

以下是翻译好的部分:

the code below i am able to retrieve serial number of the dji drone remote controller. however, I cannot get battery level. is there anyway I can retrieve battery level? please advise.

下面的代码可以检索 DJI 无人机遥控器的序列号。然而,我无法获取电池电量。有没有办法可以获取电池电量?请提供建议。

the code for serial number (which is fine):

序列号的代码(这部分正常):

public void getSerialNumber(CommonCallbacks.CompletionCallbackWith<String> callback)
{
if(baseProduct != null && baseProduct.isConnected()) {
if (baseProduct instanceof Aircraft) {
((Aircraft) baseProduct).getFlightController().getSerialNumber(callback);
}
else callback.onFailure(null);
}
else callback.onFailure(null);
}

the code for remaining battery (which doesn't work):

剩余电池的代码(这部分不起作用):

public void getBatteryLevel(CommonCallbacks.CompletionCallbackWith<Integer> callback)
{
if(baseProduct != null && baseProduct.isConnected()) {
if (baseProduct instanceof Aircraft) {
((Aircraft) baseProduct).getBattery().getChargeRemaining(callback);
}
else callback.onFailure(null);
}
else callback.onFailure(null);
}

英文:

with the code below i am able to retrieve serial number of the dji drone remote controller. however, I cannot get battery level. is there anyway I can retrieve battery level? please advise.

the code for serial number (which is fine):

public void getSerialNumber(CommonCallbacks.CompletionCallbackWith&lt;String&gt; callback)
    {
        if(baseProduct != null &amp;&amp; baseProduct.isConnected()) {
            if (baseProduct instanceof Aircraft) {
                ((Aircraft) baseProduct).getFlightController().getSerialNumber(callback);
            }
            else callback.onFailure(null);
        }
        else callback.onFailure(null);
    }

the code for remaining battery (which doesn't work):

public void getBatteryLevel(CommonCallbacks.CompletionCallbackWith&lt;Integer&gt; callback)
    {
        if(baseProduct != null &amp;&amp; baseProduct.isConnected()) {
            if (baseProduct instanceof Aircraft) {
                ((Aircraft) baseProduct).getBattery().getChargeRemaining(callback);
            }
            else callback.onFailure(null);
        }
        else callback.onFailure(null);
    }

答案1

得分: 1

你提供的代码看起来是正确的,假设baseProduct是对您的DJI遥控器的有效引用。

但是,要获取遥控器的电池电量,您需要调用getRemoteControllerBatteryInfo方法,而不是getBatteryLevel,如下所示:

public void getBatteryLevel(CommonCallbacks.CompletionCallbackWith<Integer> callback) {
    if (baseProduct != null && baseProduct.isConnected()) {
        if (baseProduct instanceof Aircraft) {
            ((Aircraft) baseProduct).getRemoteController().getBatteryInfo().getChargeRemainingInPercent(callback);
        } else {
            callback.onFailure(null);
        }
    } else {
        callback.onFailure(null);
    }
}

这将返回遥控器的电池电量,作为介于0和100之间的整数,表示剩余充电的百分比。

确保您的应用程序具有访问DJI SDK函数所需的权限,并在调用此方法之前,遥控器已连接到飞行器并打开。

英文:

The code you have provided looks correct, assuming that baseProduct is a valid reference to your DJI remote controller.

However, to get the battery level of the remote controller, you need to call the getRemoteControllerBatteryInfo method instead of getBatteryLevel as follows:

public void getBatteryLevel(CommonCallbacks.CompletionCallbackWith&lt;Integer&gt; callback) {
    if (baseProduct != null &amp;&amp; baseProduct.isConnected()) {
        if (baseProduct instanceof Aircraft) {
            ((Aircraft) baseProduct).getRemoteController().getBatteryInfo().getChargeRemainingInPercent(callback);
        } else {
            callback.onFailure(null);
        }
    } else {
        callback.onFailure(null);
    }
}

This will return the battery level of the remote controller as an integer between 0 and 100, representing the percentage of charge remaining.

Make sure that your app has the necessary permissions to access the DJI SDK functions, and that the remote controller is connected to the aircraft and turned on before calling this method.

huangapple
  • 本文由 发表于 2023年4月4日 18:04:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75928080.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定