WiiLi Wiki frontpage Include your post in the News Get links Hoteles Quito
WiiLi.org Forum Index WiiLi.org
a new revolution
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WiiRemoteJ and Arduino
Goto page Previous  1, 2
 
Post new topic   Reply to topic    WiiLi.org Forum Index -> WiiremoteJ
View previous topic :: View next topic  
Author Message
Cha0s
Site Admin


Joined: 17 Jan 2007
Posts: 466

Digg It
PostPosted: Sat Apr 12, 2008 8:53 pm    Post subject:

Code:
public class wii_Arduino extends WiiRemoteAdapter{
   
    static WiiRemote remote;
    static byte[] extData;
    static int extFirstByte;
    public int x, y, z;
    static WiiRemoteExtension ABC;
   
    public static void main (String args[]){
        try{
           
             WiiRemoteJ.setConsoleLoggingAll();
           
            WiiRemoteDiscoveryListener wrdlistener = new WiiRemoteDiscoveryListener()
            {
               
                public void wiiRemoteDiscovered(WiiRemoteDiscoveredEvent evt)
                {
                    evt.getWiiRemote().addWiiRemoteListener(new wii(evt.getWiiRemote()));
                }
               
                public void findFinished(int numberFound)
                {
                    System.out.println("Found " + numberFound + " remotes!");
                }
            };
       
           
            //Find and connect to a Wii Remote
            remote = WiiRemoteJ.findRemote();
            remote.addWiiRemoteListener(new wii_Arduino(remote));
            remote.setAccelerometerEnabled(true);
           
            remote.getButtonMaps().add(new ButtonMap(WRButtonEvent.HOME, ButtonMap.NUNCHUK, WRNunchukExtensionEvent.C, new int[]{java.awt.event.KeyEvent.VK_CONTROL},
                                            java.awt.event.InputEvent.BUTTON1_MASK, 0, -1));
            WiiRemoteExtensionFactory factory = remote.getExtensionFactory();
           
            factory.removeExtension((short)0x7D7E);           
            factory.registerWiiRemoteExtension(ABC=new WiiRemoteExtension(6){
                 
            public boolean isPayloadValid(int payload){                         
                    System.out.println("Inside Payload..............1");                     
                    return payload == getPayload();
                }
               
                public void decryptExtensionInput(byte[] arg0, int arg1, int arg2){
                    System.out.println("Inside DecryptExtension........2");
                }
               
                public short getCode(){
                    System.out.print("Inside getCode...................3");
                    //It works with any address !!!
           return (short)0x7D7E;                     
                }
               
       // This method never execute!
                public WRExtensionEvent createWRExtensionEvent(WiiRemote remote1, byte[] arg1, int arg2){ 
                    System.out.println("createWRExtensionEvent..........4");
               
                    //you need to make your own extension event class
                    //to parse the data in arg1 and arg2!!!
                    //this code shouldn't have errors, but you won't get data
                    //until you make your own WRExtensionEvent class.
                    return new WRExtensionEvent(remote1){};
                   
                }
            });
           
        remote.setExtensionEnabled(true);   
        }
        catch(Exception e){e.printStackTrace();}       
    }
   
       
   // Used this method, because this event fire after connecting Arduino (I added the listener for wii)
    public void extensionUnknown()
    {
        System.out.println("Extension unknown............................");
    }
       
    public void extensionInputReceived(WRExtensionEvent evt){
            System.out.println("Event received.");
           
    }


Please read the API docs. You're not using these classes correctly!
_________________
Cha0s
Back to top
View user's profile Send private message
sumon



Joined: 30 Mar 2008
Posts: 6
Location: Sweden

Digg It
PostPosted: Sun Apr 13, 2008 2:18 pm    Post subject:

Hi Cha0s,

Absolutely I have no idea how to create my own WRExtensionEvent class and retrieve the data from that event Sad I am getting more confused by reading the documentation (my java skills…). I am just wondering if you can write something for me, for my project! In Arduino 6 bytes of data are available to send to wii.

Thanks in advance for your kind help.

/Sumon
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
Cha0s
Site Admin


Joined: 17 Jan 2007
Posts: 466

Digg It
PostPosted: Mon Apr 14, 2008 12:24 am    Post subject:

I have no idea how Arduino works. To program the createWRExtensionEvent method, you need to know this. I'd love to help you, but I am not interested in learning about the Arduino. You're gonna have to try to figure this out on your own, my friend.
_________________
Cha0s
Back to top
View user's profile Send private message
sumon



Joined: 30 Mar 2008
Posts: 6
Location: Sweden

Digg It
PostPosted: Tue Apr 15, 2008 12:41 am    Post subject:

Sound great...! I am working with Arduino and expected to get something soon. But would you please explain the parameters of the method createWRExtensionEvents for me?

Byte[] input: Is it the bytes value by which extension will identify itself, like 0x0000 (Encrypted 0xFEFE) for Nunchuk?

int offset: why we need it? As every extension sends back data to wii in 6 bytes chunk.

I may have to ask you some others question in future and hope you wouldn’t mind. Basically I have already gone quite far with your API in my project and don’t want to switch back to something else for these experiments Sad

/Sumon
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
Cha0s
Site Admin


Joined: 17 Jan 2007
Posts: 466

Digg It
PostPosted: Tue Apr 15, 2008 4:04 pm    Post subject:

From the API:
WiiRemoteJ API wrote:
input - the data input from the extension port.
offset - the position of the first byte of extension data in input.


The input is the information received from the Wii Remote and the offset is where the Extension data begins. You need to use the input to parse the data from the extension.
_________________
Cha0s
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    WiiLi.org Forum Index -> WiiremoteJ All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group