Recharging service
For devices with a charging station, the recharging service provides the ability for the API to call the device to connect and disconnect to the charging station. As a recharging service access agent, RechargingManager provides the main API of the recharging service, which can be obtained through the RobotContext object.
RechargingManager rechargingManager = robotContext.getSystemService(RechargingManager.SERVICE);
Connect to the charging station
When the device is connected to the charging station, the charging function is automatically started, which can be achieved using the following methods:
promise /* [1] */ = rechargingManager.connectToStation() .progress(new ProgressCallback<ConnectingProgress>() { @Override public void onProgress(ConnectingProgress connectingProgress /* [2] */ ) { // Callback the progress of the calling } }) .done(new DoneCallback<Void>() { @Override public void onDone(Void aVoid) { //Callback if the calling is completed } }) .fail(new FailCallback<RechargingException>() { @Override public void onFail(RechargingException e) { // Callback if the calling has failed } });
[1]Return the asynchronous object that is waiting for the progress of the connection. This object can wait for or monitor the progress, and cancel the charging process. For concrete usage, please refer to [Promise[.
[2] TheConnectingProgressobject of theasynchronous callback describes the progress information for charging station connection, including:
| Attribute getter | Descriptions |
|---|---|
| progress | Connection progress type |
| Constants | Descriptions |
|---|---|
| PROGRESS_BEGAN | Start to connect to the charging station |
| PROGRESS_ENDED | Stop connecting to the charging station |
By specifying parameters, you can set the timeout duration for the charging station connection:
rechargingManager.connectToStation( new ConnectingOption.Builder().setTimeout(10).build() /* [1] */);
[1] The ConnectingOption object is constructed through ConnectingOption.Builder, and the instructions are as follows:
| Descriptions | Default value |
|---|---|
| Constructor function | |
| Set timeout duration, unit: second | -1 (do not time out) |
To know whether the device is charging, use the following code:
boolean isCharging = rechargingManager.isConnectedToStation();
Disconnect from the charging station
If you need to disconnect from the charging station during charging, you can use the following code:
rechargingManager.disconnectFromStation();
Note: This interface is an asynchronous interface, it also has progress and exception notifications. The connection is similar to the operation of connecting to a charging station.