Created
August 12, 2014 01:58
-
-
Save Eviltechie/8c96262df9ce632cc34a to your computer and use it in GitHub Desktop.
Daktronics All Sport Character Generator Baseball
This file contains 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
package to.joe.opencg.baseball.control; | |
import jssc.SerialPort; | |
import jssc.SerialPortException; | |
public class SerialThread extends Thread { | |
public volatile int awayRuns = 0; | |
public volatile int homeRuns = 0; | |
public volatile int balls = 0; | |
public volatile int strikes = 0; | |
public volatile int outs = 0; | |
public volatile int inning = 1; | |
public volatile boolean topOfInning = true; | |
public volatile int atBat = -1; | |
public volatile boolean error; | |
public volatile int errorPosition = -1; | |
public volatile boolean hit; | |
private SerialPort port; | |
public SerialThread(String port) throws SerialPortException { | |
this.port = new SerialPort(port); | |
this.port.openPort(); | |
this.port.setParams(9600, 8, 1, 0); | |
} | |
@Override | |
public void run() { | |
try { | |
while (!Thread.interrupted()) { | |
String buffer; | |
do { | |
buffer = port.readString(1); | |
} while (!buffer.equals("\u0001")); | |
StringBuilder b = new StringBuilder(); | |
do { | |
buffer = port.readString(1); | |
b.append(buffer); | |
} while (!buffer.equals("\u0004")); | |
String capture = b.substring(0, b.length() - 1); | |
if (capture.charAt(7) != ' ') { | |
awayRuns = Integer.parseInt(capture.substring(6, 8).trim()); | |
} else { | |
awayRuns = 0; | |
} | |
if (capture.charAt(3) != ' ') { | |
homeRuns = Integer.parseInt(capture.substring(2, 4).trim()); | |
} else { | |
homeRuns = 0; | |
} | |
if (capture.charAt(47) != ' ') { | |
balls = Integer.parseInt(capture.substring(47, 48)); | |
} else { | |
balls = 0; | |
} | |
if (capture.charAt(48) != ' ') { | |
strikes = Integer.parseInt(capture.substring(48, 49)); | |
} else { | |
strikes = 0; | |
} | |
if (capture.charAt(49) != ' ') { | |
outs = Integer.parseInt(capture.substring(49, 50)); | |
} else { | |
outs = 0; | |
} | |
if (capture.charAt(9) != ' ') { | |
inning = Integer.parseInt(capture.substring(8, 10).trim()); | |
} else { | |
inning = 1; | |
} | |
topOfInning = capture.charAt(27) == '*'; | |
if (capture.charAt(41) != ' ') { | |
atBat = Integer.parseInt(capture.substring(40, 42).trim()); | |
} else { | |
atBat = -1; | |
} | |
if (capture.charAt(51) == 'E') { | |
error = true; | |
if (capture.charAt(58) != ' ') { | |
errorPosition = Integer.parseInt(capture.substring(57, 59).trim()); | |
} else { | |
errorPosition = -1; | |
} | |
} else { | |
error = false; | |
errorPosition = -1; | |
} | |
if (capture.charAt(50) == 'H') { | |
hit = true; | |
} else { | |
hit = false; | |
} | |
} | |
port.closePort(); | |
} catch (SerialPortException e) { | |
//TODO | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment