I am trying to create two versions of my driver control code, on that runs if a partner controller is connected, one that runs if it is not. a search in the forums turned up this as a method of telling
if( nVexRCReceiveState & 0x01 )
{
player1 = true;
// first joystick is connected
}
if( nVexRCReceiveState & 0x02 )
{
player2 = true;
// second joystick is connected
}
however that post was from 2012.
the problem I am finding is that both of those IF statements always seem to return true.
am i doing something wrong, or does this method not work with current versions of robotC, does any one know a way of doing this?
Linking to a particular post is almost impossible now, so here is some code from the “ROBOTC programming tips” thread I posted a couple of years ago. The above code is correct, you can only have the partner joystick if the main joystick is also available.
// send some useful information to the debug stream
void
PrintnVexRCReceiveState()
{
if( (nVexRCReceiveState & (vrXmit1 | vrXmit2)) == (vrXmit1 | vrXmit2) )
writeDebugStreamLine("Transmitter 1 and 2 connected");
else
if( nVexRCReceiveState & vrXmit1 )
writeDebugStreamLine("Transmitter 1 connected");
else
if( nVexRCReceiveState & vrXmit2 )
writeDebugStreamLine("Transmitter 2 connected");
if( nVexRCReceiveState & vrCompetitionSwitch )
writeDebugStreamLine("Competition switch is connected");
else
writeDebugStreamLine("Competition switch not connected");
}
// Monitor nVexRCReceiveState and show changes
task main()
{
unsigned int rcReceiveState = 0;
unsigned int last_rcReceiveState = 1; // cause print on program entry
while(1)
{
rcReceiveState = nVexRCReceiveState
if( rcReceiveState != last_rcReceiveState )
{
writeDebugStreamLine("rcReceiveState is %02X", rcReceiveState );
last_rcReceiveState = rcReceiveState;
PrintnVexRCReceiveState();
}
wait1Msec(25);
}
}
ok you said the code I had above was correct, but it is not working, both if statements always return true, regardless of how many controllers are connected. Then the code you posted was different should I use “vrXmit1” in place of ‘0x01’ and “vrXmit2” in place of "0x02’?
Ok thanks for the Update, we were seeing some other weird behavior from the partner controller as well, so I will look into checking it with a different partner controller