From 28143b7f5113eebafedf4d9278bb01da29309f10 Mon Sep 17 00:00:00 2001 From: Miro Wengner Date: Sat, 14 Dec 2024 19:31:18 +0100 Subject: [PATCH] [75] updates --- .../com/robo4j/net/MessageServerTest.java | 7 +- .../com/robo4j/net/RemoteContextTests.java | 7 +- .../java/com/robo4j/hw/rpi/gps/Location.java | 100 +++++++------- .../adafruitbackpack/AbstractBackpack.java | 45 +++---- .../i2c/adafruitlcd/impl/AdafruitLcdImpl.java | 124 +++++++++--------- .../hw/rpi/i2c/gyro/CalibratedGyro.java | 18 +-- .../hw/rpi/i2c/pwm/HBridgeMC33926Device.java | 9 -- .../units/config/PropertyListBuilder.java | 2 +- .../config/enums/AdvancedTestCommandEnum.java | 4 +- .../http/test/utils/InternalUtilTests.java | 4 +- .../socket/http/test/utils/JsonUtilTests.java | 4 +- 11 files changed, 156 insertions(+), 168 deletions(-) diff --git a/robo4j-core/src/test/java/com/robo4j/net/MessageServerTest.java b/robo4j-core/src/test/java/com/robo4j/net/MessageServerTest.java index 79732e55..805c3f6e 100644 --- a/robo4j-core/src/test/java/com/robo4j/net/MessageServerTest.java +++ b/robo4j-core/src/test/java/com/robo4j/net/MessageServerTest.java @@ -44,7 +44,7 @@ public class MessageServerTest { private static final Logger LOGGER = LoggerFactory.getLogger(MessageServerTest.class); private static final int TIMEOUT_SEC = 30; - private static final String CONST_MYUUID = "myuuid"; + private static final String CONST_MY_UUID = "myuuid"; private static final String PROPERTY_SERVER_NAME = "ServerName"; private static final int SERVER_LISTEN_DELAY_MILLIS = 250; private static final String LOCALHOST_VALUE = "localhost"; @@ -53,6 +53,7 @@ public class MessageServerTest { @Test void clientServerMessagePassingTest() throws Exception { + final var messageCache = new ArrayList<>(); final var messagesLatch = new CountDownLatch(3); @@ -85,7 +86,7 @@ void clientServerMessagePassingTest() throws Exception { } var messageReceiverConfig = ConfigurationFactory.createEmptyConfiguration(); - var messageReceiver = new MessageClient(messageServer.getListeningURI(), CONST_MYUUID, messageReceiverConfig); + var messageReceiver = new MessageClient(messageServer.getListeningURI(), CONST_MY_UUID, messageReceiverConfig); if (exception != null) { throw exception; } @@ -147,7 +148,7 @@ void testMessageTypes() throws Exception { } Configuration clientConfig = ConfigurationFactory.createEmptyConfiguration(); - MessageClient client = new MessageClient(messageServer.getListeningURI(), CONST_MYUUID, clientConfig); + MessageClient client = new MessageClient(messageServer.getListeningURI(), CONST_MY_UUID, clientConfig); if (exception != null) { throw exception; } diff --git a/robo4j-core/src/test/java/com/robo4j/net/RemoteContextTests.java b/robo4j-core/src/test/java/com/robo4j/net/RemoteContextTests.java index 0ca15632..7219bece 100644 --- a/robo4j-core/src/test/java/com/robo4j/net/RemoteContextTests.java +++ b/robo4j-core/src/test/java/com/robo4j/net/RemoteContextTests.java @@ -62,6 +62,9 @@ class RemoteContextTests { @Test void discoveryOfDiscoveryEnabledRoboContextTest() throws RoboBuilderException, IOException { + var expectedMetaDataName = "Caprica"; + var expectedMetaDataClass = "Cylon"; + RoboBuilder builder = new RoboBuilder(SystemUtil.getInputStreamByResourceName("testDiscoverableSystem.xml")); RoboContext ctx = builder.build(); ctx.start(); @@ -75,8 +78,8 @@ void discoveryOfDiscoveryEnabledRoboContextTest() throws RoboBuilderException, I RoboContextDescriptor descriptor = service.getDescriptor("6"); assertFalse(service.getDiscoveredContexts().isEmpty()); - assertEquals(descriptor.getMetadata().get("name"), "Caprica"); - assertEquals(descriptor.getMetadata().get("class"), "Cylon"); + assertEquals(expectedMetaDataName, descriptor.getMetadata().get("name")); + assertEquals(expectedMetaDataClass, descriptor.getMetadata().get("class")); ctx.shutdown(); } diff --git a/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/gps/Location.java b/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/gps/Location.java index 90ab087a..686b8bce 100644 --- a/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/gps/Location.java +++ b/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/gps/Location.java @@ -18,63 +18,67 @@ /** * A 2D location on earth. - * + * * @author Marcus Hirt (@hirt) * @author Miro Wengner (@miragemiko) */ public final class Location { - private static final String STR_DEGREE = "\u00B0"; - private static final String STR_MINUTE = "'"; // "\u2032"; - private static final String STR_SECOND = "\""; // \u2033"; + private static final String STR_DEGREE = "\u00B0"; + private static final String STR_MINUTE = "'"; // "\u2032"; + private static final String STR_SECOND = "\""; // \u2033"; + public static final int DEGREE_MINS = 60; + public static final int DEGREE_SECONDS = 3600; + + private final float latitude; + private final float longitude; - private final float latitude; - private final float longitude; + /** + * Creates a new location. + * + * @param latitude the latitude in decimal degrees. + * @param longitude the longitude in decimal degrees. + */ + public Location(float latitude, float longitude) { + this.latitude = latitude; + this.longitude = longitude; + } - /** - * Creates a new location. - * - * @param latitude - * the latitude in decimal degrees. - * @param longitude - * the longitude in decimal degrees. - */ - public Location(float latitude, float longitude) { - this.latitude = latitude; - this.longitude = longitude; - } + /** + * @return the decimal degree for the latitude. + */ + public float getLatitude() { + return latitude; + } - /** - * @return the decimal degree for the latitude. - */ - public float getLatitude() { - return latitude; - } + /** + * @return the decimal degree for the longitude. + */ + public float getLongitude() { + return longitude; + } - /** - * @return the decimal degree for the longitude. - */ - public float getLongitude() { - return longitude; - } + /** + * Returns the coordinates as a String in degrees, minutes and seconds format. + * + * @return the coordinates as a String in degrees, minutes and seconds format. + */ + public String asDMS() { + return String.format("%s%s %s%s", toDMS(latitude), latitude > 0 ? "N" : "S", toDMS(longitude), longitude > 0 ? "E" : "W"); + } - /** - * Returns the coordinates as a String in degrees, minutes and seconds format. - * - * @return the coordinates as a String in degrees, minutes and seconds format. - */ - public String asDMS() { - return String.format("%s%s %s%s", toDMS(latitude), latitude > 0 ? "N" : "S", toDMS(longitude), longitude > 0 ? "E" : "W"); - } + private Object toDMS(float coordinateInDegree) { + int degreesIntAbs = Math.abs((int) coordinateInDegree); + int minute = convertDegreesByConversionType(degreesIntAbs, DEGREE_MINS); + int second = convertDegreesByConversionType(degreesIntAbs, DEGREE_SECONDS); + return String.format("%d%s%d%s%d%s", degreesIntAbs, STR_DEGREE, minute, STR_MINUTE, second, STR_SECOND); + } - private Object toDMS(float coordinate) { - int deg = Math.abs((int) coordinate); - int minute = Math.abs((int) (coordinate * 60) % 60); - int second = Math.abs((int) (coordinate * 3600) % 60); - return String.format("%d%s%d%s%d%s", deg, STR_DEGREE, minute, STR_MINUTE, second, STR_SECOND); - } + @Override + public String toString() { + return asDMS(); + } - @Override - public String toString() { - return asDMS(); - } + private int convertDegreesByConversionType(int degree, int multiplier) { + return (degree * multiplier) % DEGREE_MINS; + } } diff --git a/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/adafruitbackpack/AbstractBackpack.java b/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/adafruitbackpack/AbstractBackpack.java index 145a792d..c6d646a9 100644 --- a/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/adafruitbackpack/AbstractBackpack.java +++ b/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/adafruitbackpack/AbstractBackpack.java @@ -81,28 +81,24 @@ short intToShort(int value) { */ void setColorByMatrixToBuffer(short x, short y, BiColor color) { switch (color) { - case RED: + case RED -> { // Turn on red LED. buffer[y] |= _BV(intToShort(x + 8)); // Turn off green LED. buffer[y] &= (short) ~_BV(x); - break; - case YELLOW: + } + case YELLOW -> { // Turn on green and red LED. buffer[y] |= (short) (_BV(intToShort(x + 8)) | _BV(x)); - break; - case GREEN: + } + case GREEN -> { // Turn on green LED. buffer[y] |= _BV(x); // Turn off red LED. buffer[y] &= (short) ~_BV(intToShort(x + 8)); - break; - case OFF: - buffer[y] &= (short) (~_BV(x) & ~_BV(intToShort(x + 8))); - break; - default: - LOGGER.warn("setColorByMatrixToBuffer: {}", color); - break; + } + case OFF -> buffer[y] &= (short) (~_BV(x) & ~_BV(intToShort(x + 8))); + default -> LOGGER.warn("setColorByMatrixToBuffer: {}", color); } } @@ -134,36 +130,31 @@ void setValue(int n, short v, boolean dp) { */ void setColorToBarBuffer(short a, short c, BiColor color) { switch (color) { - case RED: + case RED -> { // Turn on red LED. buffer[c] |= _BV(a); // Turn off green LED. buffer[c] &= (short) ~_BV(intToShort(a + 8)); - break; - case YELLOW: + } + case YELLOW -> { // Turn on red and green LED. buffer[c] |= (short) (_BV(a) | _BV(intToShort(a + 8))); - break; - case GREEN: + } + case GREEN -> { // Turn on green LED. buffer[c] |= _BV(intToShort(a + 8)); // Turn off red LED. buffer[c] &= (short) ~_BV(a); - break; - case OFF: + } + case OFF -> { // Turn off red and green LED. buffer[c] &= (short) (~_BV(a) & ~_BV(intToShort(a + 8))); - break; - default: - LOGGER.warn("setColorToBarBuffer: {}", color); - break; + } + default -> LOGGER.warn("setColorToBarBuffer: {}", color); } } private void initiate(int brightness) throws IOException { -// i2CConfig.write((byte) (OSCILLATOR_TURN_ON)); // Turn on oscilator -// i2CConfig.write(blinkRate(HT16K33_BLINK_OFF)); -// i2CConfig.write(setBrightness(brightness)); writeByte((byte) (OSCILLATOR_TURN_ON)); // Turn on oscilator writeByte(blinkRate(HT16K33_BLINK_OFF)); writeByte(setBrightness(brightness)); @@ -172,8 +163,6 @@ private void initiate(int brightness) throws IOException { private void writeDisplay() throws IOException { int address = 0; for (short value : buffer) { -// i2CConfig.write(address++, (byte) (buffer[i] & 0xFF)); -// i2CConfig.write(address++, (byte) (buffer[i] >> 8)); writeByte(address++, (byte) (value & 0xFF)); writeByte(address++, (byte) (value >> 8)); } diff --git a/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/adafruitlcd/impl/AdafruitLcdImpl.java b/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/adafruitlcd/impl/AdafruitLcdImpl.java index ddf83add..a294abdd 100644 --- a/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/adafruitlcd/impl/AdafruitLcdImpl.java +++ b/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/adafruitlcd/impl/AdafruitLcdImpl.java @@ -60,34 +60,34 @@ public enum Direction { } // LCD Commands - private static final int LCD_CLEARDISPLAY = 0x01; - private static final int LCD_RETURNHOME = 0x02; - private static final int LCD_ENTRYMODESET = 0x04; - private static final int LCD_DISPLAYCONTROL = 0x08; - private static final int LCD_CURSORSHIFT = 0x10; + private static final int LCD_DISPLAY_CLEAR = 0x01; + private static final int LCD_DISPLAY_CONTROL = 0x08; + private static final int LCD_RETURN_HOME = 0x02; + private static final int LCD_ENTRY_MODE_SET = 0x04; + private static final int LCD_CURSOR_SHIFT = 0x10; // private static final int LCD_FUNCTIONSET = 0x20; - private static final int LCD_SETCGRAMADDR = 0x40; - private static final int LCD_SETDDRAMADDR = 0x80; + private static final int LCD_SET_CGRAMADDR = 0x40; + private static final int LCD_SET_DDRAMADDR = 0x80; // Flags for display on/off control - private static final int LCD_DISPLAYON = 0x04; - // private static final int LCD_DISPLAYOFF = 0x00; - private static final int LCD_CURSORON = 0x02; - private static final int LCD_CURSOROFF = 0x00; - private static final int LCD_BLINKON = 0x01; - private static final int LCD_BLINKOFF = 0x00; + private static final int LCD_DISPLAY_ON = 0x04; + // private static final int LCD_DISPLAY_OFF = 0x00; + private static final int LCD_CURSOR_ON = 0x02; + private static final int LCD_CURSOR_OFF = 0x00; + private static final int LCD_BLINK_ON = 0x01; + private static final int LCD_BLINK_OFF = 0x00; // Flags for display entry mode - // private static final int LCD_ENTRYRIGHT = 0x00; - private static final int LCD_ENTRYLEFT = 0x02; - private static final int LCD_ENTRYSHIFTINCREMENT = 0x01; - private static final int LCD_ENTRYSHIFTDECREMENT = 0x00; + // private static final int LCD_ENTRY_RIGHT = 0x00; + private static final int LCD_ENTRY_LEFT = 0x02; + private static final int LCD_ENTRY_SHIFT_INCREMENT = 0x01; + private static final int LCD_ENTRY_SHIFT_DECREMENT = 0x00; // Flags for display/cursor shift - private static final int LCD_DISPLAYMOVE = 0x08; - private static final int LCD_CURSORMOVE = 0x00; - private static final int LCD_MOVERIGHT = 0x04; - private static final int LCD_MOVELEFT = 0x00; + private static final int LCD_DISPLAY_MOVE = 0x08; + private static final int LCD_CURSOR_MOVE = 0x00; + private static final int LCD_MOVE_RIGHT = 0x04; + private static final int LCD_MOVE_LEFT = 0x00; // Port expander registers // IOCON when Bank 0 active @@ -112,9 +112,9 @@ public enum Direction { private int portA = 0x00; private int portB = 0x00; private int ddrB = 0x10; - private int displayShift = LCD_CURSORMOVE | LCD_MOVERIGHT; - private int displayMode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; - private int displayControl = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; + private int displayShift = LCD_CURSOR_MOVE | LCD_MOVE_RIGHT; + private int displayMode = LCD_ENTRY_LEFT | LCD_ENTRY_SHIFT_DECREMENT; + private int displayControl = LCD_DISPLAY_ON | LCD_CURSOR_OFF | LCD_BLINK_OFF; private Color color = Color.WHITE; public AdafruitLcdImpl() throws IOException { @@ -175,11 +175,11 @@ private synchronized void initialize() throws IOException { write(0x33); // Init write(0x32); // Init write(0x28); // 2 line 5x8 matrix - write(LCD_CLEARDISPLAY); - write(LCD_CURSORSHIFT | displayShift); - write(LCD_ENTRYMODESET | displayMode); - write(LCD_DISPLAYCONTROL | displayControl); - write(LCD_RETURNHOME); + write(LCD_DISPLAY_CLEAR); + write(LCD_CURSOR_SHIFT | displayShift); + write(LCD_ENTRY_MODE_SET | displayMode); + write(LCD_DISPLAY_CONTROL | displayControl); + write(LCD_RETURN_HOME); } private synchronized void write(int i, byte[] registers, int j, int length) throws IOException { @@ -204,7 +204,7 @@ private synchronized void write(int value) throws IOException { // If a poll-worthy instruction was issued, reconfigure D7 // pin as input to indicate need for polling on next call. - if (value == LCD_CLEARDISPLAY || value == LCD_RETURNHOME) { + if (value == LCD_DISPLAY_CLEAR || value == LCD_RETURN_HOME) { ddrB |= 0x10; // i2CConfig.write(MCP23017_IODIRB, (byte) ddrB); writeByte(MCP23017_IODIRB, (byte) ddrB); @@ -315,7 +315,7 @@ private void internalWrite(String s) throws IOException { */ @Override public synchronized void setCursorPosition(int row, int column) throws IOException { - write(LCD_SETDDRAMADDR | (column + ROW_OFFSETS[row])); + write(LCD_SET_DDRAMADDR | (column + ROW_OFFSETS[row])); } /* @@ -362,7 +362,7 @@ public synchronized void stop() throws IOException { */ @Override public synchronized void clear() throws IOException { - write(LCD_CLEARDISPLAY); + write(LCD_DISPLAY_CLEAR); } /* @@ -372,7 +372,7 @@ public synchronized void clear() throws IOException { */ @Override public synchronized void home() throws IOException { - write(LCD_RETURNHOME); + write(LCD_RETURN_HOME); } /* @@ -383,11 +383,11 @@ public synchronized void home() throws IOException { @Override public synchronized void setCursorEnabled(boolean enable) throws IOException { if (enable) { - displayControl |= LCD_CURSORON; - write(LCD_DISPLAYCONTROL | displayControl); + displayControl |= LCD_CURSOR_ON; + write(LCD_DISPLAY_CONTROL | displayControl); } else { - displayControl &= ~LCD_CURSORON; - write(LCD_DISPLAYCONTROL | displayControl); + displayControl &= ~LCD_CURSOR_ON; + write(LCD_DISPLAY_CONTROL | displayControl); } } @@ -398,7 +398,7 @@ public synchronized void setCursorEnabled(boolean enable) throws IOException { */ @Override public synchronized boolean isCursorEnabled() { - return (displayControl & LCD_CURSORON) > 0; + return (displayControl & LCD_CURSOR_ON) > 0; } /* @@ -409,11 +409,11 @@ public synchronized boolean isCursorEnabled() { @Override public synchronized void setDisplayEnabled(boolean enable) throws IOException { if (enable) { - displayControl |= LCD_DISPLAYON; - write(LCD_DISPLAYCONTROL | displayControl); + displayControl |= LCD_DISPLAY_ON; + write(LCD_DISPLAY_CONTROL | displayControl); } else { - displayControl &= ~LCD_DISPLAYON; - write(LCD_DISPLAYCONTROL | displayControl); + displayControl &= ~LCD_DISPLAY_ON; + write(LCD_DISPLAY_CONTROL | displayControl); } } @@ -424,7 +424,7 @@ public synchronized void setDisplayEnabled(boolean enable) throws IOException { */ @Override public synchronized boolean isDisplayEnabled() { - return (displayControl & LCD_DISPLAYON) > 0; + return (displayControl & LCD_DISPLAY_ON) > 0; } /* @@ -435,11 +435,11 @@ public synchronized boolean isDisplayEnabled() { @Override public synchronized void setBlinkEnabled(boolean enable) throws IOException { if (enable) { - displayControl |= LCD_BLINKON; - write(LCD_DISPLAYCONTROL | displayControl); + displayControl |= LCD_BLINK_ON; + write(LCD_DISPLAY_CONTROL | displayControl); } else { - displayControl &= ~LCD_BLINKON; - write(LCD_DISPLAYCONTROL | displayControl); + displayControl &= ~LCD_BLINK_ON; + write(LCD_DISPLAY_CONTROL | displayControl); } } @@ -450,7 +450,7 @@ public synchronized void setBlinkEnabled(boolean enable) throws IOException { */ @Override public synchronized boolean isBlinkEnabled() { - return (displayControl & LCD_BLINKON) > 0; + return (displayControl & LCD_BLINK_ON) > 0; } /* @@ -481,11 +481,11 @@ public synchronized void setBacklight(Color color) throws IOException { @Override public synchronized void scrollDisplay(Direction direction) throws IOException { if (direction == Direction.LEFT) { - displayShift = LCD_DISPLAYMOVE | LCD_MOVELEFT; - write(LCD_CURSORSHIFT | displayShift); + displayShift = LCD_DISPLAY_MOVE | LCD_MOVE_LEFT; + write(LCD_CURSOR_SHIFT | displayShift); } else { - displayShift = LCD_DISPLAYMOVE | LCD_MOVERIGHT; - write(LCD_CURSORSHIFT | displayShift); + displayShift = LCD_DISPLAY_MOVE | LCD_MOVE_RIGHT; + write(LCD_CURSOR_SHIFT | displayShift); } } @@ -499,12 +499,12 @@ public synchronized void scrollDisplay(Direction direction) throws IOException { public synchronized void setTextFlowDirection(Direction direction) throws IOException { if (direction == Direction.LEFT) { // This is for text that flows right to left - displayMode &= ~LCD_ENTRYLEFT; - write(LCD_ENTRYMODESET | displayMode); + displayMode &= ~LCD_ENTRY_LEFT; + write(LCD_ENTRY_MODE_SET | displayMode); } else { // This is for text that flows left to right - displayMode |= LCD_ENTRYLEFT; - write(LCD_ENTRYMODESET | displayMode); + displayMode |= LCD_ENTRY_LEFT; + write(LCD_ENTRY_MODE_SET | displayMode); } } @@ -517,12 +517,12 @@ public synchronized void setTextFlowDirection(Direction direction) throws IOExce public synchronized void setAutoScrollEnabled(boolean enable) throws IOException { if (enable) { // This will 'right justify' text from the cursor - displayMode |= LCD_ENTRYSHIFTINCREMENT; - write(LCD_ENTRYMODESET | displayMode); + displayMode |= LCD_ENTRY_SHIFT_INCREMENT; + write(LCD_ENTRY_MODE_SET | displayMode); } else { // This will 'left justify' text from the cursor - displayMode &= ~LCD_ENTRYSHIFTINCREMENT; - write(LCD_ENTRYMODESET | displayMode); + displayMode &= ~LCD_ENTRY_SHIFT_INCREMENT; + write(LCD_ENTRY_MODE_SET | displayMode); } } @@ -533,7 +533,7 @@ public synchronized void setAutoScrollEnabled(boolean enable) throws IOException */ @Override public synchronized boolean isAutoScrollEnabled() { - return (displayControl & LCD_ENTRYSHIFTINCREMENT) > 0; + return (displayControl & LCD_ENTRY_SHIFT_INCREMENT) > 0; } /* @@ -586,7 +586,7 @@ public void createChar(int location, byte[] pattern) throws IOException { // Send ccgram update command location &= 0x7; // Only position 0..7 are allowed - int command = LCD_SETCGRAMADDR | (location << 3); + int command = LCD_SET_CGRAMADDR | (location << 3); write(command); // Send custom character definition diff --git a/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/gyro/CalibratedGyro.java b/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/gyro/CalibratedGyro.java index 20440cc8..c19c90e2 100644 --- a/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/gyro/CalibratedGyro.java +++ b/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/gyro/CalibratedGyro.java @@ -46,21 +46,21 @@ public CalibratedGyro(ReadableDevice device, Tuple3f offsets, Tuple3f m */ public void calibrate() throws IOException { setCalibration(new Tuple3f(), Tuple3f.createIdentity()); - float[] xvalues = new float[NUMBER_OF_CALIBRATION_READINGS]; - float[] yvalues = new float[NUMBER_OF_CALIBRATION_READINGS]; - float[] zvalues = new float[NUMBER_OF_CALIBRATION_READINGS]; + float[] xValues = new float[NUMBER_OF_CALIBRATION_READINGS]; + float[] yValues = new float[NUMBER_OF_CALIBRATION_READINGS]; + float[] zValues = new float[NUMBER_OF_CALIBRATION_READINGS]; for (int i = 0; i < NUMBER_OF_CALIBRATION_READINGS; i++) { Tuple3f tmp = read(); - xvalues[i] = tmp.x; - yvalues[i] = tmp.y; - zvalues[i] = tmp.z; + xValues[i] = tmp.x; + yValues[i] = tmp.y; + zValues[i] = tmp.z; sleep(20); } Tuple3f calibration = new Tuple3f(); - calibration.x = calibrate(xvalues, NUMBER_OF_CALIBRATION_READINGS_TO_DROP); - calibration.y = calibrate(yvalues, NUMBER_OF_CALIBRATION_READINGS_TO_DROP); - calibration.z = calibrate(zvalues, NUMBER_OF_CALIBRATION_READINGS_TO_DROP); + calibration.x = calibrate(xValues, NUMBER_OF_CALIBRATION_READINGS_TO_DROP); + calibration.y = calibrate(yValues, NUMBER_OF_CALIBRATION_READINGS_TO_DROP); + calibration.z = calibrate(zValues, NUMBER_OF_CALIBRATION_READINGS_TO_DROP); LOGGER.info("calibrate:{}", RANGE_MULTIPLIERS); setCalibration(calibration, RANGE_MULTIPLIERS); } diff --git a/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/pwm/HBridgeMC33926Device.java b/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/pwm/HBridgeMC33926Device.java index 0e168d59..4c1e101f 100644 --- a/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/pwm/HBridgeMC33926Device.java +++ b/robo4j-hw-rpi/src/main/java/com/robo4j/hw/rpi/i2c/pwm/HBridgeMC33926Device.java @@ -36,8 +36,6 @@ public class HBridgeMC33926Device implements Motor { private final String name; private final PWMChannel channel; private final boolean invert; - // private final GpioPinDigitalOutput in1; -// private final GpioPinDigitalOutput in2; private final DigitalOutput gpioOut1; private final DigitalOutput gpioOut2; @@ -58,9 +56,6 @@ public HBridgeMC33926Device(String name, PWMChannel channel, GpioPin pin1, GpioP var gpioConfig1 = digitalOutputBuilder.address(pin1.address()).onState(DigitalState.LOW).build(); var gpioConfig2 = digitalOutputBuilder.address(pin2.address()).onState(DigitalState.HIGH).build(); -// GpioController gpio = GpioFactory.getInstance(); -// this.in1 = gpio.provisionDigitalOutputPin(in1, "IN1", PinState.LOW); -// this.in2 = gpio.provisionDigitalOutputPin(in2, "IN2", PinState.HIGH); gpioOut1 = pi4jRpiContext.dout().create(gpioConfig1); gpioOut2 = pi4jRpiContext.dout().create(gpioConfig2); setDirection(Direction.FORWARD); @@ -110,13 +105,9 @@ private void setDirection(Direction direction) { } if (forward) { -// in1.setState(PinState.HIGH); -// in2.setState(PinState.LOW); gpioOut1.setState(digitalStateToByte(DigitalState.HIGH)); gpioOut2.setState(digitalStateToByte(DigitalState.LOW)); } else { -// in1.setState(PinState.LOW); -// in2.setState(PinState.HIGH); gpioOut1.setState(digitalStateToByte(DigitalState.LOW)); gpioOut2.setState(digitalStateToByte(DigitalState.HIGH)); } diff --git a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/config/PropertyListBuilder.java b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/config/PropertyListBuilder.java index 9cd27429..f74843cb 100644 --- a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/config/PropertyListBuilder.java +++ b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/config/PropertyListBuilder.java @@ -26,7 +26,7 @@ */ public class PropertyListBuilder { - private List list; + private final List list; private PropertyListBuilder() { this.list = new LinkedList<>(); diff --git a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/config/enums/AdvancedTestCommandEnum.java b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/config/enums/AdvancedTestCommandEnum.java index d62806f4..1b08cf55 100644 --- a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/config/enums/AdvancedTestCommandEnum.java +++ b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/config/enums/AdvancedTestCommandEnum.java @@ -36,8 +36,8 @@ public enum AdvancedTestCommandEnum implements TestEnum { //@formatter:on private static volatile Map nameToEnum; - private int id; - private String name; + private final int id; + private final String name; AdvancedTestCommandEnum(int id, String name) { this.id = id; diff --git a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/utils/InternalUtilTests.java b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/utils/InternalUtilTests.java index 46530390..db1e16f4 100644 --- a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/utils/InternalUtilTests.java +++ b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/utils/InternalUtilTests.java @@ -21,7 +21,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Arrays; +import java.util.List; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -37,7 +37,7 @@ class InternalUtilTests { void testSeparator() { var separator = SystemPropertyUtils.get("line.separator", "\n\n"); - LOGGER.info("Separator: {}", Arrays.asList(separator.toCharArray())); + LOGGER.info("Separator: {}", List.of(separator.toCharArray())); assertNotNull(separator.toCharArray()); } diff --git a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/utils/JsonUtilTests.java b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/utils/JsonUtilTests.java index 2667c614..02df5bc5 100644 --- a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/utils/JsonUtilTests.java +++ b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/utils/JsonUtilTests.java @@ -73,7 +73,7 @@ void mapToJsonTest() { printInfo(result); assertNotNull(result); - assertEquals(result, expectedJson); + assertEquals(expectedJson, result); } @Test @@ -84,7 +84,7 @@ void mapToJsonEmptyTest() { printInfo(result); assertNotNull(result); - assertEquals(result, expectedJson); + assertEquals(expectedJson, result); } private static void printInfo(String result) {