Search in sources :

Example 1 with RobotConfigNameable

use of com.qualcomm.robotcore.hardware.RobotConfigNameable in project robotcode by OutoftheBoxFTC.

the class LynxModule method getHealthStatusWarningMessage.

/**
 * Returns a status warning message indicative of the health of the indicated device, or an
 * empty string if no such message is currently applicable.
 */
@NonNull
public static String getHealthStatusWarningMessage(HardwareDeviceHealth hardwareDeviceHealth) {
    switch(hardwareDeviceHealth.getHealthStatus()) {
        case UNHEALTHY:
            String name = null;
            if (hardwareDeviceHealth instanceof RobotConfigNameable) {
                name = ((RobotConfigNameable) hardwareDeviceHealth).getUserConfiguredName();
                if (name != null) {
                    name = AppUtil.getDefContext().getString(R.string.quotes, name);
                }
            }
            if (name == null && hardwareDeviceHealth instanceof HardwareDevice) {
                HardwareDevice hardwareDevice = (HardwareDevice) hardwareDeviceHealth;
                String typeDescription = hardwareDevice.getDeviceName();
                String connectionInfo = hardwareDevice.getConnectionInfo();
                name = AppUtil.getDefContext().getString(R.string.hwDeviceDescriptionAndConnection, typeDescription, connectionInfo);
            }
            if (name == null) {
                name = AppUtil.getDefContext().getString(R.string.hwPoorlyNamedDevice);
            }
            return AppUtil.getDefContext().getString(R.string.unhealthyDevice, name);
        default:
            return "";
    }
}
Also used : RobotConfigNameable(com.qualcomm.robotcore.hardware.RobotConfigNameable) HardwareDevice(com.qualcomm.robotcore.hardware.HardwareDevice) NonNull(android.support.annotation.NonNull)

Aggregations

NonNull (android.support.annotation.NonNull)1 HardwareDevice (com.qualcomm.robotcore.hardware.HardwareDevice)1 RobotConfigNameable (com.qualcomm.robotcore.hardware.RobotConfigNameable)1