Search in sources :

Example 1 with DigitalPortEnum

use of com.robo4j.hw.lego.enums.DigitalPortEnum in project robo4j by Robo4J.

the class InfraSensorUnit method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    setState(LifecycleState.UNINITIALIZED);
    scanInitialDelay = configuration.getInteger(PROPERTY_SCAN_INIT_DELAY, VALUE_SCAN_INIT_DELAY);
    scanPeriod = configuration.getInteger(PROPERTY_SCAN_PERIOD, VALUE_SCAN_PERIOD);
    String port = configuration.getString(PROPERTY_SENSOR_PORT, null);
    DigitalPortEnum sensorPort = DigitalPortEnum.getByType(port);
    target = configuration.getString(PROPERTY_TARGET, null);
    if (sensorPort == null) {
        throw new ConfigurationException("infraRed sensor port required: {S1,S2,S3,S4}");
    }
    if (target == null) {
        throw new ConfigurationException("infraRed sensor target required");
    }
    SensorProvider provider = new SensorProvider();
    sensor = new SensorWrapper<>(provider, sensorPort, SensorTypeEnum.INFRA);
    setState(LifecycleState.INITIALIZED);
}
Also used : SensorProvider(com.robo4j.hw.lego.provider.SensorProvider) ConfigurationException(com.robo4j.ConfigurationException) DigitalPortEnum(com.robo4j.hw.lego.enums.DigitalPortEnum)

Example 2 with DigitalPortEnum

use of com.robo4j.hw.lego.enums.DigitalPortEnum in project robo4j by Robo4J.

the class SonicSensorUnit method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    setState(LifecycleState.UNINITIALIZED);
    scanInitialDelay = configuration.getInteger(PROPERTY_SCAN_INIT_DELAY, VALUE_SCAN_INIT_DELAY);
    scanPeriod = configuration.getInteger(PROPERTY_SCAN_PERIOD, VALUE_SCAN_PERIOD);
    String port = configuration.getString(PROPERTY_SENSOR_PORT, null);
    DigitalPortEnum sensorPort = DigitalPortEnum.getByType(port);
    target = configuration.getString(PROPERTY_TARGET, null);
    if (sensorPort == null) {
        throw new ConfigurationException("sonic sensor port required: {S1,S2,S3,S4}");
    }
    if (target == null) {
        throw new ConfigurationException("sonic sensor target required");
    }
    SensorProvider provider = new SensorProvider();
    sensor = new SensorWrapper<>(provider, sensorPort, SensorTypeEnum.SONIC);
    setState(LifecycleState.INITIALIZED);
}
Also used : SensorProvider(com.robo4j.hw.lego.provider.SensorProvider) ConfigurationException(com.robo4j.ConfigurationException) DigitalPortEnum(com.robo4j.hw.lego.enums.DigitalPortEnum)

Aggregations

ConfigurationException (com.robo4j.ConfigurationException)2 DigitalPortEnum (com.robo4j.hw.lego.enums.DigitalPortEnum)2 SensorProvider (com.robo4j.hw.lego.provider.SensorProvider)2