Exemplo n.º 1
0
/****************************************************************************
 Function
   Check4Lock
 Parameters
   None
 Returns
   bool: true if a new event was detected
 Description
   Sample event checker grabbed from the simple lock state machine example
 Notes
   will not compile, sample only
 Author
   J. Edward Carryer, 08/06/13, 13:48
****************************************************************************/
bool Check4Lock(void)
{
  static uint8_t LastPinState = 0;
  uint8_t CurrentPinState;
  bool ReturnVal = false;
  
  CurrentPinState =  LOCK_PIN;
  // check for pin high AND different from last time
  // do the check for difference first so that you don't bother with a test
  // of a port/variable that is not going to matter, since it hasn't changed
  if ( (CurrentPinState != LastPinState) &&
       (CurrentPinState == LOCK_PIN_HI) )
  {                     // event detected, so post detected event
    ES_Event ThisEvent;
    ThisEvent.EventType = ES_LOCK;
    ThisEvent.EventParam = 1;
    // this could be any of the service post function, ES_PostListx or 
    // ES_PostAll functions
    ES_PostList01(ThisEvent); 
    ReturnVal = true;
  }
  LastPinState = CurrentPinState; // update the state for next time

  return ReturnVal;
}
Exemplo n.º 2
0
boolean Check4PositionFound(void)
{
    boolean ReturnVal = False;


    float CurrentXPosition = accessXPosition();
    float CurrentYPosition = accessYPosition();
    float CurrentBotOrientation = accessAngle();

    // check for pin high and different from last time

    if ( (CurrentXPosition != LastXPosition) ||
            (CurrentYPosition != LastYPosition) ||
            (CurrentBotOrientation != LastBotOrientation) )
    {
        ES_Event ThisEvent;
        ThisEvent.EventType = POSITION_FOUND;
        ES_PostList01(ThisEvent);
        ReturnVal = True;
        //ReturnVal = False;
    }


    LastXPosition = CurrentXPosition;
    LastYPosition = CurrentYPosition;
    LastBotOrientation = CurrentBotOrientation;

    return ReturnVal;
}
Exemplo n.º 3
0
boolean BinChecker(void)
{
    unsigned int CurrentBin1Status;
    unsigned int CurrentBin2Status;
    unsigned int CurrentBin3Status;
    unsigned int CurrentBin4Status;

    boolean ReturnVal = False;

    CurrentBin1Status =  queryFSR( BIN1 );
    CurrentBin2Status =  queryFSR( BIN2 );
    CurrentBin3Status =  queryFSR( BIN3 );
    CurrentBin4Status =  queryFSR( BIN4 );

    if ( (CurrentBin1Status != LastBin1Status)|
            (CurrentBin2Status != LastBin2Status)|
            (CurrentBin3Status != LastBin3Status)|
            (CurrentBin4Status != LastBin4Status) )
    {
        ES_Event ThisEvent;
        ThisEvent.EventType = BIN_CHANGED;
        if (CurrentBin1Status != LastBin1Status)
        {
            ThisEvent.EventParam = 1;
        } else if(CurrentBin2Status != LastBin2Status)
        {
            ThisEvent.EventParam = 2;
        } else if(CurrentBin3Status != LastBin3Status)
        {
            ThisEvent.EventParam = 3;
        } else
        {
            ThisEvent.EventParam = 4;
        }
        ES_PostList01(ThisEvent);
        ReturnVal = True;
    }
    LastBin1Status = CurrentBin1Status;
    LastBin2Status = CurrentBin2Status;
    LastBin3Status = CurrentBin3Status;
    LastBin4Status = CurrentBin4Status;

    return ReturnVal;
}
Exemplo n.º 4
0
boolean WallAngleChecker(void)
{
    unsigned int CurrentWallAngleStatus;
    boolean ReturnVal = False;

    CurrentWallAngleStatus =  queryFSR( WALL_ANGLE );

    if ( (CurrentWallAngleStatus != LastWallAngleStatus) )
    {
        ES_Event ThisEvent;
        ThisEvent.EventType = WALL_MOVED;
        ThisEvent.EventParam = (CurrentWallAngleStatus - LastWallAngleStatus);
        ES_PostList01(ThisEvent);
        ReturnVal = True;
    }
    LastWallAngleStatus = CurrentWallAngleStatus;

    return ReturnVal;
}
Exemplo n.º 5
0
boolean KeyStrokeEvents(void)
{
    ES_Event ThisEvent;

    int KeyStroke;

    ThisEvent.EventType = ES_NO_EVENT;

    if ( kbhit() != 0)       // there was a key pressed
    {

        KeyStroke = getchar();
        switch ( toupper(KeyStroke))
        {
        case 'A' :
            ThisEvent.EventType = HONE_BIN1;
            IsIR_StepperEvent= True;
            break;
        case 'B' :
            ThisEvent.EventType = HONE_BIN2;
            IsIR_StepperEvent= True;
            break;
        case 'C' :
            ThisEvent.EventType = HONE_BIN3;
            IsIR_StepperEvent= True;
            break;
        case 'D' :
            ThisEvent.EventType = HONE_BIN4;
            IsIR_StepperEvent= True;
            break;
        case 'E' :
            ThisEvent.EventType = STOP_STEPPING;
            IsIR_StepperEvent= True;
            break;
        case 'F' :
            ThisEvent.EventType = DEPOSIT_TIME;
            IsThinkTankEvent = True;
            break;
        case 'G' :
            ThisEvent.EventType = FAVORITE_BIN_THREATENED;
            IsThinkTankEvent = True;
            break;
        case 'H' :
            ThisEvent.EventType = BIN_CHOSEN;
            ThisEvent.EventParam = 1;
            IsThinkTankEvent = True;
            break;
        case 'I' :
            ThisEvent.EventType = DEPOSIT_COMMAND;
            /*IsTankEvent = True;*/ break;
        case 'J' :
            ThisEvent.EventType = WALL_CHOSEN;
            ThisEvent.EventParam = LEFT;
            IsThinkTankEvent = True;
            break;
        case 'K' :
            ThisEvent.EventType = EPIC_PUSH_FAIL;
            IsThinkTankEvent = True;
            break;
        case 'L' :
            ThisEvent.EventType = GOAL_ANGLE_ACHIEVED;
            IsThinkTankEvent = True;
            break;
        case 'M' :
            ThisEvent.EventType = WALL_THREATENS_HOPPER;
            IsTankEvent = True;
            break;
        case 'N' :
            ThisEvent.EventType = WALL_NO_LONGER_THREATENS_HOPPER;
            IsTankEvent = True;
            break;
        case 'O' :
            ThisEvent.EventType = RIGHT_ZEROED;
            IsTankEvent = True;
            break;
        case 'P' :
            ThisEvent.EventType = LEFT_ZEROED;
            IsTankEvent = True;
            break;
        case 'Q' :
            ThisEvent.EventType = START_CALIBRATING_HOPPER;
            IsTankEvent = True;
            break;
        case 'R' :
            ThisEvent.EventType = ARRIVED;
            IsThinkTankEvent = True;
            break;
        case 'S' :
            ThisEvent.EventType = ROTATION_COMPLETE;
            IsThinkTankEvent = True;
            break;
        case 'T' :
            ThisEvent.EventType = GO_TO_LOW_COMMAND;
            break;
        case 'U' :
            ThisEvent.EventType = BALLS_IN_PLAY;
            break;
        case 'X' :
            ThisEvent.EventType = POSITION_FOUND;
            /*IsThinkTankEvent = True;*/ break;
        case 'Y' :
            ThisEvent.EventType = FIND_POSITION;
            IsIR_StepperEvent= True;
            break;
        case 'Z' :
            ThisEvent.EventType = ZERO_FOUND;
            break;
        }

        if (IsTankEvent)
        {
            ES_PostList00(ThisEvent);
            IsTankEvent = False;
        } else if (IsIR_StepperEvent)
        {
            ES_PostList06(ThisEvent);
            IsIR_StepperEvent = False;
        }
        else if (IsThinkTankEvent)
        {
            ES_PostList01(ThisEvent);
            IsThinkTankEvent = False;
        }
        else
        {
            ES_PostList02(ThisEvent);
            ES_PostList06(ThisEvent);
        }
        printf("posted\n\r");
        return(True);
    }

    return(False);
}