I'm working on this library I have a problem to make it work where I'm wrong?
how should I call it?
how should I call it?
B4X:
package com.spinter.test;
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.widget.Toast;
import android.widget.ToggleButton;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
@ShortName("test")
@Version(1.01f)
@Author("Spinter")
@DependsOn (values={"ioiolibandroid","ioiolibaccessory","ioiolibandroiddevice","ioiolibbt"})
@Permissions(values={"android.permission.INTERNET","android.permission.BLUETOOTH","android.permission.BLUETOOTH_ADMIN"})
public class MCrypt extends IOIOActivity {
//public class MCrypt {
//Toast.makeText(pBA.context,"Inizializated!", Toast.LENGTH_LONG).show();
//@SuppressWarnings("unused")
private static BA contextName = null;
private ToggleButton button_;
public void Initialize(BA pBA,String eventName) {
contextName =pBA;
//new Looper();
BA.Log("B4A log: Initialize ");
}
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()
*/
@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!");
}
}
/**
* A method to create our IOIO thread.
*
* @see ioio.lib.util.AbstractIOIOActivity#createIOIOThread()
* protected
*/
protected IOIOLooper createIOIOLooper() {
BA.Log("B4A log: looper ");
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(contextName.context, message, Toast.LENGTH_LONG).show();
}
});
}
private int numConnected_ = 0;
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);
}
}
}
});
}
}//fine