mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-22 01:11:40 +00:00
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) Photon Vision.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.photonvision.common.hardware;
|
||||
|
||||
public enum PiVersion {
|
||||
PI_B("Pi Model B"),
|
||||
COMPUTE_MODULE("Compute Module Rev"),
|
||||
ZERO_W("Pi Zero W Rev 1.1"),
|
||||
PI_3("Pi 3"),
|
||||
PI_4("Pi 4"),
|
||||
COMPUTE_MODULE_3("Compute Module 3"),
|
||||
UNKNOWN("UNKNOWN");
|
||||
|
||||
private final String identifier;
|
||||
|
||||
PiVersion(String s) {
|
||||
this.identifier = s.toLowerCase();
|
||||
}
|
||||
|
||||
public static PiVersion getPiVersion() {
|
||||
if (!Platform.isRaspberryPi()) return PiVersion.UNKNOWN;
|
||||
String piString = Platform.currentPiVersionStr;
|
||||
for (PiVersion p : PiVersion.values()) {
|
||||
if (piString.toLowerCase().contains(p.identifier)) return p;
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,11 @@ public enum Platform {
|
||||
|
||||
private static final String OS_NAME = System.getProperty("os.name");
|
||||
private static final String OS_ARCH = System.getProperty("os.arch");
|
||||
public static final Platform CurrentPlatform = getCurrentPlatform();
|
||||
|
||||
// These are querried on init and should never change after
|
||||
public static final Platform currentPlatform = getCurrentPlatform();
|
||||
protected static final String currentPiVersionStr = getPiVersionString();
|
||||
public static final PiVersion currentPiVersion = PiVersion.getPiVersion();
|
||||
|
||||
private static String UnknownPlatformString =
|
||||
String.format("Unknown Platform. OS: %s, Architecture: %s", OS_NAME, OS_ARCH);
|
||||
@@ -61,7 +65,7 @@ public enum Platform {
|
||||
}
|
||||
|
||||
public static boolean isRaspberryPi() {
|
||||
return CurrentPlatform.equals(LINUX_RASPBIAN);
|
||||
return currentPlatform.equals(LINUX_RASPBIAN);
|
||||
}
|
||||
|
||||
@SuppressWarnings("StatementWithEmptyBody")
|
||||
@@ -114,4 +118,22 @@ public enum Platform {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
// Querry /proc/device-tree/model. This should return the model of the pi
|
||||
// Versions here:
|
||||
// https://github.com/raspberrypi/linux/blob/rpi-5.10.y/arch/arm/boot/dts/bcm2710-rpi-cm3.dts
|
||||
private static String getPiVersionString() {
|
||||
if (!isRaspberryPi()) return "";
|
||||
try {
|
||||
shell.executeBashCommand("cat /proc/device-tree/model");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (shell.getExitCode() == 0) {
|
||||
// We expect it to be in the format "raspberry pi X model X"
|
||||
return shell.getOutput();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ public class ScriptManager {
|
||||
}
|
||||
|
||||
public static void queueEvent(ScriptEventType eventType) {
|
||||
if (!Platform.CurrentPlatform.isWindows()) {
|
||||
if (!Platform.currentPlatform.isWindows()) {
|
||||
try {
|
||||
queuedEvents.putLast(eventType);
|
||||
logger.info("Queued event: " + eventType.name());
|
||||
|
||||
@@ -76,7 +76,7 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
public static void setFilePerms(Path path) throws IOException {
|
||||
if (!Platform.CurrentPlatform.isWindows()) {
|
||||
if (!Platform.currentPlatform.isWindows()) {
|
||||
File thisFile = path.toFile();
|
||||
Set<PosixFilePermission> perms =
|
||||
Files.readAttributes(path, PosixFileAttributes.class).permissions();
|
||||
@@ -94,7 +94,7 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
public static void setAllPerms(Path path) {
|
||||
if (!Platform.CurrentPlatform.isWindows()) {
|
||||
if (!Platform.currentPlatform.isWindows()) {
|
||||
String command = String.format("chmod 777 -R %s", path.toString());
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import org.photonvision.common.hardware.PiVersion;
|
||||
import org.photonvision.common.hardware.Platform;
|
||||
import org.photonvision.common.logging.LogGroup;
|
||||
import org.photonvision.common.logging.Logger;
|
||||
@@ -83,7 +84,12 @@ public class PicamJNI {
|
||||
}
|
||||
|
||||
public static boolean isSupported() {
|
||||
return libraryLoaded && !isVCSMSupported() && getSensorModel() != SensorModel.Disconnected;
|
||||
return libraryLoaded
|
||||
&& !isVCSMSupported()
|
||||
&& getSensorModel() != SensorModel.Disconnected
|
||||
&& Platform.isRaspberryPi()
|
||||
&& (Platform.currentPiVersion == PiVersion.PI_3
|
||||
|| Platform.currentPiVersion == PiVersion.COMPUTE_MODULE_3);
|
||||
}
|
||||
|
||||
public static SensorModel getSensorModel() {
|
||||
|
||||
@@ -36,7 +36,7 @@ public class HardwareTest {
|
||||
|
||||
if (!Platform.isRaspberryPi()) return;
|
||||
|
||||
System.out.println("Testing on platform: " + Platform.CurrentPlatform);
|
||||
System.out.println("Testing on platform: " + Platform.currentPlatform);
|
||||
|
||||
System.out.println("Printing CPU Info:");
|
||||
System.out.println("Memory: " + cpuMetrics.getMemory() + "MB");
|
||||
|
||||
@@ -169,7 +169,8 @@ public class Main {
|
||||
"Starting PhotonVision version "
|
||||
+ PhotonVersion.versionString
|
||||
+ " on "
|
||||
+ Platform.CurrentPlatform.toString());
|
||||
+ Platform.currentPlatform.toString()
|
||||
+ (Platform.isRaspberryPi() ? (" (Pi " + Platform.currentPiVersion.name() + ")") : ""));
|
||||
|
||||
try {
|
||||
CameraServerCvJNI.forceLoad();
|
||||
|
||||
Reference in New Issue
Block a user