Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -444,14 +444,99 @@
this.usesRP1 = usesRP1;
}

/**
* Returns the {@link BoardModel} corresponding to the given {@link RevisionCode} by matching on the board type and,
* where necessary, the PCB revision or memory size.
*
* @param revisionCode the parsed revision code to identify
* @return the matching {@code BoardModel}, or {@code UNKNOWN} if the type is not recognized
*/
public static BoardModel getByRevisionCode(RevisionCode revisionCode) {
switch (revisionCode.type()) {
case RPI_A:
return BoardModel.MODEL_1_A;
case RPI_B:
case RPI_ALPHA:

Check warning on line 459 in pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardModel.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge the previous cases into this one using comma-separated label.

See more on https://sonarcloud.io/project/issues?id=Pi4J_pi4j&issues=AZ8UmY90mHX9CG1piDiv&open=AZ8UmY90mHX9CG1piDiv&pullRequest=682
return BoardModel.MODEL_1_B;
case RPI_A_PLUS:
return BoardModel.MODEL_1_A_PLUS;
case RPI_B_PLUS:
return BoardModel.MODEL_1_B_PLUS;
case RPI_2B:
if (revisionCode.revision() < 2) {
return BoardModel.MODEL_2_B;
} else {
return BoardModel.MODEL_2_B_V1_2;
}
case RPI_CM1:
return BoardModel.COMPUTE_1;
case RPI_3B:
return BoardModel.MODEL_3_B;
case RPI_ZERO:
if (revisionCode.revision() < 3) {
return BoardModel.ZERO_PCB_1_2;
} else {
return BoardModel.ZERO_PCB_1_3;
}
case RPI_CM3:
return BoardModel.COMPUTE_3;
case RPI_ZERO_W:
return BoardModel.ZERO_W;
case RPI_3B_PLUS:
return BoardModel.MODEL_3_B_PLUS;
case RPI_3A_PLUS:
return BoardModel.MODEL_3_A_PLUS;
case RPI_CM3_PLUS:
return BoardModel.COMPUTE_3_PLUS;
case RPI_4B:
return BoardModel.MODEL_4_B;
case RPI_ZERO_2_W:
case RPI_CM0:

Check warning on line 494 in pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardModel.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge the previous cases into this one using comma-separated label.

See more on https://sonarcloud.io/project/issues?id=Pi4J_pi4j&issues=AZ8UmY90mHX9CG1piDiw&open=AZ8UmY90mHX9CG1piDiw&pullRequest=682
return BoardModel.ZERO_V2;
case RPI_400:
return BoardModel.MODEL_400;
case RPI_CM4:
return BoardModel.COMPUTE_4;
case RPI_CM4S:
return BoardModel.COMPUTE_4_SODIMM;
case RPI_5:
return BoardModel.MODEL_5_B;
case RPI_CM5:
case RPI_CM5_LITE:

Check warning on line 505 in pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardModel.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge the previous cases into this one using comma-separated label.

See more on https://sonarcloud.io/project/issues?id=Pi4J_pi4j&issues=AZ8UmY90mHX9CG1piDix&open=AZ8UmY90mHX9CG1piDix&pullRequest=682
return BoardModel.COMPUTE_5;
case RPI_500_500_PLUS:
if (RevisionCode.MemorySize.GB_16.equals(revisionCode.memorySize())) {
return BoardModel.MODEL_500_PLUS;
} else {
return BoardModel.MODEL_500;
}
default:
return UNKNOWN;
}
}

/**
* Retrieves the board model corresponding to the given board code.
*
* <p>Where possible, identification is performed by decoding the structured fields of the revision code per the
* Raspberry Pi revision code specification. If the revision code cannot be parsed, falls back to direct string
* matching against known board codes.</p>
*
* @param boardCode the board code to look up
* @return the matching {@code BoardModel} or {@code UNKNOWN} if no match is found
* @throws Exception if multiple matches are found
*/
public static BoardModel getByBoardCode(String boardCode) throws Exception {
try {
RevisionCode revisionCode = RevisionCode.of(boardCode);
BoardModel result = getByRevisionCode(revisionCode);
if (result != UNKNOWN) {
return result;
}
} catch (IllegalArgumentException e) {

Check warning on line 536 in pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardModel.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace "e" with an unnamed pattern.

See more on https://sonarcloud.io/project/issues?id=Pi4J_pi4j&issues=AZ8UmY90mHX9CG1piDiy&open=AZ8UmY90mHX9CG1piDiy&pullRequest=682
// Not a valid revision code, fall through to legacy lookup.
}

var matches = Arrays.stream(BoardModel.values())
.filter(bm -> bm.boardCodes.contains(boardCode))
.collect(Collectors.toList());
Expand Down
Loading
Loading