Last active
June 13, 2019 23:52
-
-
Save nhalstead/a1efffa70953ad8e124db55721c3bca3 to your computer and use it in GitHub Desktop.
Using this you are able to generate some java code for `RobotMap.java`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* $str will hold a value that is copied from Excel or Google Sheets. | |
* This will export Java code for RobotMap.java | |
* | |
* @author Noah Halstead <[email protected]> | |
* | |
*/ | |
$str = <<<EOF | |
DIO0 upperLimit | |
DIO1 lowerLimit | |
DIO4 leftEncoder | |
DIO5 leftEncoderNegative | |
DIO6 rightEncoder | |
DIO7 rightEncoderNegative | |
DIO8 hatchSwitchAutoClose | |
DIO9 ballLoaded | |
VAR_DEBUG TRUE | |
VAR_REDUCESPEED 0.8 | |
EOF; | |
$re = '/((DIO|PWM|AN|CAN|USB|PCN)([0-9]*)\t([a-zA-Z]*)|VAR_([a-zA-Z0-9]*)(\t)([a-zA-Z0-9]*))/m'; | |
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); | |
header("Content-Type: text/plain"); | |
$list = []; | |
foreach($matches as $row){ | |
$type = "object"; | |
if(!empty($row[5]) && !empty($row[6])) { | |
$value = "null"; | |
if(strtolower($row[7]) == "true" || $row[7] == "1"){ | |
$type = "boolean"; | |
$value = "true"; | |
} | |
else if(strtolower($row[7]) == "false" || $row[7] == "0"){ | |
$type = "boolean"; | |
$value = "false"; | |
} | |
else if(is_numaric($row[7])){ | |
$type = "int"; | |
$value = $row[7]; | |
} | |
else { | |
$type = "string"; | |
$value = "\"".$row[7]."\""; | |
} | |
$list["VAR"][] = [ | |
$type, | |
$value, | |
strtoupper($row[5]), | |
]; | |
} | |
else { | |
$type = "int"; | |
$list[trim(strtoupper($row[2]))][] = [ | |
$type, | |
$row[3], | |
strtoupper($row[4]), | |
]; | |
} | |
} | |
foreach($list as $type => $typeList){ | |
echo "\r\n\r\n\t// ".$type."\r\n"; | |
foreach($typeList as $rowRegex){ | |
echo "\tpublic static ".$rowRegex[0]." ".$rowRegex[2]." = ".$rowRegex[1].";\r\n"; | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DIO | |
public static int UPPERLIMIT = 0; | |
public static int LOWERLIMIT = 1; | |
public static int LEFTENCODER = 4; | |
public static int LEFTENCODERNEGATIVE = 5; | |
public static int RIGHTENCODER = 6; | |
public static int RIGHTENCODERNEGATIVE = 7; | |
public static int HATCHSWITCHAUTOCLOSE = 8; | |
public static int BALLLOADED = 9; | |
// VAR | |
public static boolean DEBUG = true; | |
public static boolean REDUCESPEED = false; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment