board-specific usability #808
This commit is contained in:
parent
7ea2860dc7
commit
34ce9f529c
|
@ -1,5 +1,7 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.enum_reader.Value;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
@ -14,6 +16,7 @@ import java.util.Set;
|
|||
public class EnumToString {
|
||||
public final static StringBuilder cppFileContent = new StringBuilder();
|
||||
private final static StringBuilder headerFileContent = new StringBuilder();
|
||||
public static final String RELATIVE_PATH = "controllers/algo/rusefi_enums.h";
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length != 2) {
|
||||
|
@ -26,7 +29,7 @@ public class EnumToString {
|
|||
headerFileContent.append("#ifndef _A_H_HEADER_\r\n");
|
||||
headerFileContent.append("#define _A_H_HEADER_\r\n");
|
||||
|
||||
processFile(inputPath + File.separator + "controllers/algo/rusefi_enums.h");
|
||||
processFile(inputPath + File.separator + RELATIVE_PATH);
|
||||
|
||||
headerFileContent.append("#endif /*_A_H_HEADER_ */\r\n");
|
||||
|
||||
|
@ -69,7 +72,7 @@ public class EnumToString {
|
|||
|
||||
public static void process(Reader reader) throws IOException {
|
||||
EnumsReader.process(reader);
|
||||
for (Map.Entry<String, Set<String>> e : EnumsReader.enums.entrySet()) {
|
||||
for (Map.Entry<String, Set<Value>> e : EnumsReader.enums.entrySet()) {
|
||||
String enumName = e.getKey();
|
||||
cppFileContent.append(makeCode(enumName, e.getValue()));
|
||||
EnumToString.headerFileContent.append(getMethodSignature(enumName) + ";\r\n");
|
||||
|
@ -80,15 +83,15 @@ public class EnumToString {
|
|||
cppFileContent.setLength(0);
|
||||
}
|
||||
|
||||
private static String makeCode(String enumName, Set<String> values) {
|
||||
private static String makeCode(String enumName, Set<Value> values) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getMethodSignature(enumName) + "{\r\n");
|
||||
|
||||
sb.append("switch(value) {\r\n");
|
||||
|
||||
for (String e : values) {
|
||||
sb.append("case " + e + ":\r\n");
|
||||
sb.append(" return \"" + e + "\";\r\n");
|
||||
for (Value e : values) {
|
||||
sb.append("case " + e.getName() + ":\r\n");
|
||||
sb.append(" return \"" + e.getName() + "\";\r\n");
|
||||
}
|
||||
|
||||
sb.append(" }\r\n");
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.enum_reader.Value;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.rusefi.EnumsReader.isKeyValueLine;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -25,6 +27,9 @@ public class EnumToStringTest {
|
|||
"\tGPIO_UNASSIGNED = 0,\n" +
|
||||
"\tGPIO_INVALID = 1,\n" +
|
||||
"}brain_pin_e;"));
|
||||
|
||||
Set<Value> values = EnumsReader.enums.get("brain_pin_e");
|
||||
|
||||
assertEquals("const char *getBrain_pin_e(brain_pin_e value){\r\n" +
|
||||
"switch(value) {\r\n" +
|
||||
"case GPIO_INVALID:\r\n" +
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.enum_reader.Value;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
@ -9,9 +11,9 @@ import java.util.TreeMap;
|
|||
import java.util.TreeSet;
|
||||
|
||||
public class EnumsReader {
|
||||
private final static Set<String> currentValues = new TreeSet<>();
|
||||
private final static Set<Value> currentValues = new TreeSet<>();
|
||||
|
||||
public final static Map<String, Set<String>> enums = new TreeMap<>();
|
||||
public final static Map<String, Set<Value>> enums = new TreeMap<>();
|
||||
|
||||
public static void process(Reader in) throws IOException {
|
||||
boolean isInsideEnum = false;
|
||||
|
@ -28,7 +30,7 @@ public class EnumsReader {
|
|||
isInsideEnum = false;
|
||||
line = line.substring(1, line.length() - 1);
|
||||
System.out.println("Ending enum " + line);
|
||||
enums.put(line, new TreeSet<>(currentValues));
|
||||
enums.put(line, new TreeSet<Value>(currentValues));
|
||||
} else {
|
||||
line = line.replaceAll("//.+", "");
|
||||
if (isInsideEnum) {
|
||||
|
@ -38,7 +40,7 @@ public class EnumsReader {
|
|||
if (index != -1)
|
||||
line = line.substring(0, index);
|
||||
System.out.println("Line " + line);
|
||||
currentValues.add(line);
|
||||
currentValues.add(new Value(line));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package com.rusefi.enum_reader;
|
||||
|
||||
public class Value implements Comparable<Value> {
|
||||
private final String name;
|
||||
|
||||
public Value(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Value o) {
|
||||
return name.compareTo(o.name);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue