View Single Post
  #3   Spotlight this post!  
Unread 21-02-2014, 10:32
apalrd's Avatar
apalrd apalrd is offline
More Torque!
AKA: Andrew Palardy (Most people call me Palardy)
VRC #3333
Team Role: College Student
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Auburn Hills, MI
Posts: 1,347
apalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond repute
Re: BCD switch programming

BCD is a limited subset of a hex nibble (single hex character). You can do that using bit shifts:

Code:
uint8 temp = getDigitalIn(#);
temp |= (getDigitalIn(#)) << 1;
temp |= (getDigitalIn(#)) << 2;
temp |= (getDigitalIn(#)) << 3;

//Now temp is a number from 0x00 to 0x0F
The lower levels of the WPIlib access the Digital Inputs as a single uint16 from the FPGA. If you wanted to poke and find the function to read those, you could just apply a mask and bitshift to get your number, instead of creating 4 dio objects and reading all of them (much less code, more efficient):

Code:
uint16 auton_num = <get the 16 bit DI register>;
auton_num &= 0x00F0;
auton_num = auton_num >> 4;
In LV, we use the auton number to index a 2d array of auton types (a struct of an array of strings and a command number). The first index is the auton, the second is time (when the command returns True, it advances to the next element in the array on the next iteration). The array is populated on boot by reading text files and parsing them. The array of strings are arguments, which functions read numbers out of on the first call.
__________________
Kettering University - Computer Engineering
Kettering Motorsports
Williams International - Commercial Engines - Controls and Accessories
FRC 33 - The Killer Bees - 2009-2012 Student, 2013-2014 Advisor
VEX IQ 3333 - The Bumble Bees - 2014+ Mentor

"Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function." ~ John Carmack