diff --git a/simgui-ds.json b/simgui-ds.json new file mode 100644 index 0000000..73cc713 --- /dev/null +++ b/simgui-ds.json @@ -0,0 +1,92 @@ +{ + "keyboardJoysticks": [ + { + "axisConfig": [ + { + "decKey": 65, + "incKey": 68 + }, + { + "decKey": 87, + "incKey": 83 + }, + { + "decKey": 69, + "decayRate": 0.0, + "incKey": 82, + "keyRate": 0.009999999776482582 + } + ], + "axisCount": 3, + "buttonCount": 4, + "buttonKeys": [ + 90, + 88, + 67, + 86 + ], + "povConfig": [ + { + "key0": 328, + "key135": 323, + "key180": 322, + "key225": 321, + "key270": 324, + "key315": 327, + "key45": 329, + "key90": 326 + } + ], + "povCount": 1 + }, + { + "axisConfig": [ + { + "decKey": 74, + "incKey": 76 + }, + { + "decKey": 73, + "incKey": 75 + } + ], + "axisCount": 2, + "buttonCount": 4, + "buttonKeys": [ + 77, + 44, + 46, + 47 + ], + "povCount": 0 + }, + { + "axisConfig": [ + { + "decKey": 263, + "incKey": 262 + }, + { + "decKey": 265, + "incKey": 264 + } + ], + "axisCount": 2, + "buttonCount": 6, + "buttonKeys": [ + 260, + 268, + 266, + 261, + 269, + 267 + ], + "povCount": 0 + }, + { + "axisCount": 0, + "buttonCount": 0, + "povCount": 0 + } + ] +} diff --git a/simgui.json b/simgui.json new file mode 100644 index 0000000..0c4f056 --- /dev/null +++ b/simgui.json @@ -0,0 +1,15 @@ +{ + "NTProvider": { + "types": { + "/FMSInfo": "FMSInfo", + "/LiveWindow/LED": "Subsystem", + "/LiveWindow/TestMotor": "Subsystem", + "/LiveWindow/Ungrouped/Scheduler": "Scheduler" + } + }, + "NetworkTables": { + "SmartDashboard": { + "open": true + } + } +} diff --git a/src/main/java/frc4388/utility/DesmosClient.html b/src/main/java/frc4388/utility/DesmosClient.html index 7e0a472..b842852 100644 --- a/src/main/java/frc4388/utility/DesmosClient.html +++ b/src/main/java/frc4388/utility/DesmosClient.html @@ -42,55 +42,59 @@ variables = JSON.parse(this.responseText); for(let variable of variables) { - console.log(); if(EXPRESSION_TYPES['expression'].includes(variable['type'])) { variable['lname'] = latexName(variable['name']); calculator.setExpression({ id: variable['name'], latex: variable['lname'] + '=' + variable['value']}); } else if(EXPRESSION_TYPES['table'].includes(variable['type'])) { - let cols = []; - for(let col of variable['value'].split('\s')) { - col = col.split(','); - let latexStr = latexName(col[0]); - let valuesArr = col.slice(1, col.length); - - cols.push({ latex: latexStr, values: valuesArr }); - } - + let cols = getColumns(variable['value'].split(' ')); calculator.setExpression({ type: 'table', id: variable['name'], columns: cols}); - break; - } else { - console.log('Invalid type : ' + variable['type']); - } + } else + console.log('Invalid input type : ' + variable['type']); } setTimeout(requestVariables, 0); } + function getColumns(unparsedCols) { + let cols = []; + for(let col of unparsedCols) { + col = col.split(','); + let latexStr = latexName(col[0]); + let valuesArr = col.slice(1, col.length); + + cols.push({ latex: latexStr, values: valuesArr }); + } + + return cols; + } + function getVariables() { let vars = []; let expressions = calculator.getExpressions(); for(expression of expressions) { - if(expression['type'] === 'expression') { - readVariable(expression['latex']); - } else { - console.log('Invalid type : ' + expression['type']); - } + if(expression['type'] === 'expression') + vars = readVariable(expression['latex']); + else + console.log('Invalid output type : ' + expression['type']); } return vars; } function readVariable(latex) { - let lname = expression['latex'].split('=')[0]; - let lvalue = expression['latex'].split('=')[1]; + let vars = []; + let lname = latex.split('=')[0]; + let lvalue = latex.split('=')[1]; if(lname && lname != '' && lvalue && lvalue != '') { let name = regularName(lname); let value = regularValue(lvalue); - vars.push({"name": name, "value": value}); + vars.push({"name": name, "type": "expression", "value": value}); } + + return vars; } function latexName(name) { @@ -117,7 +121,9 @@ let stringified = ''; for(let variable of vars) { - stringified += variable['name'] + '\t' + variable['value'] + '\n'; + stringified += variable['name'] + '\t' + + variable['type'] + '\t' + + variable['value'] + '\n'; } return stringified; diff --git a/src/main/java/frc4388/utility/DesmosServer.java b/src/main/java/frc4388/utility/DesmosServer.java index b5e7bab..4cc1e16 100644 --- a/src/main/java/frc4388/utility/DesmosServer.java +++ b/src/main/java/frc4388/utility/DesmosServer.java @@ -9,6 +9,8 @@ import java.net.Socket; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; import org.opencv.core.Point; @@ -18,7 +20,7 @@ import org.opencv.core.Point; * @author Daniel McGrath * */ public class DesmosServer extends Thread { - private static HashMap desmosVariables = new HashMap<>(); + private static HashMap desmosQueue = new HashMap<>(); private static HashMap readVariables = new HashMap<>(); private static boolean running = false; @@ -42,7 +44,7 @@ public class DesmosServer extends Thread { * Creates DesmosServer running on port 5500 * */ public DesmosServer() { - activePort = 5500; + activePort = 8000; } @Override @@ -77,7 +79,7 @@ public class DesmosServer extends Thread { /** * Handles client requests * - * @param The client connection + * @param client The client connection * @throws IOException * */ public void handleClient(Socket client) throws IOException { @@ -114,7 +116,7 @@ public class DesmosServer extends Thread { * {"list": "[2,4]"} * ] * - * @param The client connection + * @param client The client connection * @throws IOException * */ public void sendResponse(Socket client) throws IOException { @@ -140,13 +142,17 @@ public class DesmosServer extends Thread { public static String getJSONOutput() { String json = "["; - if(!desmosVariables.isEmpty()) { - for(String key : desmosVariables.keySet()) { + if(!desmosQueue.isEmpty()) { + Set keySet = new HashSet<>(desmosQueue.keySet()); + + for(String key : keySet) { json += "\n\t{" + "\"name\":\"" + key + "\"," - + "\"type\":\"" + desmosVariables.get(key)[0] + "\"," - + "\"value\":\"" + desmosVariables.get(key)[1] + "\"" + + "\"type\":\"" + desmosQueue.get(key)[0] + "\"," + + "\"value\":\"" + desmosQueue.get(key)[1] + "\"" + "},"; + + desmosQueue.remove(key); } json = json.substring(0, json.length()-1); // remove comma at the end @@ -184,32 +190,29 @@ public class DesmosServer extends Thread { // --------------------------------------------------------------------- public static void putInteger(String name, Integer value) { - desmosVariables.put(name, new String[] {"integer", value.toString()}); + desmosQueue.put(name, new String[] {"integer", value.toString()}); } public static void putDouble(String name, Double value) { - desmosVariables.put(name, new String[] {"double", value.toString()}); + desmosQueue.put(name, new String[] {"double", value.toString()}); } public static void putPoint(String name, Point point) { - desmosVariables.put(name, new String[] {"point", "(" + point.x + "," + point.y + ")"}); + desmosQueue.put(name, new String[] {"point", "(" + point.x + "," + point.y + ")"}); } public static void putArray(String name, double... arr) { - desmosVariables.put(name, new String[] {"array", Arrays.toString(arr).replace(" ", "")}); + desmosQueue.put(name, new String[] {"array", Arrays.toString(arr).replace(" ", "")}); } public static void putTable(String name, Object... table) { - // Check parameters - for(int i = 0; i < table.length; i += 2) - if(!(table[i] instanceof String)) { return; } - - for(int i = 1; i < table.length; i += 2) - if(!(table[i] instanceof double[])) { return; } - String tableStr = ""; for(int i = 0; i < table.length; i += 2) { + // Check parameters + if(!(table[i] instanceof String)) { return; } + if(!(table[i+1] instanceof double[])) { return; } + tableStr += table[i] + ","; String values = Arrays.toString((double[]) table[i+1]).replace(" ", ""); tableStr += values.substring(1, values.length() - 1); @@ -218,7 +221,7 @@ public class DesmosServer extends Thread { tableStr = tableStr.substring(0, tableStr.length()-1); // remove space at the end - desmosVariables.put(name, new String[] {"table", tableStr}); + desmosQueue.put(name, new String[] {"table", tableStr}); } // ---------------------------------------------------------------------