import com.illposed.osc.OSCMessage;
import com.illposed.osc.transport.OSCPortOut;

import java.net.InetAddress;
import java.util.Arrays;

public class ArduinoCommunication {
    private InetAddress address;
    private int port;
    private OSCPortOut oscPortOut;

    public ArduinoCommunication(String ipAdress, int portNr) {
        try{
            address = InetAddress.getByName(ipAdress);
            port = portNr;
            oscPortOut = new OSCPortOut(address, port);
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

    public void sendMessage(int a, double x, double y){
        String oscAddress = "/arduino/command"; // OSC-Adresse für die Nachricht
        OSCMessage message = new OSCMessage(oscAddress, Arrays.asList(a, x, y));
        try {
            oscPortOut.send(message);
        }
        catch (Exception e){
            e.printStackTrace();
        }
        System.out.println("OSC Nachricht gesendet: " + message);
    }
}
