From d34aae4283c600ec8eee3381bddc5b8007aea6bc Mon Sep 17 00:00:00 2001 From: Miro Wengner Date: Wed, 9 Oct 2024 10:00:54 +0200 Subject: [PATCH] [69] logger update --- .../units/lego/BasicSonicSensorServoUnitMock.java | 14 ++++++++------ .../units/rpi/roboclaw/RoboClawUnitExample.java | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/robo4j-units-lego/src/test/java/com/robo4j/units/lego/BasicSonicSensorServoUnitMock.java b/robo4j-units-lego/src/test/java/com/robo4j/units/lego/BasicSonicSensorServoUnitMock.java index fc76999f..c5cbd134 100644 --- a/robo4j-units-lego/src/test/java/com/robo4j/units/lego/BasicSonicSensorServoUnitMock.java +++ b/robo4j-units-lego/src/test/java/com/robo4j/units/lego/BasicSonicSensorServoUnitMock.java @@ -17,39 +17,42 @@ package com.robo4j.units.lego; import com.robo4j.AttributeDescriptor; -import com.robo4j.ConfigurationException; import com.robo4j.RoboContext; import com.robo4j.configuration.Configuration; import com.robo4j.hw.lego.enums.DigitalPortEnum; import com.robo4j.hw.lego.enums.SensorTypeEnum; import com.robo4j.hw.lego.wrapper.SensorTestWrapper; import com.robo4j.units.lego.sonic.LegoSonicServoMessage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author Marcus Hirt (@hirt) * @author Miro Wengner (@miragemiko) */ +// TODO : verify usage public class BasicSonicSensorServoUnitMock extends BasicSonicServoUnit { + private static final Logger LOGGER = LoggerFactory.getLogger(BasicSonicSensorServoUnitMock.class); public BasicSonicSensorServoUnitMock(RoboContext context, String id) { super(context, id); } @Override - protected void onInitialization(Configuration configuration) throws ConfigurationException { + protected void onInitialization(Configuration configuration) { super.sensor = new SensorTestWrapper(DigitalPortEnum.S3, SensorTypeEnum.SONIC); - System.out.println("on initialization"); + LOGGER.info("on initialization"); } @Override public void onMessage(LegoSonicServoMessage message) { - System.out.println("onMessage : " + message); + LOGGER.info("onMessage : {}", message); } @Override public void shutdown() { super.shutdown(); - System.out.println("executor is down"); + LOGGER.info("executor is down"); } @SuppressWarnings("unchecked") @@ -62,5 +65,4 @@ public R onGetAttribute(AttributeDescriptor attribute) { } - } diff --git a/robo4j-units-rpi/src/examples/java/com/robo4j/units/rpi/roboclaw/RoboClawUnitExample.java b/robo4j-units-rpi/src/examples/java/com/robo4j/units/rpi/roboclaw/RoboClawUnitExample.java index eff5d100..df256201 100644 --- a/robo4j-units-rpi/src/examples/java/com/robo4j/units/rpi/roboclaw/RoboClawUnitExample.java +++ b/robo4j-units-rpi/src/examples/java/com/robo4j/units/rpi/roboclaw/RoboClawUnitExample.java @@ -60,7 +60,7 @@ public static void main(String[] args) throws RoboBuilderException, FileNotFound LOGGER.info("State after start:"); LOGGER.info(SystemUtil.printStateReport(ctx)); - String lastCommand = ""; + String lastCommand; Scanner scanner = new Scanner(System.in); LOGGER.info( "Type the roboclaw unit to control and the speed [-1, 1] and angular direction[-180, 180]. For example:\ntank 1 0\nType q and enter to quit!\n"); @@ -68,12 +68,12 @@ public static void main(String[] args) throws RoboBuilderException, FileNotFound lastCommand = lastCommand.trim(); String[] split = lastCommand.split(" "); if (split.length != 3) { - System.out.println("Could not parse " + lastCommand + ". Please try again!"); + LOGGER.warn("Could not parse {}. Please try again!", lastCommand); continue; } RoboReference servoRef = ctx.getReference(split[0]); if (servoRef == null) { - System.out.println("Could not find any robo unit named " + split[0] + ". Please try again!"); + LOGGER.warn("Could not find any robo unit named {}. Please try again!", split[0]); continue; } try {