Switch default always triggers
Jan 26, 2017 at 8:13am UTC
I have inserted
'default' statements in my switch.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
void confirmCompletion()
{
if (radio.available())
{
radio.read(&confirmation, sizeof (confirmation));
if (confirmation[0] == 'X' )
{
if (libraryMasterDebug)
{
Serial.print("Task " );
Serial.print(confirmation[1]);
Serial.print(" completed by slave" );
Serial.println(confirmation[2]);
} // end if
// Set the Finite State Machine flags.
switch (confirmation[2]) // Slave number.
{
case '0' :
switch (confirmation[1]) // Task number.
{
case '1' :
slave0task1done = true ;
slave0working = false ;
break ;
case '2' :
slave0task2done = true ;
slave0working = false ;
break ;
case '3' :
slave0task3done = true ;
slave0working = false ;
break ;
default :
if (libraryMasterDebug)
{
Serial.print
("Invalid task confirmation from slave" );
Serial.println(confirmation[2]);
} // end if
stallTheProgram();
} // end case switch (confirmation[1])
case '1' :
switch (confirmation[1]) // Task number.
{
case '1' :
slave1task1done = true ;
slave0working = false ;
break ;
case '2' :
slave1task2done = true ;
slave0working = false ;
break ;
case '3' :
slave1task3done = true ;
slave0working = false ;
break ;
default :
if (libraryMasterDebug)
{
Serial.print
("Invalid task confirmation from slave" );
Serial.println(confirmation[2]);
} // end if
stallTheProgram();
} // end case switch (confirmation[1])
// =========================================
// cases must be set for all possible slaves << ===========
// =========================================
default :
if (libraryMasterDebug)
Serial.println("Invalid slave number" );
stallTheProgram();
} // end switch (confirmation[2])
} // end if (confirmation[0] == 'X')
} // end if (radio.available())
} // end confirmCompletion()
Now the operation always drops out on the outer default,
"Invalid Slave number." .
What do I have wrong this time?
Jan 26, 2017 at 8:59am UTC
In your nested switches, the various clauses for the OUTER one (that starting on line 18) don't seem to have break statements, so will "drop through" to the bottom.
The inner switch blocks seem OK.
Jan 27, 2017 at 2:20am UTC
You got it!
Thanks.
Topic archived. No new replies allowed.