so i know that "go to" are not the best for object oriented programing but this is going to solve all my issues, if i can ever get it working
so first i need to say that i am programming this inside a micro based complier but the code is still c, i will explain all the stuff that may look bazzar.
and yes I KNOW I KNOW I KNOW i need to factorize my code because right now it is just a ton of copy and past, and i have figured out a way to do that, but i just need a little more time, but i really need to get this to work
so here is my issue, i am creating flash patterns for a project, yes flash patterns like you would see on a cop car or ambulance etc...i am controlling them using i2c and a digitial i/o expander which is not the problem the code works great(besides the fact i need to reduce the copy and past) so i am controlling the lights with a mechanical encoder which is programmed and working great
my issue is that when i cange the encoder to a different position i want it to break out of the for loop and go to a different for loop, so the encoder is on an interrupt that sense when its changed positions.( the hardware for that is fine ) i just need to work on the software
so i figured i would use the "go to' statement so when i change the encoder it could go to the next for loop, but i need it to do that and break from the first for loop to and execute the second on.
so weird stuff that is applicable to my micro(the PSoC ) is
i2c which not to insult anybody entelligence but a brief definition is just a way of having multiple devices on the same bus line doing different things, all i2c needs a group two address which is why i have a variable there, and to send data you need to issue the write command and and the other code to go with that, which is why it is at the bottom of the for loop
so here is the code
the encoder switch statement is long so i am only posting the first two cases, i know it needs a default case but no need to wast anybody time,
the main loop is a void main(void){ }Code:switch(encoder1) { case 0x00: LCD_PrCString(" "); LCD_Position(1,0); LCD_PrCString("Case0"); Police_Primary_LightBar( ); break; case 0x01: LCD_PrCString(" "); LCD_Position(1,0); LCD_PrCString("Case1"); Police_LightBar_Secondary( ); break; void Police_Primary_LightBar(void) { int j; police_primary: G_Flag_Change_From_Read =0; for(j=0; j<4000; j++) { if(G_Change_From_Read) goto police_secondary; if(j<1000) { if(G_Flag1) { Side_Lights_LightBar( ); Test_Function4( ); I2Caddr=0x20; charcount=2; command[0]=0x00; command[1]=0xE0; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); Side_Lights_LightBar( ); Test_Function1( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0xc0; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } else { Side_Lights_LightBar( ); Test_Function4(); I2Caddr=0x20; charcount=2; command[0]=0x00; command[1]=0x07; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); Side_Lights_LightBar( ); Test_Function1( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0x03; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } } else if((j>1000) && (j<2000)) { if(G_Flag1) { Side_Lights_LightBar( ); I2Caddr=0x20; charcount=2; command[0]=0x00; command[1]=0x3C; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0x81; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } else { Side_Lights_LightBar( ); I2Caddr=0x20; charcount=2; command[0]=0x00; command[1]=0xC3; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0x3c; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } } else if((j>2000) && (j<3000)) { if(G_Flag1) { Side_Lights_LightBar( ); I2Caddr=0x20; charcount=2; command[0]=0x00; command[1]=0x55; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0x16; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } else { Side_Lights_LightBar( ); I2Caddr=0x20; charcount=2; command[0]=0x00; command[1]=0xAA; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); Side_Lights_LightBar( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0x61; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } } else { if(G_Flag1) { Side_Lights_LightBar( ); I2Caddr=0x20; charcount=2; command[0]=0x00; command[1]=0xFF; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0x00; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } else { Side_Lights_LightBar( ); I2Caddr=0x20; charcount=2; command[0]=0x00; command[1]=0x00; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0xFF; I2C_bWriteBytes(I2Caddr, command, charcount, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } } } } // end of police light bar primary void Police_LightBar_Secondary(void) { int i; police_secondary; G_Flag_Change_From_Read=0; for(i=0; i<4000; i++) { if(G_Flag_Change_From_Read) goto police_primary; if(i< 2000){ if(G_Flag1) { Side_Lights_LightBar( ); Test_Function( ); I2Caddr=0x20; charcount=2; command[0]=0x00; command[1]=0xE0; I2C_bWriteBytes(I2Caddr, command, 2, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0xC0; I2C_bWriteBytes(I2Caddr, command, 2, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } else { Side_Lights_LightBar( ); Test_Function( ); I2Caddr=0x20; charcount=2; command[0]=0x00; command[1]=0x07; I2C_bWriteBytes(I2Caddr, command, 2, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0x03; I2C_bWriteBytes(I2Caddr, command, 2, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } if(G_Flag2) { Side_Lights_LightBar( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0x28; I2C_bWriteBytes(I2Caddr, command, 2, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } else { Side_Lights_LightBar( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0x14; I2C_bWriteBytes(I2Caddr, command, 2, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } } else { if(G_Flag4) { Side_Lights_LightBar( ); Test_Function( ); I2Caddr=0x20; charcount=2; command[0]=0x00; command[1]=0xE0; I2C_bWriteBytes(I2Caddr, command, 2, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0xC0; I2C_bWriteBytes(I2Caddr, command, 2, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } else { Side_Lights_LightBar( ); Test_Function( ); I2Caddr=0x20; charcount=2; command[0]=0x00; command[1]=0x07; I2C_bWriteBytes(I2Caddr, command, 2, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0x03; I2C_bWriteBytes(I2Caddr, command, 2, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } if(G_Flag1) { Side_Lights_LightBar( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0x28; I2C_bWriteBytes(I2Caddr, command, 2, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } else { Side_Lights_LightBar( ); I2Caddr=0x20; charcount=2; command[0]=0x01; command[1]=0x14; I2C_bWriteBytes(I2Caddr, command, 2, I2C_CompleteXfer); while(!(I2C_bReadI2CStatus( ) & I2CHW_WR_COMPLETE)); I2C_ClrWrStatus( ); } } } }// end of police lightbar_Secondary void PSoC_GPIO_ISR_C(void) { G_Flag_Change_From_Read=1; } void Counter16_1_ISR(void) { G_Flag2 = !G_Flag2; num2=rand( ); } void Counter16_2_ISR(void) { G_Flag3= !G_Flag3; num3=rand( ); grille_function1_Data_ADDR ^= grille_function1_MASK; } void Counter16_3_ISR(void) { G_Flag4= !G_Flag4; //G_Flag4=0; num4=rand( ); }
and just has the switch statement in it
once again when the encoder switches i need it to break from the first for loop and go to the second for loop, in theory this should work but i am not sure if it will
please help
thank you