View unanswered posts | View active topics It is currently Thu Aug 13, 2020 1:24 pm

Reply to topic  [ 3 posts ] 
TETRIX Remote Control Buttons - Information 
Author Message
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 620
Post TETRIX Remote Control Buttons - Information
In ROBOTC 2.01, the behaviors of the Joy1Btn and Joy2Btn functions have been changed.

In previous versions, these functions would return the individual bit-mask value of the buttons. This means that following buttons would return the following values:
Button 1 = 1
Button 2 = 2
Button 3 = 4
Button 4 = 8

Because of this, most common usage of this function would be something like this:
while(joy1Btn(3) != 0)
Do Some Code

Which isn't always very intuitive.

To make this simpler, we added some bit logic to reduce all button values to return a "1" when the button is pressed. So now that means...
Button 1 = 1
Button 2 = 1
Button 3 = 1
Button 4 = 1

For those who like to see things behind the scenes, lines 83-86 from the JoystickInclude.c file shows how this works:
bool joy1Btn(int btn)
{   return ((joystick.joy1_Buttons & (1 << (btn - 1))) != 0);  }
bool joy2Btn(int btn)
{   return ((joystick.joy2_Buttons & (1 << (btn - 1))) != 0);  }

I hope this provides some clarification on button usage. If not, please post in this topic and we'll try and update this post to provide clearer information.

Timothy Friez
ROBOTC Developer - SW Engineer

Thu Jan 14, 2010 10:30 am

Joined: Thu Nov 07, 2013 7:40 pm
Posts: 4
Post Re: TETRIX Remote Control Buttons - Information
Would'nt it be much easier to do
return joystick.joy1_Buttons >> btn) & 1);

Obviously it would be the same, and it is much easier to read, so my question is does the method you posted have a slight speed advantage?
Edit: after reviewing my post, I am pretty sure the method I posted would have speed advantages, because it has nearly half the amount of operations.

Sat Nov 09, 2013 7:36 am

Joined: Mon Feb 10, 2014 8:03 am
Posts: 1
Post Re: TETRIX Remote Control Buttons - Information
thanks for that information..keep us updated..

Fri Apr 18, 2014 10:31 am
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

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 post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.