plugin progress

This commit is contained in:
rusefi 2020-07-14 22:59:06 -04:00
parent 4aeffa4d17
commit 1e114ccfe9
3 changed files with 58 additions and 7 deletions

View File

@ -48,4 +48,12 @@ public class TsTuneReader {
return defaultDirectory + File.separator + "TunerStudioProjects";
}
}
@NotNull
public static String getProjectModeFileName(String projectName) {
return getProjectsDir() +
File.separator + projectName +
File.separator + "projectCfg" +
File.separator + "mainController.ini";
}
}

View File

@ -6,7 +6,6 @@ import com.opensr5.ini.IniFileModel;
import com.rusefi.TsTuneReader;
import com.rusefi.ui.util.FrameHelper;
import java.io.File;
import java.util.ArrayList;
import java.util.Objects;
@ -22,10 +21,7 @@ public class PluginBodySandbox {
private static final String PROJECT_NAME = "dev";
public static void main(String[] args) {
String iniFile = TsTuneReader.getProjectsDir() +
File.separator + PROJECT_NAME +
File.separator + "projectCfg" +
File.separator + "mainController.ini";
String iniFile = TsTuneReader.getProjectModeFileName(PROJECT_NAME);
IniFileModel model = new IniFileModel().readIniFile(iniFile);
Objects.requireNonNull(model, "model");
java.util.List<String> fieldNamesList = new ArrayList<>(model.allIniFields.keySet());
@ -44,4 +40,5 @@ public class PluginBodySandbox {
return controllerAccess;
}).getContent());
}
}

View File

@ -1,7 +1,13 @@
package com.rusefi.ts_plugin;
import com.efiAnalytics.plugin.ecu.ControllerAccess;
import com.efiAnalytics.plugin.ecu.ControllerException;
import com.efiAnalytics.plugin.ecu.ControllerParameterChangeListener;
import com.opensr5.ini.IniFileModel;
import com.opensr5.ini.field.IniField;
import com.rusefi.TsTuneReader;
import com.rusefi.autoupdate.AutoupdateUtil;
import com.rusefi.config.generated.Fields;
import com.rusefi.tools.online.Online;
import com.rusefi.tools.online.UploadResult;
import com.rusefi.ts_plugin.util.ManifestHelper;
@ -16,6 +22,7 @@ import org.putgemin.VerticalFlowLayout;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.Map;
import java.util.function.Supplier;
/**
@ -36,6 +43,20 @@ public class PluginEntry implements TsPluginBody {
private UploaderStatus uploaderStatus = new UploaderStatus();
private final Timer timer = new Timer(1000 /* one second */, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Timer! " + System.currentTimeMillis() + " " + timer + " " + e);
}
});
ControllerParameterChangeListener listener = new ControllerParameterChangeListener() {
@Override
public void parameterValueChanged(String parameterName) {
System.out.println("Parameter value changed " + parameterName);
timer.restart();
}
};
/**
* the real constructor - this one is invoked via reflection
@ -45,6 +66,9 @@ public class PluginEntry implements TsPluginBody {
}
public PluginEntry(Supplier<ControllerAccess> controllerAccessSupplier) {
System.out.println("PluginEntry init " + this);
timer.stop();
timer.setRepeats(false);
this.controllerAccessSupplier = controllerAccessSupplier;
upload.setBackground(new Color(0x90EE90));
@ -55,7 +79,7 @@ public class PluginEntry implements TsPluginBody {
String configurationName = getConfigurationName();
if ((currentConfiguration == null && configurationName != null)
|| !currentConfiguration.equals(configurationName)) {
handleConfigurationChange(configurationName);
handleConfigurationChange(configurationName, controllerAccessSupplier.get());
}
boolean isProjectActive = configurationName != null;
@ -132,13 +156,35 @@ public class PluginEntry implements TsPluginBody {
/**
* This method is invoked every time we defect a switch between projects
*/
private void handleConfigurationChange(String configurationName) {
private void handleConfigurationChange(String configurationName, ControllerAccess controllerAccess) {
uploaderStatus.readTuneState(configurationName);
if (configurationName != null) {
subscribeToUpdates(configurationName, controllerAccess);
}
updateUploadEnabled();
currentConfiguration = configurationName;
}
private void subscribeToUpdates(String configurationName, ControllerAccess controllerAccess) {
IniFileModel model = new IniFileModel().readIniFile(TsTuneReader.getProjectModeFileName(configurationName));
Map<String, IniField> allIniFields = model.allIniFields;
if (model.allIniFields == null)
return;
for (Map.Entry<String, IniField> field : allIniFields.entrySet()) {
boolean isOnlineTuneField = field.getValue().getOffset() >= Fields.engine_configuration_s_size;
if (!isOnlineTuneField) {
try {
controllerAccess.getControllerParameterServer().subscribe(configurationName, field.getKey(), listener);
} catch (ControllerException e) {
throw new IllegalStateException(e);
}
}
}
}
public static boolean isEmpty(Constant constant) {
if (constant == null)
return true;