/*******************************************************************************
* FILE NAME: user_routines.h
*
* DESCRIPTION: 
*  This is the include file which corresponds to user_routines.c and
*  user_routines_fast.c
*  It contains some aliases and function prototypes used in those files.
*
* USAGE:
*  If you add your own routines to those files, this is a good place to add
*  your custom macros (aliases), type definitions, and function prototypes.
*******************************************************************************/

#ifndef __user_program_h_
#define __user_program_h_


/*******************************************************************************
                            MACRO DECLARATIONS
*******************************************************************************/
/* Add your macros (aliases and constants) here.                              */
/* Do not edit the ones in ifi_aliases.h                                      */
/* Macros are substituted in at compile time and make your code more readable */
/* as well as making it easy to change a constant value in one place, rather  */
/* than at every place it is used in your code.                               */
/*
 EXAMPLE CONSTANTS:
#define MAXIMUM_LOOPS   5
#define THE_ANSWER      42
#define TRUE            1
#define FALSE           0
#define PI_VAL          3.1415

 EXAMPLE ALIASES:
#define LIMIT_SWITCH_1  rc_dig_int1  (Points to another macro in ifi_aliases.h)
#define MAIN_SOLENOID   solenoid1    (Points to another macro in ifi_aliases.h)
*/

/* Used in limit switch routines in user_routines.c */
#define OPEN        1     /* Limit switch is open (input is floating high). */
#define CLOSED      0     /* Limit switch is closed (input connected to ground). */
#define PRESSED		1	  /* Button is pressed	*/
#define NOT_PRESSED	0	  /* Button has not been pressed */


#if defined(QUADRATUREINT)
  #define QUADRATUREINTRIGHT  BIT2CHAR(rc_dig_in04, rc_dig_in12)
  #define QUADRATUREINTLEFT BIT2CHAR(rc_dig_in03, rc_dig_in11)
  /* Interrupt 3 and 4 are used by the encoders.  They are
   * connected to the digital_03 and digital_04 inputs.
   */
  #define QUADRATUREINTINIT \
    TRISBbits.TRISB4 = 1;	/* Interrupt 3 is an input */ \
    INTCON2bits.RBIP = 0;	/* Low priority on int 3-6 */ \
    INTCON2bits.INTEDG2 = 1;	/* Trigger on rising edge? */ \
    INTCONbits.RBIF = 0;	/* Clear any pending on 3-6 */ \
    TRISBbits.TRISB5 = 1;	/* Interrupt 4 is an input */ \
    INTCON2bits.INTEDG3 = 1;	/* Trigger on falling edge? */ \
    INTCONbits.RBIE = 1;	/* Enable interrupt 3-6 */

#endif
#if defined(KITBOT)
  //#define DIST_PER_PULSE (24900L/128)
  #define DIST_PER_PULSE_LEFT (24900L/128)
  #define DIST_PER_PULSE_RIGHT (-24900L/128)
  //#define DEGREE_PER_PULSE (8700L/128)
  #define DEGREE_PER_PULSE_LEFT (8700L/128)
  #define DEGREE_PER_PULSE_RIGHT (-8700L/128)
  #define INITIAL_DISTANCE 450
#else
  #define DIST_PER_PULSE_LEFT (20000L/64)
  #define DIST_PER_PULSE_RIGHT (-20000L/128)
  #define DEGREE_PER_PULSE_LEFT (2000L/64)
  #define DEGREE_PER_PULSE_RIGHT (-2000L/128)
  #define INITIAL_DISTANCE 333
#endif

/*******************************************************************************
                           FUNCTION PROTOTYPES
*******************************************************************************/

/* These routines reside in user_routines.c */
void User_Initialization(void);
void Process_Data_From_Master_uP(void);
void Default_Routine(void);
char debounce_button(char *last_button, char button);
char command_turn_left(int degrees);
char command_turn_right(int degrees);
char command_drive(int distance);

/* These routines reside in user_routines_fast.c */
void InterruptHandlerLow (void);  /* DO NOT CHANGE! */
void User_Autonomous_Code(void);  /* Only in full-size FRC system. */
void Process_Data_From_Local_IO(void);
void InterruptVectorLow (void);



#endif
/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

