Always executing the first CASE statement
I'm trying to use a SWITCH statement in my code, and after running it. It looks like the first CASE statement is always executed regardless of what the value is. My Code:
SWITCH (BUTTON.INPUT.CHANNEL)
{
CASE 1: PULSE [vdvDisplay, 27]
CASE 2: PULSE [vdvDisplay, 28]
CASE 11:
{
nInputSource++
SEND_COMMAND dvDisplay, "'INPUT-',ITOA(nInputSource)"
}
}
I've noticed this happening with multiple switch statements
SWITCH (BUTTON.INPUT.CHANNEL)
{
CASE 1: PULSE [vdvDisplay, 27]
CASE 2: PULSE [vdvDisplay, 28]
CASE 11:
{
nInputSource++
SEND_COMMAND dvDisplay, "'INPUT-',ITOA(nInputSource)"
}
}
I've noticed this happening with multiple switch statements
0
Comments
BUTTON_EVENT [dvTP, 1]
BUTTON_EVENT [dvTP, 2]
BUTTON_EVENT [dvTP, 11]
{
}
stack_var integer iBtn; iBtn = get_last(buttuon.input.channel); send_string 0, "'button is... ', itoa(iBtn)"; switch(iBtn){ case 1... }or if you want some opinion on structuring your code
BUTTON_1 = [a number]; BUTTON_2 = [a number]; BUTTON_3 = [a number]; BUTTON_4 = [a number]; volatile integer nBtns[] = { BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4 }; button_event[dvTPs,nBtns]{ stack_var btn; stack var tp; btn = get_last(nBtns); tp = get_last(dvTPs); switch(nBtns[btn]){ case BUTTON_1: { } case BUTTON_2: { break; } default:{ } }hopefully these help in isolating your problem. I personally prefer not to use the button.input.chanel call as I've had weird things happen with no answer as to why.
Define_Function Handle_DisplayButtonPresses(Integer btn, Dev Device, Integer InputSource) { Switch ( btn ) { Case 1: { PULSE[Device, PWR_ON]; Break; } Case 2: { PULSE[Device, PWR_OFF]; Break; } Case 11: { InputSource++; SEND_COMMAND Device, "'INPUT-', ITOA(InputSource)"; Break; } } } DEFINE_EVENT BUTTON_EVENT [dvTP, 1] BUTTON_EVENT [dvTP, 2] BUTTON_EVENT [dvTP, 11] { PUSH: { Handle_DisplayButtonPresses(Button.Input.Channel, dvDisplay, nInputSource); } }You can absolutely do what you're doing, however I usually use a function for a single, specific task that will be repeated; this way I have a single place to update a command, while many places could potentially call this function/task.
You should figure out whats causing your problem and fix it instead of jumping to an alternative means of bypassing the problem.
Regardless, I don't see anything wrong with the OP's code as posted. There is funny business taking place elsewhere.
Simply, working with the setup as the OP has setup.
You are right, there was probably nothing wrong with what the OP had;
the problem most likely lies elsewhere.
BUTTON_EVENT [dvTP, 1] BUTTON_EVENT [dvTP, 2] BUTTON_EVENT [dvTP, 11] { push: { SWITCH (BUTTON.INPUT.CHANNEL) { CASE 1: PULSE [dvDisplay, 27] CASE 2: PULSE [dvDisplay, 28] CASE 11: { nInputSource++ SEND_COMMAND dvDisplay, "'INPUT-',ITOA(nInputSource)" } } } }Maybe every button on the TP has channel code 1.