Hi, my team wants to use the two buttons next to the hat on the controllers FIRST gave us. I used dashboard and got that they are aux1 and aux2 and I found p1_sw_aux1 and p1_sw_aux2. However, I haven’t been able to figure out what data type they are. I tried using them as a conditional hoping they would be non-zero if depressed (if(p1_sw_aux1) {}), but that didn’t work. I tried searching but I only found a single thread and it simply said you could use them (http://www.chiefdelphi.com/forums/showthread.php?t=48293&highlight=p1_sw_aux). Any help would be greatly appreciated.
p1_sw_aux1 is really a macro
#define p1_sw_aux1 rxdata.oi_swA_byte.bitselect.bit2 // Aux input
bitselect is a member of a union and is of defined type ‘bitid’
typedef struct
{
unsigned int bit0:1;
unsigned int bit1:1;
unsigned int bit2:1;
unsigned int bit3:1;
unsigned int bit4:1;
unsigned int bit5:1;
unsigned int bit6:1;
unsigned int bit7:1;
} bitid;
Thus, the ‘type’ of bit2 is a single bit, the value is always 0 or 1.
HTH
Thank you, I figured it would be essentially a Boolean value but wasn’t sure because my code wasn’t working. My next question is then why doesn’t this code work:
if(p2_sw_aux1) {
pwm01 = 187;
} else if(p2_sw_aux2) {
pwm01 = 67;
} else {
pwm01 = 127;
}
pwm01 goes to a motor that is meant to pivot two casters. I know that the victor its wired to works as well as the controller and cables and such. I know that in C++ the if statements should work but I haven’t used C in a while and I forgot the differences in the two standards. Again, any help is greatly appreciated.
that code should work fine. Just to be certain, you do know that that’s referencing the joystick in port 2?
if that’s not it, try moving the else if and the else onto a second line from the ending brackets. DOn’t think that’s it, but it might be a problem…
“pwm01 goes to a motor that is meant to pivot two casters. I know that the victor its wired to works as well as the controller and cables and such. I know that in C++ the if statements should work but I haven’t used C in a while and I forgot the differences in the two standards. Again, any help is greatly appreciated.”
C++ is a superset of C thus everything that works in C will work in C++. Your code looks OK. You know p2_sw_aux1 is on the second joystick, correct? Print the value of p2_sw_aux1 to make sure it is changing.
HTH
This isn’t entirely true. C++ is a modified version of C that incorporates true object oriented programming into it. There are also a few fundamental syntax changes (cout<<""; instead of printf(""), as one example) that may play havoc with direct conversions of code. If you are coming from C++ to C, the differences are easy and trivial enough to learn C.
“This isn’t entirely true.”
This is a common mis-perception. Its entirely true, C++ is a superset of C that expands the syntax to include object-oriented concepts, streaming I/O and other constructs. Though it is not the recommended practice, I can use printf in C++. It makes no difference in this thread I reckon but C preceded C++, not the other way around.
HTH
The code looks fine. Are you sure pwm01 isn’t set to something else later in the code (for example, in the default code)?
Not sure what I did (I rewrote all the code for unrelated reasons) but now it works. Thanks for all the help.