I'm currently re-writing a bit of code and i'm in two minds about which way to take it. Advice would be greatly appreciated :)
The application is used to control a USB circuit board. The board has 32 analog outputs. The outputs are switched on and off by sending a 32bit integer to the board. So to turn on outputs 2 and 4 you send it the number 10 (10= 0101) or to turn on 1,2 and 3 you send 7 (1110) etc.
This part is outside my control.
I currently set the outputs usign a simple math equation:
Output1 = (int)(Math.Pow(2, Convert.ToDouble(Output) - 1));
Each analog output controls a single solenoid. The problem, is that every 8th output controls an LED on the board itself so isn't used, and due to space limitations i have had to skip a couple of the outputs in the middle.
The result: turning on solenoid number 17 requires activating output number 20.
I want the user to be able to enter the number of the solenoid, since the output numbers are hard to figure out unless you know how they are wired.
Sorry for the loooong background. But heres the question:
I am writing the following enum:
public enum Output
{
_1 = 0,
_2 = 1,
_3 = 2,
_4 = 3,
_5 = 4,
_6 = 5,
_7 = 6,
_8 = 8,
_9 = 9,
_10 = 10,
_11 = 11,
_12 = 12,
_13 = 16,
_14 = 17,
_15 = 18,
_16 = 19,
_17 = 20,
_18 = 21,
_19 = 22,
_20 = 24,
_21 = 25,
_22 = 26,
_23 = 27,
_24 = 28
}
I was then going to populate a combobox with each enum option.
So when they pick Output._17 i can use (int)Output._17 to get the correct output.
Am i coming at this all wrong? Something feels a little Kludge-like about the enum : /