Skip to content

RC Battery List Item Widget

Cristina Suciu edited this page Dec 23, 2020 · 1 revision

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

Usage

To add the RC Battery widget to your DUXBetaSmartListModel class, override buildModelLists and include DUXBetaRCBatteryListItemWidget() or [DUXBetaFlightModeWidget duxbeta_className] in your modelClassnameList:

Swift Example

@objc open class MySmartListModel : DUXBetaSmartListModel {
    @objc open override func buildModelLists() {
        super.buildModelLists()
        self.modelClassnameList.append(DUXBetaRCBatteryListItemWidget.duxbeta_className())
    }
}

ObjC Example

@interface DUXBetaTestSmartListModel : DUXBetaSmartListModel
@end

@implementation DUXBetaTestSmartListModel
- (void)buildModelLists {
    [super buildModelLists];
    [self.modelClassnameList append:[DUXBetaRCBatteryListItemWidget duxbeta_className]];
}
@end

Customizations

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 default uxsdk_danger.
  • var normalValueColor: UIColor - The text color of the value in a normal state, by default white.
  • var disconnectedValueColor: UIColor - The text color of the value in a normal state, by default uxsdk_disabledGrayWhite58.

Low Battery

To get this effect we would use the following code:

Swift Example

rcBatteryWidget.labelTextColorLowBattery = .yellow

ObjC Example

rcBatteryWidget.labelTextColorLowBattery = UIColor.yellowColor;

Hooks

The widget provides hooks for the users to add functionality based on the state changes in the widget. The RCBatteryListItemWidget provides the following hooks

  1. 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.
Clone this wiki locally