-
Notifications
You must be signed in to change notification settings - Fork 15
RC Battery List Item Widget
The RCBatteryListItemWidget displays the percent battery remaining in the attached Remote Controller. It displays a value even if an aircraft is not currently connected to the remote controller.
If the battery is below the low battery threshhold for that controller, the percent remaining will display in the warning color.
The following are the three states for the widget:
Disconnected
Normal
Low Battery
To add the RC Battery widget to your DUXBetaSmartListModel class, override buildModelLists and include DUXBetaRCBatteryListItemWidget() or [DUXBetaFlightModeWidget duxbeta_className] in your modelClassnameList:
@objc open class MySmartListModel : DUXBetaSmartListModel {
@objc open override func buildModelLists() {
super.buildModelLists()
self.modelClassnameList.append(DUXBetaRCBatteryListItemWidget.duxbeta_className())
}
}
@interface DUXBetaTestSmartListModel : DUXBetaSmartListModel
@end
@implementation DUXBetaTestSmartListModel
- (void)buildModelLists {
[super buildModelLists];
[self.modelClassnameList append:[DUXBetaRCBatteryListItemWidget duxbeta_className]];
}
@end
The UI elements can be customized to match the style of the user's application. The widget supports all the customizations that its parent, DUXBetaListItemLabelOnly, supports and also adds the customization for the low battery color. An example of a customized RC battery list item widget showing a custom low battery color could look something like this:
-
var warningValueColor: UIColor
- The text color of the battery percent when below the threshold limit, by defaultuxsdk_danger
. -
var normalValueColor: UIColor
- The text color of the value in a normal state, by defaultwhite
. -
var disconnectedValueColor: UIColor
- The text color of the value in a normal state, by defaultuxsdk_disabledGrayWhite58
.
Low Battery
To get this effect we would use the following code:
rcBatteryWidget.labelTextColorLowBattery = .yellow
rcBatteryWidget.labelTextColorLowBattery = UIColor.yellowColor;
The widget provides hooks for the users to add functionality based on the state changes in the widget. The RCBatteryListItemWidget provides the following hooks
-
RCBatteryItemModelState
- Provides a hook for changes to the remote controller battery state from the widget model. It inherits from ListItemLabelButtonModelState and adds the following hooks:
-
+ (instancetype)rcBatteryStateUpdated:(DJIRCBatteryState)batteryState;
- Event when the battery state is updated by connecting/disconecting or battery level changing. The DJIRCBatteryState is converted into a dictionary for easy of processing, with 3 values.-
remainingChargeInPercent
- An NSNumber 0-100 -
remainingChargeInmAh
- An NSNumber value -
isCharging
- An NSNumber containing a boolean value indiating of the remote controller is plugged in and charging.
-
DJI UX SDK Version 5 Beta 4.1