2019-09-15 15:03:44 -04:00
|
|
|
package com.chameleonvision.settings;
|
2019-09-16 04:10:26 +03:00
|
|
|
|
2019-10-06 17:26:17 -04:00
|
|
|
import com.chameleonvision.network.NetworkManager;
|
2019-10-04 15:55:45 -04:00
|
|
|
import com.chameleonvision.util.FileHelper;
|
2019-09-19 14:07:42 -04:00
|
|
|
import com.chameleonvision.vision.camera.CameraManager;
|
2019-09-12 23:23:36 +03:00
|
|
|
import com.google.gson.Gson;
|
2019-09-20 02:17:22 -04:00
|
|
|
import com.google.gson.GsonBuilder;
|
2019-09-16 04:10:26 +03:00
|
|
|
|
2019-09-20 02:17:22 -04:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.FileReader;
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
2019-09-11 22:07:24 +03:00
|
|
|
|
2019-09-16 04:10:26 +03:00
|
|
|
public class SettingsManager {
|
2019-09-26 15:01:51 -04:00
|
|
|
public static final Path SettingsPath = Paths.get(System.getProperty("user.dir"), "settings");
|
2019-10-04 15:55:45 -04:00
|
|
|
public static com.chameleonvision.settings.GeneralSettings GeneralSettings;
|
2019-09-16 04:10:26 +03:00
|
|
|
|
2019-09-20 19:54:59 -04:00
|
|
|
private SettingsManager() {}
|
2019-09-16 04:10:26 +03:00
|
|
|
|
2019-10-06 17:26:17 -04:00
|
|
|
public static void initialize() {
|
2019-09-20 19:54:59 -04:00
|
|
|
initGeneralSettings();
|
2019-10-06 17:26:17 -04:00
|
|
|
// if (manageNetwork) {
|
|
|
|
|
|
2019-10-04 15:55:45 -04:00
|
|
|
// NetworkSettings netSettings = new NetworkSettings();
|
|
|
|
|
// netSettings.hostname = GeneralSettings.hostname;
|
|
|
|
|
// netSettings.gateway = GeneralSettings.gateway;
|
|
|
|
|
// netSettings.netmask = GeneralSettings.netmask;
|
|
|
|
|
// netSettings.connectionType = GeneralSettings.connection_type;
|
|
|
|
|
// netSettings.ip = GeneralSettings.ip;
|
|
|
|
|
// netSettings.run();
|
2019-10-06 17:26:17 -04:00
|
|
|
// }
|
2019-09-20 19:54:59 -04:00
|
|
|
var allCameras = CameraManager.getAllCamerasByName();
|
2019-10-15 21:00:18 +03:00
|
|
|
if (!allCameras.containsKey(GeneralSettings.currentCamera) && allCameras.size() > 0) {
|
2019-09-20 19:54:59 -04:00
|
|
|
var cam = allCameras.entrySet().stream().findFirst().get().getValue();
|
2019-10-15 21:00:18 +03:00
|
|
|
GeneralSettings.currentCamera = cam.name;
|
|
|
|
|
GeneralSettings.currentPipeline = cam.getCurrentPipelineIndex();
|
2019-09-20 19:54:59 -04:00
|
|
|
}
|
|
|
|
|
}
|
2019-09-16 04:10:26 +03:00
|
|
|
|
2019-09-20 19:54:59 -04:00
|
|
|
private static void initGeneralSettings() {
|
|
|
|
|
FileHelper.CheckPath(SettingsPath);
|
|
|
|
|
try {
|
2019-10-04 15:55:45 -04:00
|
|
|
GeneralSettings = new Gson().fromJson(new FileReader(Paths.get(SettingsPath.toString(), "settings.json").toString()), com.chameleonvision.settings.GeneralSettings.class);
|
2019-09-20 19:54:59 -04:00
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
GeneralSettings = new GeneralSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-11 22:07:24 +03:00
|
|
|
|
2019-09-20 19:54:59 -04:00
|
|
|
public static void updateCameraSetting(String cameraName, int pipelineNumber) {
|
2019-10-15 21:00:18 +03:00
|
|
|
GeneralSettings.currentCamera = cameraName;
|
|
|
|
|
GeneralSettings.currentPipeline = pipelineNumber;
|
2019-09-20 19:54:59 -04:00
|
|
|
}
|
2019-09-14 17:14:49 +03:00
|
|
|
|
2019-09-20 19:54:59 -04:00
|
|
|
public static void updatePipelineSetting(int pipelineNumber) {
|
2019-10-15 21:00:18 +03:00
|
|
|
GeneralSettings.currentPipeline = pipelineNumber;
|
2019-09-20 19:54:59 -04:00
|
|
|
}
|
2019-09-12 01:05:27 +03:00
|
|
|
|
2019-09-20 19:54:59 -04:00
|
|
|
public static void saveSettings() {
|
|
|
|
|
CameraManager.saveCameras();
|
|
|
|
|
saveGeneralSettings();
|
|
|
|
|
}
|
2019-09-16 04:10:26 +03:00
|
|
|
|
2019-09-20 19:54:59 -04:00
|
|
|
private static void saveGeneralSettings() {
|
|
|
|
|
try {
|
|
|
|
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
|
|
|
FileWriter writer = new FileWriter(Paths.get(SettingsPath.toString(), "settings.json").toString());
|
|
|
|
|
gson.toJson(GeneralSettings, writer);
|
|
|
|
|
writer.flush();
|
|
|
|
|
writer.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-10 23:47:06 +03:00
|
|
|
}
|