/*@!Encoding:1252*/
variables
{
  const int kACTIVE   = 1;
  const int kDEACTIVE = 0;

  int gDriveToStorePos = 1;

  //declare global variables
  int gCurrentPosition, gDriverID;

  //data for different stored saetpositions
  int gStoredPosition[4] = {12, 11 , 9, 12};
}

on linFrame Seatsetting
{
  if(gDriveToStorePos == kACTIVE) return;

  //shift the seat position
  @LIN::Seat_up_Dsp = this.Seat_up;
  @LIN::Seat_down_Dsp = this.Seat_down;

  if (gCurrentPosition < 15 && this.Seat_up)
  {
    gCurrentPosition = gCurrentPosition + 1;
    @LIN::Seatvertical_Dsp = gCurrentPosition;
  }
  if (gCurrentPosition > 8 && this.Seat_down)
  {
    gCurrentPosition = gCurrentPosition - 1;
    @LIN::Seatvertical_Dsp = gCurrentPosition;
  }
}

SetSeatposition(int actDriver)
{
  if(gDriverID != actDriver)  
  {
    gDriveToStorePos = kACTIVE;
    gDriverID = actDriver;
  }
  if(gDriveToStorePos == kACTIVE)
  { 
    //get the stored seat position
    if(gCurrentPosition < gStoredPosition[gDriverID])
    {
      gCurrentPosition = gCurrentPosition + 1;
      @LIN::Seatvertical_Dsp = gCurrentPosition;
    }
    if(gCurrentPosition > gStoredPosition[gDriverID])
    { 
      gCurrentPosition = gCurrentPosition - 1;
      @LIN::Seatvertical_Dsp = gCurrentPosition;
    }
    if(gCurrentPosition == gStoredPosition[gDriverID]) gDriveToStorePos = kDEACTIVE;
  }
}

on linFrame Seatposition
{
  //call function to get the stored seat position
  SetSeatposition(this.Driver);
}

on linFrame StoreSeatposition
{
  //store the current seat position
  if(this.Storeposition)
  gStoredPosition[gDriverID] = gCurrentPosition;
}

on start
{
  gCurrentPosition = 8;
}

