diff --git a/applications/HelloIOIO/src/main/java/ioio/examples/hello/MainActivity.java b/applications/HelloIOIO/src/main/java/ioio/examples/hello/MainActivity.java deleted file mode 100644 index c83915c68..000000000 --- a/applications/HelloIOIO/src/main/java/ioio/examples/hello/MainActivity.java +++ /dev/null @@ -1,153 +0,0 @@ -package ioio.examples.hello; - -import ioio.lib.api.DigitalOutput; -import ioio.lib.api.IOIO; -import ioio.lib.api.IOIO.VersionType; -import ioio.lib.api.exception.ConnectionLostException; -import ioio.lib.util.BaseIOIOLooper; -import ioio.lib.util.IOIOLooper; -import ioio.lib.util.android.IOIOActivity; - -import android.content.Context; -import android.os.Bundle; -import android.widget.Toast; -import android.widget.ToggleButton; - -/** - * This is the main activity of the HelloIOIO example application. - *

- * It displays a toggle button on the screen, which enables control of the - * on-board LED. This example shows a very simple usage of the IOIO, by using - * the {@link IOIOActivity} class. For a more advanced use case, see the - * HelloIOIOPower example. - */ -public class MainActivity extends IOIOActivity { - private ToggleButton button_; - private int numConnected_ = 0; - - /** - * Called when the activity is first created. Here we normally initialize - * our GUI. - */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - button_ = findViewById(R.id.button); - } - - /** - * A method to create our IOIO thread. - * - * @see ioio.lib.util.AbstractIOIOActivity#createIOIOThread() - */ - @SuppressWarnings("JavadocReference") - @Override - protected IOIOLooper createIOIOLooper() { - return new Looper(); - } - - private void showVersions(IOIO ioio, String title) { - toast(String.format("%s\n" + - "IOIOLib: %s\n" + - "Application firmware: %s\n" + - "Bootloader firmware: %s\n" + - "Hardware: %s", - title, - ioio.getImplVersion(VersionType.IOIOLIB_VER), - ioio.getImplVersion(VersionType.APP_FIRMWARE_VER), - ioio.getImplVersion(VersionType.BOOTLOADER_VER), - ioio.getImplVersion(VersionType.HARDWARE_VER))); - } - - private void toast(final String message) { - final Context context = this; - runOnUiThread(new Runnable() { - @Override - public void run() { - Toast.makeText(context, message, Toast.LENGTH_LONG).show(); - } - }); - } - - private void enableUi(final boolean enable) { - // This is slightly trickier than expected to support a multi-IOIO use-case. - runOnUiThread(new Runnable() { - @Override - public void run() { - if (enable) { - if (numConnected_++ == 0) { - button_.setEnabled(true); - } - } else { - if (--numConnected_ == 0) { - button_.setEnabled(false); - } - } - } - }); - } - - /** - * This is the thread on which all the IOIO activity happens. It will be run - * every time the application is resumed and aborted when it is paused. The - * method setup() will be called right after a connection with the IOIO has - * been established (which might happen several times!). Then, loop() will - * be called repetitively until the IOIO gets disconnected. - */ - class Looper extends BaseIOIOLooper { - /** - * The on-board LED. - */ - private DigitalOutput led_; - - /** - * Called every time a connection with IOIO has been established. - * Typically used to open pins. - * - * @throws ConnectionLostException When IOIO connection is lost. - * @see ioio.lib.util.IOIOLooper#setup() - */ - @SuppressWarnings("JavadocReference") - @Override - protected void setup() throws ConnectionLostException { - showVersions(ioio_, "IOIO connected!"); - led_ = ioio_.openDigitalOutput(0, true); - enableUi(true); - } - - /** - * Called repetitively while the IOIO is connected. - * - * @throws ConnectionLostException When IOIO connection is lost. - * @throws InterruptedException When the IOIO thread has been interrupted. - * @see ioio.lib.util.IOIOLooper#loop() - */ - @Override - public void loop() throws ConnectionLostException, InterruptedException { - led_.write(!button_.isChecked()); - Thread.sleep(100); - } - - /** - * Called when the IOIO is disconnected. - * - * @see ioio.lib.util.IOIOLooper#disconnected() - */ - @Override - public void disconnected() { - enableUi(false); - toast("IOIO disconnected"); - } - - /** - * Called when the IOIO is connected, but has an incompatible firmware version. - * - * @see ioio.lib.util.IOIOLooper#incompatible(IOIO) - */ - @Override - public void incompatible() { - showVersions(ioio_, "Incompatible firmware version!"); - } - } -} \ No newline at end of file diff --git a/applications/HelloIOIO/src/main/java/ioio/examples/hello/MainActivity.kt b/applications/HelloIOIO/src/main/java/ioio/examples/hello/MainActivity.kt new file mode 100644 index 000000000..b3286a383 --- /dev/null +++ b/applications/HelloIOIO/src/main/java/ioio/examples/hello/MainActivity.kt @@ -0,0 +1,146 @@ +package ioio.examples.hello + +import android.content.Context +import android.os.Bundle +import android.widget.Toast +import android.widget.ToggleButton +import ioio.lib.api.DigitalOutput +import ioio.lib.api.IOIO +import ioio.lib.api.IOIO.VersionType +import ioio.lib.api.exception.ConnectionLostException +import ioio.lib.util.BaseIOIOLooper +import ioio.lib.util.IOIOLooper +import ioio.lib.util.android.IOIOActivity + +/** + * This is the main activity of the HelloIOIO example application. + * + * + * It displays a toggle button on the screen, which enables control of the + * on-board LED. This example shows a very simple usage of the IOIO, by using + * the [IOIOActivity] class. For a more advanced use case, see the + * HelloIOIOPower example. + */ +class MainActivity : IOIOActivity() { + private var toggleButton: ToggleButton? = null + private var numConnected = 0 + + /** + * Called when the activity is first created. Here we normally initialize + * our GUI. + */ + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.main) + toggleButton = findViewById(R.id.button) + } + + /** + * A method to create our IOIO thread. + * + * @see ioio.lib.util.AbstractIOIOActivity.createIOIOThread + */ + override fun createIOIOLooper(): IOIOLooper { + return Looper() + } + + private fun showVersions(ioio: IOIO, title: String) { + toast( + String.format( + """ + %s + IOIOLib: %s + Application firmware: %s + Bootloader firmware: %s + Hardware: %s + """.trimIndent(), + title, + ioio.getImplVersion(VersionType.IOIOLIB_VER), + ioio.getImplVersion(VersionType.APP_FIRMWARE_VER), + ioio.getImplVersion(VersionType.BOOTLOADER_VER), + ioio.getImplVersion(VersionType.HARDWARE_VER) + ) + ) + } + + private fun toast(message: String) { + val context: Context = this + runOnUiThread { Toast.makeText(context, message, Toast.LENGTH_LONG).show() } + } + + private fun enableUi(enable: Boolean) { + // This is slightly trickier than expected to support a multi-IOIO use-case. + runOnUiThread { + if (enable) { + if (numConnected++ == 0) { + toggleButton!!.isEnabled = true + } + } else { + if (--numConnected == 0) { + toggleButton!!.isEnabled = false + } + } + } + } + + /** + * This is the thread on which all the IOIO activity happens. It will be run + * every time the application is resumed and aborted when it is paused. The + * method setup() will be called right after a connection with the IOIO has + * been established (which might happen several times!). Then, loop() will + * be called repetitively until the IOIO gets disconnected. + */ + internal inner class Looper : BaseIOIOLooper() { + /** + * The on-board LED. + */ + private var digitalOutput: DigitalOutput? = null + + /** + * Called every time a connection with IOIO has been established. + * Typically used to open pins. + * + * @throws ConnectionLostException When IOIO connection is lost. + * @see ioio.lib.util.IOIOLooper.setup + */ + @Throws(ConnectionLostException::class) + override fun setup() { + showVersions(ioio_, "IOIO connected!") + digitalOutput = ioio_.openDigitalOutput(0, true) + enableUi(true) + } + + /** + * Called repetitively while the IOIO is connected. + * + * @throws ConnectionLostException When IOIO connection is lost. + * @throws InterruptedException When the IOIO thread has been interrupted. + * @see ioio.lib.util.IOIOLooper.loop + */ + @Throws(ConnectionLostException::class, InterruptedException::class) + override fun loop() { + digitalOutput!!.write(!toggleButton!!.isChecked) + Thread.sleep(100) + } + + /** + * Called when the IOIO is disconnected. + * + * @see ioio.lib.util.IOIOLooper.disconnected + */ + override fun disconnected() { + enableUi(false) + toast("IOIO disconnected") + } + + /** + * Called when the IOIO is connected, but has an incompatible firmware version. + * + * @see ioio.lib.util.IOIOLooper.incompatible + */ + @Deprecated("Deprecated in Java") + override fun incompatible() { + showVersions(ioio_, "Incompatible firmware version!") + } + } +} diff --git a/gradlew b/gradlew index 65dcd68d6..1aa94a426 100755 --- a/gradlew +++ b/gradlew @@ -83,10 +83,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +131,13 @@ 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. + if ! command -v java >/dev/null 2>&1 + then + 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 fi # Increase the maximum file descriptors if we can. @@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 93e3f59f1..25da30dbd 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -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. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -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. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail