diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..9fb80d4 --- /dev/null +++ b/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c364f00 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.gradle +build +gradle + diff --git a/.project b/.project new file mode 100644 index 0000000..0d4667d --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + StackMatGen3TimerAPI + Project StackMatGen3TimerAPI created by Buildship. + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.buildship.core.gradleprojectnature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000..41b9140 --- /dev/null +++ b/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,11 @@ +build.commands=org.eclipse.jdt.core.javabuilder +connection.arguments= +connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) +connection.gradle.user.home=null +connection.java.home=null +connection.jvm.arguments= +connection.project.dir= +derived.resources=.gradle,build +eclipse.preferences.version=1 +natures=org.eclipse.jdt.core.javanature +project.path=\: diff --git a/README.md b/README.md index 7947b98..647c651 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,78 @@ # StackMatGen3TimerAPI StackMat Generation 3 Timer API + +## YuXin Timer + +The software works with the "YuXin Cube Timer V1", too. This piece of hardware can be connected to your computer's microphone input via a simple cable: On the timer it's a 2.5mm TS (mono) audio jack, for the PC side you need a 3.5mm audio jack (mono / TS or stereo / TRS). When you use a stereo jack, make sure to connect the **center** (Tip)! Initially, I chose the Sleeve which is not picked up by the software. + +The current time display is emitted at regular intervals, in a 10-byte ASCII telegram that totals about 80ms, in what looks like standard serial 12008N1 communication, least significant bit first, low voltage "1", high voltage "0": + +- One *instruction* byte + * For some reason **my** Yuxin timer only ever sends the "S" instruction (0x53). + * I do _not_ receive A, L, R, C, or Space instructions. + * As a consequence, [PrismaPuzzleTimer](https://github.com/phillip-hayes/PrismaPuzzleTimer) does show the elapsed time, but is unable to detect the start and end of a solve (!!) + * Since I only have a single unit that I have already tinkered with I cannot be sure if that's not a home-made malfunction, so __maybe__ Yuxin are not to blame, might well be my own fault. +- six digits, representing the time ("0" = 0x30 ... "9" = 0x39) +- one check digit +- one LF (0x0A) +- one CR (0x0D) + +For illustration, here is a plot of how "6.189" gets communicated as "S-006189-X-LF-CR". See the Yuxin folder for more images. This was taken off a unit with PCB date "2016-12-14" using [Soundcard Scope](https://www.zeitnitz.eu/scms/scope_en). To safeguard my PC against potentially harmful input signals, I whipped up a protection circuit with two antiparallel diodes and two resistors as a voltage divider. + +![YuXin Cube Timer V1 S-006189-X-LF-CR](yuxin/scope-006189_bw.jpg "YuXin Cube Timer V1 S-006189-X-LF-CR") + +Happy cubing! + +## Trying it out with the YuXin Timer + +1. You need Java. + - Any Java version should be OK (6,7,8). +1. Open a command line (CMD.EXE, Bash) + - Change to some working directory + - Check Java installation: `java -version` - this should show that Java is available. + - Download this repo/branch: `git clone --branch YuxinDocAmendment https://github.com/m9aertner/StackMatGen3TimerAPI.git` + - Change into the downloaded code: `cd StackMatGen3TimerAPI` +1. Build using [Gradle](http://gradle.org): `./gradlew build` + - This downloads Gradle (once), + - then builds the application's code and JAR file. + - Result is a JAR file: `build/libs/StackMatGen3TimerAPI.jar` +1. Execution + - Connect the timer with to your computer's Mic port (pink 3.5 mm TRS) + - Execute: `java -jar build/libs/StackMatGen3TimerAPI.jar` + - This JAR is executable via `Main-Class` entry in `META-INF/MANIFEST.MF` + - It feels a bit odd, but *no parameters* are supported. The Mixer `#5` is hard-coded. That works for me, not sure what that *magic constant* means. + - The app initializes, then waits for data from the timer. Any data recieved is decoded and shown on each _change_. + - As an example, here's how I start the app, then start the timer (Power button), start a solve, stop at 1s577, reset back to 0m00s000, and finally press Enter to quit. + +``` +StackMatGen3TimerAPI> java -jar build\libs\StackMatGen3TimerAPI.jar +12, 2017 9:06:47 PM au.com.emc.cubing.stackmat.StackmatManager start +INFORMATION: Starting Stackmat gen 3 manager +Apr 12, 2017 9:06:47 PM au.com.emc.cubing.stackmat.StackmatInterpreter initialize +INFORMATION: Initialising stackmat gen 3 interpreter +Apr 12, 2017 9:06:47 PM au.com.emc.cubing.stackmat.StackmatInterpreter doInBackground +INFORMATION: Starting Stackmat background thread +Apr 12, 2017 9:06:47 PM au.com.emc.cubing.stackmat.Main main +INFORMATION: Press Enter to continue... +0:00:000 +0:00:068 +0:00:197 +0:00:326 +0:00:455 +0:00:584 +0:00:713 +0:00:842 +0:00:971 +0:01:100 +0:01:220 +0:01:349 +0:01:478 +0:01:577 +0:00:000 + +Apr 12, 2017 9:06:59 PM au.com.emc.cubing.stackmat.Main main +INFORMATION: Stopping manager... +Apr 12, 2017 9:06:59 PM au.com.emc.cubing.stackmat.StackmatManager stop +INFORMATION: Stopping Stackmat gen 3 manager +``` + diff --git a/bin/StackmatGen3TimerAPI.jar b/bin/StackmatGen3TimerAPI.jar deleted file mode 100644 index 50de424..0000000 Binary files a/bin/StackmatGen3TimerAPI.jar and /dev/null differ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..fb78ac5 --- /dev/null +++ b/build.gradle @@ -0,0 +1,42 @@ +// Simple Gradle file to build StackMatGen3TimerAPI. +// +// Gradle can auto-install itself. See https://docs.gradle.org/current/userguide/gradle_wrapper.html +// Just call +// +// ./gradlew build +// +// to build. The result JAR file will be in +// +// build/libs/StackMatGen3TimerAPI.jar +// +// To run, call +// +// java -jar build/libs/StackMatGen3TimerAPI.jar +// +// This assumes java is in the PATH. Check using +// +// java -version +// + +apply plugin: 'java' + +sourceSets { + main { + java { + srcDirs = ['src'] // Non-standard source folder. Default is src/main/java. + } + } +} + +jar { + manifest { + attributes 'Main-Class': 'au.com.emc.cubing.stackmat.Main' + } +} + +// Load/install the wrapper. This is done once and the result is +// committed to version control. You do not need to call this. +task wrapper(type: Wrapper) { + gradleVersion = '3.5' +} + diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..9aa616c --- /dev/null +++ b/gradlew @@ -0,0 +1,169 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..e95643d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/au/com/emc/cubing/stackmat/Main.java b/src/au/com/emc/cubing/stackmat/Main.java index 9ee6d2f..75a7b57 100644 --- a/src/au/com/emc/cubing/stackmat/Main.java +++ b/src/au/com/emc/cubing/stackmat/Main.java @@ -1,5 +1,7 @@ package au.com.emc.cubing.stackmat; +import java.util.logging.Logger; + /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates @@ -11,19 +13,33 @@ */ public class Main { - public static void main(String[] args) { + private final static Logger LOGGER = Logger.getLogger(Main.class.getName()); + + public static void main(String[] args) throws Exception { StackmatManager smm = StackmatManager.getInstance(); - + smm.register(new StackmatReporterConsole()); - + smm.setSamplingRate(16000); smm.setMixerNumber(5); smm.setSwitchThreshold(100); - - smm.start(); - - System.console().readLine(); - + + smm.start(); + + try { + // There may be no console when running in Eclipse or other IDE + if( System.console() != null ) { + LOGGER.info("Press Enter to continue..."); + System.console().readLine(); + } else { + LOGGER.info("Waiting 60 seconds..."); + Thread.sleep(60l * 1000); + } + } finally { + LOGGER.info("Stopping manager..."); + smm.stop(); + } + } } diff --git a/src/au/com/emc/cubing/stackmat/StackmatInterpreter.java b/src/au/com/emc/cubing/stackmat/StackmatInterpreter.java index db96500..df181d2 100644 --- a/src/au/com/emc/cubing/stackmat/StackmatInterpreter.java +++ b/src/au/com/emc/cubing/stackmat/StackmatInterpreter.java @@ -1,7 +1,7 @@ package au.com.emc.cubing.stackmat; -import java.util.List; import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -75,7 +75,7 @@ public class StackmatInterpreter { private TargetDataLine line; - private StackmatState state = null; + // private StackmatState state = null; private boolean enabled = true; private int bitValueBetweenMessages = -1; diff --git a/yuxin/scope-000000_bw.jpg b/yuxin/scope-000000_bw.jpg new file mode 100644 index 0000000..ed14b59 Binary files /dev/null and b/yuxin/scope-000000_bw.jpg differ diff --git a/yuxin/scope-000297_bw.jpg b/yuxin/scope-000297_bw.jpg new file mode 100644 index 0000000..daae69b Binary files /dev/null and b/yuxin/scope-000297_bw.jpg differ diff --git a/yuxin/scope-001823_bw.jpg b/yuxin/scope-001823_bw.jpg new file mode 100644 index 0000000..3773dc8 Binary files /dev/null and b/yuxin/scope-001823_bw.jpg differ diff --git a/yuxin/scope-004676_bw.jpg b/yuxin/scope-004676_bw.jpg new file mode 100644 index 0000000..57be21e Binary files /dev/null and b/yuxin/scope-004676_bw.jpg differ diff --git a/yuxin/scope-006189_bw.jpg b/yuxin/scope-006189_bw.jpg new file mode 100644 index 0000000..62262ae Binary files /dev/null and b/yuxin/scope-006189_bw.jpg differ diff --git a/yuxin/scope-025382_bw.jpg b/yuxin/scope-025382_bw.jpg new file mode 100644 index 0000000..b3beb33 Binary files /dev/null and b/yuxin/scope-025382_bw.jpg differ