mirror of
https://github.com/Team4388/2022NoWayHome.git
synced 2026-06-09 08:48:07 -06:00
Table fix, type safety, and queue
This commit is contained in:
@@ -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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"NTProvider": {
|
||||||
|
"types": {
|
||||||
|
"/FMSInfo": "FMSInfo",
|
||||||
|
"/LiveWindow/LED": "Subsystem",
|
||||||
|
"/LiveWindow/TestMotor": "Subsystem",
|
||||||
|
"/LiveWindow/Ungrouped/Scheduler": "Scheduler"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"NetworkTables": {
|
||||||
|
"SmartDashboard": {
|
||||||
|
"open": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,55 +42,59 @@
|
|||||||
variables = JSON.parse(this.responseText);
|
variables = JSON.parse(this.responseText);
|
||||||
|
|
||||||
for(let variable of variables) {
|
for(let variable of variables) {
|
||||||
console.log();
|
|
||||||
if(EXPRESSION_TYPES['expression'].includes(variable['type'])) {
|
if(EXPRESSION_TYPES['expression'].includes(variable['type'])) {
|
||||||
variable['lname'] = latexName(variable['name']);
|
variable['lname'] = latexName(variable['name']);
|
||||||
calculator.setExpression({ id: variable['name'], latex: variable['lname'] + '=' + variable['value']});
|
calculator.setExpression({ id: variable['name'], latex: variable['lname'] + '=' + variable['value']});
|
||||||
} else if(EXPRESSION_TYPES['table'].includes(variable['type'])) {
|
} else if(EXPRESSION_TYPES['table'].includes(variable['type'])) {
|
||||||
let cols = [];
|
let cols = getColumns(variable['value'].split(' '));
|
||||||
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 });
|
|
||||||
}
|
|
||||||
|
|
||||||
calculator.setExpression({ type: 'table', id: variable['name'], columns: cols});
|
calculator.setExpression({ type: 'table', id: variable['name'], columns: cols});
|
||||||
break;
|
} else
|
||||||
} else {
|
console.log('Invalid input type : ' + variable['type']);
|
||||||
console.log('Invalid type : ' + variable['type']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(requestVariables, 0);
|
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() {
|
function getVariables() {
|
||||||
let vars = [];
|
let vars = [];
|
||||||
let expressions = calculator.getExpressions();
|
let expressions = calculator.getExpressions();
|
||||||
|
|
||||||
for(expression of expressions) {
|
for(expression of expressions) {
|
||||||
if(expression['type'] === 'expression') {
|
if(expression['type'] === 'expression')
|
||||||
readVariable(expression['latex']);
|
vars = readVariable(expression['latex']);
|
||||||
} else {
|
else
|
||||||
console.log('Invalid type : ' + expression['type']);
|
console.log('Invalid output type : ' + expression['type']);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return vars;
|
return vars;
|
||||||
}
|
}
|
||||||
|
|
||||||
function readVariable(latex) {
|
function readVariable(latex) {
|
||||||
let lname = expression['latex'].split('=')[0];
|
let vars = [];
|
||||||
let lvalue = expression['latex'].split('=')[1];
|
let lname = latex.split('=')[0];
|
||||||
|
let lvalue = latex.split('=')[1];
|
||||||
|
|
||||||
if(lname && lname != '' && lvalue && lvalue != '') {
|
if(lname && lname != '' && lvalue && lvalue != '') {
|
||||||
let name = regularName(lname);
|
let name = regularName(lname);
|
||||||
let value = regularValue(lvalue);
|
let value = regularValue(lvalue);
|
||||||
|
|
||||||
vars.push({"name": name, "value": value});
|
vars.push({"name": name, "type": "expression", "value": value});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return vars;
|
||||||
}
|
}
|
||||||
|
|
||||||
function latexName(name) {
|
function latexName(name) {
|
||||||
@@ -117,7 +121,9 @@
|
|||||||
let stringified = '';
|
let stringified = '';
|
||||||
|
|
||||||
for(let variable of vars) {
|
for(let variable of vars) {
|
||||||
stringified += variable['name'] + '\t' + variable['value'] + '\n';
|
stringified += variable['name'] + '\t'
|
||||||
|
+ variable['type'] + '\t'
|
||||||
|
+ variable['value'] + '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
return stringified;
|
return stringified;
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import java.net.Socket;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.opencv.core.Point;
|
import org.opencv.core.Point;
|
||||||
|
|
||||||
@@ -18,7 +20,7 @@ import org.opencv.core.Point;
|
|||||||
* @author Daniel McGrath
|
* @author Daniel McGrath
|
||||||
* */
|
* */
|
||||||
public class DesmosServer extends Thread {
|
public class DesmosServer extends Thread {
|
||||||
private static HashMap<String, String[]> desmosVariables = new HashMap<>();
|
private static HashMap<String, String[]> desmosQueue = new HashMap<>();
|
||||||
private static HashMap<String, String[]> readVariables = new HashMap<>();
|
private static HashMap<String, String[]> readVariables = new HashMap<>();
|
||||||
|
|
||||||
private static boolean running = false;
|
private static boolean running = false;
|
||||||
@@ -42,7 +44,7 @@ public class DesmosServer extends Thread {
|
|||||||
* Creates DesmosServer running on port 5500
|
* Creates DesmosServer running on port 5500
|
||||||
* */
|
* */
|
||||||
public DesmosServer() {
|
public DesmosServer() {
|
||||||
activePort = 5500;
|
activePort = 8000;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,7 +79,7 @@ public class DesmosServer extends Thread {
|
|||||||
/**
|
/**
|
||||||
* Handles client requests
|
* Handles client requests
|
||||||
*
|
*
|
||||||
* @param The client connection
|
* @param client The client connection
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* */
|
* */
|
||||||
public void handleClient(Socket client) throws IOException {
|
public void handleClient(Socket client) throws IOException {
|
||||||
@@ -114,7 +116,7 @@ public class DesmosServer extends Thread {
|
|||||||
* {"list": "[2,4]"}
|
* {"list": "[2,4]"}
|
||||||
* ]
|
* ]
|
||||||
*
|
*
|
||||||
* @param The client connection
|
* @param client The client connection
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* */
|
* */
|
||||||
public void sendResponse(Socket client) throws IOException {
|
public void sendResponse(Socket client) throws IOException {
|
||||||
@@ -140,13 +142,17 @@ public class DesmosServer extends Thread {
|
|||||||
public static String getJSONOutput() {
|
public static String getJSONOutput() {
|
||||||
String json = "[";
|
String json = "[";
|
||||||
|
|
||||||
if(!desmosVariables.isEmpty()) {
|
if(!desmosQueue.isEmpty()) {
|
||||||
for(String key : desmosVariables.keySet()) {
|
Set<String> keySet = new HashSet<>(desmosQueue.keySet());
|
||||||
|
|
||||||
|
for(String key : keySet) {
|
||||||
json += "\n\t{"
|
json += "\n\t{"
|
||||||
+ "\"name\":\"" + key + "\","
|
+ "\"name\":\"" + key + "\","
|
||||||
+ "\"type\":\"" + desmosVariables.get(key)[0] + "\","
|
+ "\"type\":\"" + desmosQueue.get(key)[0] + "\","
|
||||||
+ "\"value\":\"" + desmosVariables.get(key)[1] + "\""
|
+ "\"value\":\"" + desmosQueue.get(key)[1] + "\""
|
||||||
+ "},";
|
+ "},";
|
||||||
|
|
||||||
|
desmosQueue.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
json = json.substring(0, json.length()-1); // remove comma at the end
|
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) {
|
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) {
|
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) {
|
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) {
|
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) {
|
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 = "";
|
String tableStr = "";
|
||||||
|
|
||||||
for(int i = 0; i < table.length; i += 2) {
|
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] + ",";
|
tableStr += table[i] + ",";
|
||||||
String values = Arrays.toString((double[]) table[i+1]).replace(" ", "");
|
String values = Arrays.toString((double[]) table[i+1]).replace(" ", "");
|
||||||
tableStr += values.substring(1, values.length() - 1);
|
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
|
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});
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user