ELCTRKEYPADCALLBACK loop_cb_kp_follow = NULL; ELCTRKEYPADCALLBACK loop_cb_kp_high_follow = NULL; ELCTRKEYPADCALLBACK loop_cb_noevent = NULL; void ctrSetCB_kp_follow( ELCTRKEYPADCALLBACK cb ){ if(cb != NULL){ loop_cb_kp_follow = cb; } } void ctrSetCB_kp_high_follow( ELCTRKEYPADCALLBACK cb ){ if(cb != NULL){ loop_cb_kp_high_follow = cb; } } void ctrSetCB_noevent( ELCTRKEYPADCALLBACK cb ){ if(cb != NULL){ loop_cb_noevent = cb; } } void ctrWaitTillLoopFree(void) { while( ( elctr.loopbusy ) || ( elctr.event != EVT_NOTHING ) ){ ; } } void ctrDoLoopEvent( unsigned char event ) { ctrWaitTillLoopFree(); elctr.event = event; } void ctrLoop ( char * data ) { unsigned char event; if( elctr.run ) { return; } if( ctrif_StartConnection() == 0){ ctrif_StopConnection(); return; } elctr.run = 1; while( elctr.run ) { event = EVT_NOTHING; elctr.loopbusy = 0; if( elctr.keypad ) { event = read_keypad( elctr.keypad ); } if( event == EVT_NOTHING ) { event = elctr.event; } if( event == EVT_NOTHING ){ if(loop_cb_noevent != NULL){ (*loop_cb_noevent)(); } continue; } elctr.loopbusy = 1; elctr.event = EVT_NOTHING; if(event < IFEVT_ENDVALUES ) { switch( event ) { case IFEVT_ENDALL: elctr.run = 0; break; case IFEVT_STOPMOTORS: if( ctrif_StopMotors() == 0 ) { elctr.run = 0; } break; case IFEVT_STARTGUIDE: /*free, - key follow*/ if(loop_cb_kp_follow != NULL){ (*loop_cb_kp_follow)(); } break; case IFEVT_GOTORADECKOORS: /*keys high, and follow, this is normally used for ending all from ext. prog ( calling ctrendall )*/ if(loop_cb_kp_high_follow != NULL){ (*loop_cb_kp_high_follow)(); } break; case IFEVT_SLOWLEFT: if( ctrif_GoLeft_Slow() == 0 ) { elctr.run = 0; break; } break; case IFEVT_SLOWRIGHT: if( ctrif_GoRight_Slow( ) == 0 ) { elctr.run = 0; break; } break; case IFEVT_SLOWDOWN: if( ctrif_GoDown_Slow() == 0 ) { elctr.run = 0; break; } break; case IFEVT_SLOWUP: if( ctrif_GoUp_Slow() == 0 ) { elctr.run = 0; break; } break; case IFEVT_FASTLEFT: if( ctrif_GoLeft_Fast() == 0 ) { elctr.run = 0; break; } break; case IFEVT_FASTRIGHT: if( ctrif_GoRight_Fast() == 0 ) { elctr.run = 0; break; } break; case IFEVT_FASTDOWN: if( ctrif_GoDown_Fast() == 0 ) { elctr.run = 0; break; } break; case IFEVT_FASTUP: if( ctrif_GoUp_Fast() == 0 ) { elctr.run = 0; break; } break; default: break; } continue; } if(event >= PREVT_STARTVALUES ) { switch( event ) { case PREVT_INITFIELDROTATOR: elctr.fruse = 1; break; case PREVT_STOPFIELDROTATOR: elctr.fruse = 0; break; case PREVT_FRTURNLEFT: if(elctr.fruse){ if( ctrif_FrTurnLeft() == 0 ) { elctr.run = 0; } } break; case PREVT_FRTURNRIGHT: if(elctr.fruse){ if( ctrif_FrTurnRight() == 0 ) { elctr.run = 0; } } break; default: break; } } } ctrif_StopConnection(); }