...
Other usage style, it's working directly with the connection.
It is more decoupled, but less powerful
Code Block | ||||
---|---|---|---|---|
| ||||
import br.com.criativasoft.opendevice.connection.ConnectionListener; import br.com.criativasoft.opendevice.connection.ConnectionStatus; import br.com.criativasoft.opendevice.connection.DeviceConnection; import br.com.criativasoft.opendevice.connection.message.Message; import br.com.criativasoft.opendevice.core.command.DeviceCommand; import br.com.criativasoft.opendevice.core.connection.Connections; public class DemoBlinkCommandDemo implements ConnectionListener { public DemoBlinkCommandDemo() throws Exception { DeviceConnection conn = Connections.out.usb(); conn.addListener(this); conn.connect(); long delay = 500; while(conn.isConnected()) { conn.send(DeviceCommand.ON(1)); // '1' is Device ID not pin ! Thread.sleep(delay); conn.send(DeviceCommand.OFF(1)); Thread.sleep(delay); } System.out.println("TERMINATED !"); } public static void main(String[] args) throws Exception { new DemoBlinkCommandDemo(); } // ------------------------------------------------------------ // ------------- ConnectionListener Impl -------------------------- public void onMessageReceived(Message message, DeviceConnection connection) { String type = message.getClass().getSimpleName(); System.out.println("onMessageReceived("+type+"): "+ message); } public void connectionStateChanged(DeviceConnection connection, ConnectionStatus status) { System.out.println("connectionStateChanged : " + status); } } |
...