当前位置: 首页>>代码示例>>Java>>正文


Java HardwareDevice类代码示例

本文整理汇总了Java中com.qualcomm.robotcore.hardware.HardwareDevice的典型用法代码示例。如果您正苦于以下问题:Java HardwareDevice类的具体用法?Java HardwareDevice怎么用?Java HardwareDevice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HardwareDevice类属于com.qualcomm.robotcore.hardware包,在下文中一共展示了HardwareDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
/**
 * Searches through this to find a {@link HardwareDevice} with the given name. If there are more
 * than one {@code HardwareDevice}s with the given name, the first one found is the one
 * returned.
 *
 * @param name a non-null, non-empty <code>String</code> to use to match to a HardwareDevice
 * @return a HardwareDevice with the given name
 * @throws RuntimeException         if the HardwareDevice cannot be cast to the correct form
 * @throws NullPointerException     if name is null or empty
 * @throws IllegalArgumentException if the a name with the given name cannot be found
 */
@NotNull
public <T extends HardwareDevice> T get(String name) throws RuntimeException {
    name = checkNotNull(Strings.emptyToNull(name));
    try {
        for (DeviceMap<? extends HardwareDevice> deviceMap : fullMap) {
            if (deviceMap.containsKey(name)) {
                //noinspection unchecked
                return (T) deviceMap.get(name);
            }
        }
    } catch (ClassCastException ex) {
        throw new RuntimeException("Incorrect cast occurred for the Hardware Device " +
                "with the name of " + name, ex);
    }

    throw new IllegalArgumentException("Device " + name + " was not found");
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:29,代码来源:ExtensibleHardwareMap.java

示例2: findNameFor

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
public String findNameFor(@NotNull HardwareDevice device) {
    if (!fullMap.containsKey(checkNotNull(device).getClass())) {
        throw new IllegalArgumentException("Unknown device type");
    }

    final DeviceMap<? extends HardwareDevice> hardwareDevices = fullMap.checkedGet(device.getClass());
    final Set<? extends Map.Entry<String, ? extends HardwareDevice>> hardwareDevicesSet = hardwareDevices.entrySet();
    if (hardwareDevices.containsValue(device)) {
        for (Map.Entry<String, ? extends HardwareDevice> testDevice : hardwareDevicesSet) {
            if (device.equals(testDevice.getValue())) {
                return testDevice.getKey();
            }
        }
    }

    throw new IllegalArgumentException("Unknown device");
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:18,代码来源:ExtensibleHardwareMap.java

示例3: init

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
@Override
public void init(RobotContext ctx) throws Exception {
    File file = new File("/sdcard/robots/sensorData.csv");
    file.getParentFile().mkdirs();
    fileWriter = Files.newWriter(file, Charsets.UTF_8);
    sensors.addAll(hardwareMap.colorSensors().values());
    sensors.addAll(hardwareMap.ultrasonicSensors().values());
    sensors.addAll(hardwareMap.analogInputs().values());
    sensors.addAll(hardwareMap.digitalChannels().values());
    sensors.addAll(hardwareMap.irSeekerSensors().values());

    StringBuilder builder = new StringBuilder();
    for (HardwareDevice device : sensors) {
        builder.append(device.toString());
        if (device instanceof ColorSensor) {
            for (int i = 0; i < 4; i++) {
                builder.append(',');
            }
        }
    }
    fileWriter.write(builder.toString());
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:23,代码来源:SensorPerformanceTest.java

示例4: mapUserI2cDevice

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
private void mapUserI2cDevice(HardwareMap map, DeviceManager deviceMgr, I2cController i2cController, DeviceConfiguration devConf) {
    if (!devConf.isEnabled()) return;
    UserSensorType userType = (UserSensorType) devConf.getType();
    HardwareDevice hardwareDevice = deviceMgr.createUserI2cDevice(i2cController, devConf.getPort(), userType);
    if (hardwareDevice != null) {
        // User-defined types don't live in read2 type-specific mapping, only in the overall one
        map.put(devConf.getName(), hardwareDevice);
    }
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:10,代码来源:XtensibleEventLoop.java

示例5: checkedGet

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
public <T extends HardwareDevice> DeviceMap<T> checkedGet(@NotNull Class<T> type) {
    if (!super.containsKey(type)) {
        throw new IllegalArgumentException("Map doesn't contain " + type.getSimpleName());
    }

    return (DeviceMap<T>) delegate.get(type);
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:8,代码来源:DeviceMultiMap.java

示例6: checkedPut

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
public <T extends HardwareDevice> DeviceMap<T> checkedPut(@NotNull Class<T> kClass, @NotNull DeviceMap<T> value) {
    if (super.containsKey(kClass)) {
        throw new IllegalArgumentException("Map already contains a reference for " + kClass.getSimpleName());
    }

    return (DeviceMap<T>) delegate.put(kClass, value);
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:8,代码来源:DeviceMultiMap.java

示例7: init

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
@Override
    @CallSuper
    public void init(RobotContext ctx, LinkedList<Object> out) throws Exception {
        hardwareMap = hardwareMap();
        gamepad1 = gamepad1();
        gamepad2 = gamepad2();
        telemetry = telemetry();

        if (child != null && childOpMode != null) {
            LinkedList<Field> fields = new LinkedList<>(Arrays.asList(childOpMode.getFields()));
            for (Field field : fields) {
//                DeviceMap map = getFromClass(field.getType());
//                if (map == null) {
//                    continue;
//                }
//
//                if (map.containsKey(field.getName())) {
//                    field.set(child, map.get(field.getName()));
//                }
                if (!field.isAnnotationPresent(Inject.class)) {
                    continue;
                }

                try {
                    field.setAccessible(true);
                    field.set(childOpMode, hardwareMap.get((Class<? extends HardwareDevice>) field.getType(), field.getName()));
                } catch (Exception ex) {
                    RobotLog.w("Failed to set device on a @Inject field " + field.getName() + " for \"" + childOpMode.getSimpleName() + "\"");
                }
            }
        }

        init(ctx);
    }
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:35,代码来源:SimpleOpMode.java

示例8: remove

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
public static <T extends HardwareDevice> void remove(HardwareMap.DeviceMapping<T> from, IFuncArg<Boolean, T> predicate, IAction<T> action) {
    List<String> names = new LinkedList<>();
    for (Map.Entry<String, T> pair : from.entrySet()) {
        T t = pair.getValue();
        if (predicate == null || predicate.value(t)) {
            names.add(pair.getKey());
            if (action != null) action.doAction(t);
        }
    }
    for (String name : names) {
        removeName(from, name);
    }
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:14,代码来源:Util.java

示例9: contains

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
public static <T extends HardwareDevice> boolean contains(HardwareMap.DeviceMapping<T> map, String name) {
    for (Map.Entry<String, T> pair : map.entrySet()) {
        if (pair.getKey().equals(name))
            return true;
    }
    return false;
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:8,代码来源:Util.java

示例10: getConnectionInfo

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
@Override
public String getConnectionInfo() {
    String sController = "anI2cController";
    if (this.controller instanceof HardwareDevice)
        sController = this.controller.getConnectionInfo();
    return String.format("%s; port: %d", sController, this.port);
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:TeamClutch2016,代码行数:8,代码来源:I2cDeviceOnI2cDeviceController.java

示例11: getUnderlyingMap

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
/**
 * Gets the {@link ImmutableMap} based off of a {@link ExtensibleHardwareMap}
 *
 * @return the {@code ImmutableMap} for the {@code ExtensibleHardwareMap}
 */
@NotNull
public ImmutableMap<Class<? extends HardwareDevice>,
            DeviceMap<? extends HardwareDevice>> getUnderlyingMap() {
    return deviceMap;
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:11,代码来源:ImmutableHardwareMap.java

示例12: delegate

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
@Override
protected Map<Class<? extends HardwareDevice>, DeviceMap<? extends HardwareDevice>> delegate() {
    return delegate;
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:5,代码来源:DeviceMultiMap.java

示例13: get

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
@Override
public DeviceMap<? extends HardwareDevice> get(@Nullable Object object) {
    throw new UnsupportedOperationException("Attempted to use get(); use checkedGet()");
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:5,代码来源:DeviceMultiMap.java

示例14: put

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
@Override
public DeviceMap<? extends HardwareDevice> put(@NotNull Class kClass, @NotNull DeviceMap value) {
    throw new UnsupportedOperationException("Attempted to use put(); use checkedPut()");
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:5,代码来源:DeviceMultiMap.java

示例15: providesHardwareDevices

import com.qualcomm.robotcore.hardware.HardwareDevice; //导入依赖的package包/类
@Provides
@VariableNamedProvider
public HardwareDevice providesHardwareDevices(String name) {
    checkState(isAttached(), "provider is not attached");
    return extensibleHardwareMap.get(name);
}
 
开发者ID:MHS-FIRSTrobotics,项目名称:RadicalRobotics2017,代码行数:7,代码来源:OpModeRunnerProvider.java


注:本文中的com.qualcomm.robotcore.hardware.HardwareDevice类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。