Skip to content

Commit

Permalink
Merge pull request #350 from Pi4J/feature/codeCleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
FDelporte authored Apr 18, 2024
2 parents 2c6399d + 90a4430 commit c4ea33e
Show file tree
Hide file tree
Showing 20 changed files with 36 additions and 73 deletions.
2 changes: 1 addition & 1 deletion pi4j-core/src/main/java/com/pi4j/io/IODataReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ default int read(CharBuffer buffer) {
default byte readByte() {
int actual = read();
if(actual < 0) throw new IOReadException("I2C READ ERROR; " + actual);
return (byte)actual;
return (byte) actual;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion pi4j-core/src/main/java/com/pi4j/io/IOType.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Class<? extends IOConfigBuilder> getConfigBuilderClass() {
public <CB extends IOConfigBuilder>CB newConfigBuilder(Context context) {
try {
Method newInstance = getConfigBuilderClass().getMethod("newInstance", Context.class);
return (CB)newInstance.invoke(null, context);
return (CB) newInstance.invoke(null, context);
} catch (Exception e) {
throw new Pi4JException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ public AnalogBase(PROVIDER_TYPE provider, CONFIG_TYPE config){
@Override
public ANALOG_TYPE addListener(AnalogValueChangeListener... listener) {
valueChangeEventManager.add(listener);
return (ANALOG_TYPE)this;
return (ANALOG_TYPE) this;
}

/** {@inheritDoc} */
@Override
public ANALOG_TYPE removeListener(AnalogValueChangeListener... listener) {
valueChangeEventManager.add(listener);
return (ANALOG_TYPE)this;
return (ANALOG_TYPE) this;
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ public int readRegister(int register) {
/** {@inheritDoc} */
@Override
public int readRegister(byte[] register, byte[] buffer, int offset, int length) {
return(this.i2c.readRegister(register,buffer,offset,length));
return this.i2c.readRegister(register,buffer,offset,length);
}


/** {@inheritDoc} */
@Override
public int readRegister(int register, byte[] buffer, int offset, int length) {
return(this.i2c.readRegister(register,buffer,offset,length));
return this.i2c.readRegister(register,buffer,offset,length);
}


Expand All @@ -147,12 +147,12 @@ public int writeRegister(int register, byte b) {
/** {@inheritDoc} */
@Override
public int writeRegister(int register, byte[] data, int offset, int length) {
return(this.i2c.writeRegister(register,data,offset,length));
return this.i2c.writeRegister(register,data,offset,length);
}

/** {@inheritDoc} */
@Override
public int writeRegister(byte[] register, byte[] data, int offset, int length) {
return(this.i2c.writeRegister(register,data,offset,length));
return this.i2c.writeRegister(register,data,offset,length);
}
}
6 changes: 3 additions & 3 deletions pi4j-core/src/main/java/com/pi4j/util/Frequency.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ public static float milliseconds(Number frequency){
public static int getFrequencyFromNanos(Number nanoseconds){
int frequency;
if(nanoseconds.longValue() <= 0){
return(0);
return 0;
}
long period = 1000000000; // NANOSECONDS PER SECOND;
frequency = Math.round(1000000000/nanoseconds.longValue());
long period = 1_000_000_000; // NANOSECONDS PER SECOND;
frequency = (int) Math.round(period / (nanoseconds.longValue() * 1.0));
return frequency;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public boolean compareArray( byte[] a, byte[]b, int aOffset, int numBytes){
}
}
}
return (rval);
return rval;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public DigitalInput create(DigitalInputConfig config) {
@Override
public int getPriority() {
// the gpioD driver should be higher priority always
return(150);
return 150;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public DigitalOutput create(DigitalOutputConfig config) {
@Override
public int getPriority() {
// the gpioD driver should be higher priority always
return(150);
return 150;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ public LinuxFsDigitalInputProviderImpl(String gpioFileSystemPath) {
@Override
public int getPriority() {
// the linux FS Digital driver should be higher priority on RP1 chip
int rval = 50;
if(BoardInfoHelper.usesRP1()) {
rval = 100;
}
return(rval);
return BoardInfoHelper.usesRP1() ? 100 : 50;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ public LinuxFsDigitalOutputProviderImpl(String gpioFileSystemPath) {
@Override
public int getPriority() {
// the linux FS Digital driver should be higher priority on RP1 chip.
int rval = 50;
if(BoardInfoHelper.usesRP1()) {
rval = 100;
}
return(rval);
return BoardInfoHelper.usesRP1() ? 100 : 50;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@
* #L%
*/

import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.util.Objects;

import com.pi4j.io.i2c.I2C;
import com.pi4j.io.i2c.I2CBase;
import com.pi4j.io.i2c.I2CConfig;
import com.pi4j.io.i2c.I2CProvider;
import com.pi4j.plugin.linuxfs.util.SystemUtil;

import com.pi4j.plugin.linuxfs.util.SystemUtil;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.util.Objects;

/**
* <p>PiGpioI2C class.</p>
Expand Down Expand Up @@ -312,14 +311,13 @@ public int readRegister(byte[] register, byte[] buffer, int offset, int length)
this.i2CBus.executeIOCTL(this, command, ioctlData, offsets);

// move results back into user buffer
for(int i = 0; i <length; i++){ // can I assume length is safe and the readBuff data is not shorter ?? I think yes
buffer[i] = ioctlData.get(readBuffPosition +i );
; }
for (int i = 0; i < length; i++) { // can I assume length is safe and the readBuff data is not shorter ?? I think yes
buffer[i] = ioctlData.get(readBuffPosition + i);
}

return (readLength);
return readLength;
}


/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public int executeIOCTL(final I2C i2c, long command, ByteBuffer data, IntBuffer
throw new Pi4JException("Failed to execute action for device " + i2c.device() + " on bus " + this.bus, e);
}

return(rc);
return rc;
}

public <R> R execute(final I2C i2c, final CheckedFunction<LinuxFile, R> action) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public LinuxFsI2CProviderImpl() {
@Override
public int getPriority() {
// the linux FS driver should always be higher priority
return(150);
return 150;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.pi4j.io.pwm.PwmProviderBase;
import com.pi4j.io.pwm.PwmType;
import com.pi4j.plugin.linuxfs.internal.LinuxPwm;

import static java.text.MessageFormat.format;

/**
Expand All @@ -61,11 +62,7 @@ public LinuxFsPwmProviderImpl(String pwmFileSystemPath, int pwmChip) {
@Override
public int getPriority() {
// the linux FS PWM driver should be higher priority on RP1 chip
int rval = 50;
if(BoardInfoHelper.usesRP1()) {
rval = 100;
}
return(rval);
return BoardInfoHelper.usesRP1() ? 100 : 50;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ public PiGpioDigitalInputProviderImpl(PiGpio piGpio) {
@Override
public int getPriority() {
// the Pigpio driver should be higher priority when NOT on RP1 chip
int rval = 100;
if(BoardInfoHelper.usesRP1()) {
rval = 50;
}
return(rval);
return BoardInfoHelper.usesRP1() ? 50 : 100;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ public PiGpioDigitalOutputProviderImpl(PiGpio piGpio) {
@Override
public int getPriority() {
// the Pigpio driver should be higher priority when NOT on RP1 chip.
int rval = 100;
if(BoardInfoHelper.usesRP1()) {
rval = 50;
}
return(rval);
return BoardInfoHelper.usesRP1() ? 50 : 100;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ public PiGpioI2CProviderImpl(PiGpio piGpio) {
@Override
public int getPriority() {
// the Pigpio driver should be higher priority when NOT on RP1 chip
int rval = 100;
if(BoardInfoHelper.usesRP1()) {
rval = 50;
}
return(rval);
return BoardInfoHelper.usesRP1() ? 50 : 100;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ public PiGpioPwmProviderImpl(PiGpio piGpio) {
@Override
public int getPriority() {
// the Pigpio driver should be higher priority when NOT on RP1 chip.
int rval = 100;
if(BoardInfoHelper.usesRP1()) {
rval = 50;
}
return(rval);
return BoardInfoHelper.usesRP1() ? 50 : 100;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ public PiGpioSerialProviderImpl(PiGpio piGpio) {
@Override
public int getPriority() {
// the Pigpio driver should be higher priority when NOT on Rp1 chip.
int rval = 100;
if(BoardInfoHelper.usesRP1()) {
rval = 50;
}
return(rval);
return BoardInfoHelper.usesRP1() ? 50 : 100;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ public PiGpioSpiProviderImpl(PiGpio piGpio) {
@Override
public int getPriority() {
// the Pigpio driver should be higher priority when NOT on RP1 chip.
int rval = 100;
if(BoardInfoHelper.usesRP1()) {
rval = 50;
}
return(rval);
return BoardInfoHelper.usesRP1() ? 50 : 100;
}

/**
Expand Down

0 comments on commit c4ea33e

Please sign in to comment.