// wp2m_user_if.c
//
//
//
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <conio.h>

// Mission Parameter Default Settings from wp2m.c

extern double maxLegMeters;    // meters between AUV surfacings
extern int yoyoMinAltitude;            // meters
extern int missionYoyoMinDepth;
extern int missionYoyoMaxDepth;
extern int missionYoyoMaxDepthShallow;
extern double missionSpeed;
extern double missionSpeedSlow;
extern int gpsHits;
extern double spd;
extern double wayPointDepth;
extern int choice;
extern char reply;
extern double minDepth;
extern double maxDepth;
extern double abortDepth;
extern double abortAltitude;
extern double abortLockoutDepth;
extern int abortOnTimeout; // 1 TRUE, 0 FALSE
extern double diveAngle;

// yoyoMinAlt function
// allows user to modify int variable yoyoMinAltitude
//
int yoyoMinAlt()
  {
      printf("YoYo Minimum Altitude is %d meters\n", yoyoMinAltitude );
      printf( "Please enter new altitude in meters \n\n > ");
      scanf( "%d", &choice );
         (void)getchar();  // clean input of newline
      return (choice);
  }

// yoyoMinDepth function
// allows user to modify int variable missionYoyoMinDepth
//
int yoyoMinDepth()
  {
      printf("mission YoYo Min Depth is %d meters\n", missionYoyoMinDepth );
      printf( "Please enter new depth in meters \n\n > ");
      scanf( "%d", &choice );
         (void)getchar();  // clean input of newline
      return (choice);
  }

// yoyoMaxDepth function
// allows user to modify int variable missionYoyoMinDepth
//
int yoyoMaxDepth()
  {
      printf("mission YoYo Max Depth is %d meters\n", missionYoyoMaxDepth );
      printf( "Please enter new depth in meters \n\n > ");
      scanf( "%d", &choice );
         (void)getchar();  // clean input of newline
      return (choice);
  }

// yoyoMaxDepthShallow function
// allows user to modify int variable missionYoyoMinDepth
//
int yoyoMaxDepthShallow()
  {
      printf("mission YoYo Max Depth Shallow is %d meters\n", missionYoyoMaxDepthShallow );
      printf( "Please enter new depth in meters \n\n > ");
      scanf( "%d", &choice );
         (void)getchar();  // clean input of newline
      return (choice);
  }

// get_diveAngle function
// allows user to modify default dive angle ( 30 )
//  Added 2 Aug 14
//
double get_diveAngle()
  {
      printf("mission dive angle is %.0f degrees\n", diveAngle);
      printf("Please enter new dive angle in degrees \n\n >");
      scanf("%lf", &diveAngle);
         (void)getchar();  // clean input of newline
      return diveAngle;
  }


// gpsNum function
// allows user to modify number of gps hits
//
int gpsNum()
  {
      printf("Number of GPS hits per surfacing is %d \n", gpsHits );
      printf( "Please enter new number of hits \n\n > ");
      scanf( "%d", &choice );
         (void)getchar();  // clean input of newline
      return (choice);
  }

double get_maxLegMeters()
  {
      printf("Meters between AUV surfacings is %.1f \n", maxLegMeters );
      printf( "Please enter new distance in meters \n\n > ");
      scanf( "%lf", &maxLegMeters );
         (void)getchar();  // clean input of newline
      return maxLegMeters;
  }

double get_wayPointDepth()
  {
    printf("Default Waypoint Depth is %.1f \n", wayPointDepth );
    printf( "Please enter new depth \n\n > ");
    scanf( "%lf", &wayPointDepth );
      (void)getchar();  // clean input of newline

    //printf("\n\n wayPointDepth entered = %.1f\n\n", wayPointDepth);
    //getch();

    return wayPointDepth;
  }

int queryYoYoParameters()
  {
    // present default mission parameters
    // inquire if any need to be changed
    // if change needed, type the number of the parameter
    // else type 0
    do {
         printf ( "\n\n YOYO Mission Parameters \n\n" );

         printf ( "1  YOYO_MIN_ALTITUDE %d\n", yoyoMinAltitude );
         printf ( "2  MISSION_YOYO_MIN_DEPTH %d\n",  missionYoyoMinDepth );
         printf ( "3  MISSION_YOYO_MAX_DEPTH %d\n", missionYoyoMaxDepth );
         printf ( "4  MISSION_YOYO_MAX_DEPTH_SHALLOW %d\n", missionYoyoMaxDepthShallow );
         printf ( "5  MISSION_DIVE_ANGLE %.1f\n", diveAngle);
         printf ( "0  All parameters are OK\n" );
         printf ( "  Choose number of parameter to modify.\n" );
         printf ( "  If parameters are OK, type 0 \n\n > " );
         scanf( "%d", &choice );
           (void)getchar();  // clean input of newline
         switch (choice)
           {
             case 1:
               yoyoMinAltitude = yoyoMinAlt();
               break;
             case 2:
               missionYoyoMinDepth = yoyoMinDepth();
               break;
             case 3:
               missionYoyoMaxDepth = yoyoMaxDepth();
               break;
             case 4:
               missionYoyoMaxDepthShallow = yoyoMaxDepthShallow();
               break;
             case 5:
               diveAngle = get_diveAngle();
               break;
             case 0:
               printf( "0\n");
               break;
             default:
               printf( "Error ... please try again\n");
           }
       } while( choice != 0 );

    return(choice);
  }

// Speed function
// allows user to modify double variable missionSpeed
//
double Speed()
  {
      printf("mission Speed is %.3f meters per second\n", missionSpeed );
      printf( "Please enter new speed in meters per second \n\n >");
      scanf( "%lf", &spd );
         (void)getchar();  // clean input of newline
      return (spd);
  }

// SpeedSlow function
// allows user to modify double variable missionSpeedSlow
//
double SpeedSlow()
  {
      printf("mission Speed Slow is %.3f meters per second\n", missionSpeedSlow );
      printf( "Please enter new speed in meters per second \n\n >");
      scanf( "%lf", &spd );
         (void)getchar();  // clean input of newline
      return (spd);
  }

// minDepth function
// allows user to modify double var minDepth
double get_minDepth()
  {
      printf("minDepth is %.1f meters\n", minDepth );
      printf( "Please enter new minDepth in meters \n\n >");
      scanf( "%lf", &minDepth );
         (void)getchar();  // clean input of newline
      return (minDepth);
  }

// maxDepth function
// allows user to modify double var maxDepth
double get_maxDepth()
  {
      printf("maxDepth is %.1f meters\n", maxDepth );
      printf( "Please enter new maxDepth in meters \n\n >");
      scanf( "%lf", &maxDepth );
         (void)getchar();  // clean input of newline
      return (maxDepth);
  }

// abortDepth function
// allows user to modify double var abortDepth
double get_abortDepth()
  {
      printf("abortDepth is %.1f meters\n", abortDepth );
      printf( "Please enter new abortDepth in meters \n\n >");
      scanf( "%lf", &abortDepth );
         (void)getchar();  // clean input of newline
      return (abortDepth);
  }

// abortAltitude function
// allows user to modify double var abortAltitude
double get_abortAltitude()
  {
      printf("abortAltitude is %.1f meters\n", abortAltitude );
      printf( "Please enter new abortAltitude in meters \n\n >");
      scanf( "%lf", &abortAltitude );
         (void)getchar();  // clean input of newline
      return (abortAltitude);
  }

// abortLockoutDepth function
// allows user to modify double var abortLockoutDepth
double get_abortLockoutDepth()
  {
      printf("abortLockoutDepth is %.1f meters\n", abortLockoutDepth );
      printf( "Please enter new abortLockoutDepth in meters \n\n >");
      scanf( "%lf", &abortLockoutDepth );
         (void)getchar();  // clean input of newline
      return (abortLockoutDepth);
  }


// abortOnTimeout function
// allows user to modify double var abortLockoutDepth
double get_abortOnTimeout()
  {
      printf("abortOnTimeout is %d \n", abortOnTimeout );

      printf( "Please enter new abortOnTimeout \n");
      printf("1 for TRUE, or 0 for FALSE \n\n >");
      scanf( "%d", &abortOnTimeout );
         (void)getchar();  // clean input of newline
      return (abortOnTimeout);
  }

int queryMissionParameters()
  {
    // present default mission parameters
    // inquire if any need to be changed
    // if change needed, type the number of the parameter
    // else type 0
    do {
         printf ( "\n\n Mission Parameters \n\n" );

         printf ( " 1  MISSION_SPEED %.3f\n", missionSpeed );
         printf ( " 2  MISSION_SPEED_SLOW %.3f\n", missionSpeedSlow );
         printf ( " 3  GPS_HITS %d\n", gpsHits );
         printf ( " 4  Meters between surfacings %.1f\n", maxLegMeters);
         printf ( " 5  minDepth %.1f\n", minDepth);
         printf ( " 6  maxDepth %.1f\n", maxDepth);
         printf ( " 7  abortDepth %.1f\n", abortDepth);
         printf ( " 8  abortAltitude %.1f\n", abortAltitude);
         printf ( " 9  abortLockoutDepth %.1f\n", abortLockoutDepth);
         printf ( "10  abortOnTimeout %d\n\n", abortOnTimeout);
         printf ( " 0   All parameters are OK\n" );
         printf ( "  Choose number of parameter to modify.\n" );
         printf ( "  If parameters are OK, type 0 \n\n > " );
         scanf( "%d", &choice );
         (void)getchar();  // clean input of newline
         switch (choice)
           {
             case 1:
               missionSpeed = Speed();
               break;
             case 2:
               missionSpeedSlow = SpeedSlow();
               break;
             case 3:
               gpsHits = gpsNum();
               break;
             case 4:
               maxLegMeters = get_maxLegMeters();
               break;
             case 5:
               minDepth = get_minDepth();
               break;
             case 6:
               maxDepth = get_maxDepth();
               break;
             case 7:
               abortDepth = get_abortDepth();
               break;
             case 8:
               abortAltitude = get_abortAltitude();
               break;
             case 9:
               abortLockoutDepth = get_abortLockoutDepth();
               break;
             case 10:
               abortOnTimeout = get_abortOnTimeout();
               break;
             case 0:
               printf( "0\n");
               break;
             default:
               printf( "Error ... please try again\n");
           }
       } while( choice != 0 );
    return(choice);
  }

// inquire if this is a YOYO mission
// if yes, set yoyo = 1
//
int queryYoyo()
  {
    int yoyoMission;
    do {
        printf ( " Will this be a YOYO Mission ? \n" );
        printf ( " Please enter Y or N > ");
        scanf( "%c", &reply );
        (void)getchar();  // clean input of newline
        // printf( " choice = %c \n ", reply );
        // getch();
         switch (reply)
           {
             case 'n':
             case 'N':
                yoyoMission = 0;
                break;
             case 'y':
             case 'Y':
                yoyoMission = 1;
                break;
             default:
                printf(" Please enter y or n ");
           }
       } while ( (reply  != 'n') && ( reply != 'N') && ( reply != 'y') && ( reply != 'Y') ) ;

    return(yoyoMission);
  }

// inquire if this is a GULPER mission
// if yes, arm the gulpers at the start of the mission
// inform user to move the arming behavior if necessary
//
int queryGulper()
  {
   int gulperMission;

    do {
        printf ( " Will this be a GULPER Mission ? \n" );
        printf ( " Please enter Y or N > ");
        scanf( "%c", &reply );
        (void)getchar();  // clean input of newline
        // printf( " choice = %c \n ", reply );
        // getch();
         switch (reply)
           {
             case 'n':
             case 'N':
                gulperMission = 0;
                break;
             case 'y':
             case 'Y':
                gulperMission = 1;
                break;
             default:
                printf(" Please enter y or n ");
           }
       } while ( (reply  != 'n') && ( reply != 'N') && ( reply != 'y') && ( reply != 'Y') ) ;

     if ( gulperMission == 1 )
       {
       printf ( " \n\n The Gulpers will be armed at mission start \n" );
       printf ( " Remember to move the behavior if necessary \n" );
       printf ( " Hit any key to continue \n");
       getch();
       printf ( "\n\n" );
       }
      return(gulperMission);
   }
