/****************************************************************************
 
  Header file of Standard Project Constants

 ****************************************************************************/

#ifndef Constants_H
#define Constants_H

//Ticks
//#define TicksPerUS 							  40
static const uint32_t TicksPerUS = 40;
//#define TicksPerMS 							  40000
static const uint32_t TicksPerMS = 40000;
#define TicksPerUS_f							40.f

#define MS_PER_S									1000
static const uint32_t TicksPerS = 40000000;

#define TURN_180_TIME							1200 //ms
#define START_NUM_COWS						5
	
	//Areas
#define SUPPLY_DEPOT							0x04
#define AREA_1										0x03
#define AREA_2										0x02
#define AREA_3										0x01
#define START											0x00

//ReportStatusAreas
#define R1												0x0001
#define R2												0x0010
#define R3												0x0011
#define G1												0x0100
#define G2												0x0101
#define G3												0x0110

//Bits
#define BITS_IN_NIBBLE 					  4
#define ALL_BITS 								  (0xff<<2)
#define MAX_16_BIT 							  0xFFFF

//Team
#define RED 										  0
#define GREEN 									  1

//GPIO
#define INPUT										  0
#define OUTPUT									  1
#define HI											  1
#define LO											  0

//PWM
#define FREQUENCY_PWM0_GEN_0 		  7000
#define FREQUENCY_PWM0_GEN_1 		  7000
#define PWM0_GENERATOR_0 					0
#define PWM0_GENERATOR_1 					1
#define PWM0_GENERATOR_3 					2
#define PWM1_GENERATOR_0 					3
#define PWM1_GENERATOR_1 					4
#define CHANNEL_A 							  0
#define CHANNEL_B 							  1
#define PWM_NORMAL_POL 					  0
#define PWM_INV_POL 						  1

#define OFF 										  0 //PWM %
#define HALF_SPEED 							  70 //PWM %
#define FULL_SPEED 							  100 //PWM %
#define TURN_SPEED							  60 //PWM %
#define TURN_SPEED_BEACON				  30 //PWM %
#define FLYWHEEL_DUTY							70

//Motor Speeds
#define AREA_11_SPEED							 50.f
#define AREA_21_SPEED              70.f
#define AREA_31_SPEED              50.f
#define AREA_12_SPEED							 70.f
#define AREA_22_SPEED							 70.f
#define AREA_32_SPEED              70.f
#define AREA_13_SPEED              70.f
#define AREA_23_SPEED              70.f
#define AREA_33_SPEED              70.f

// Servo
#define SERVO_MAX_PULSE						2000 // uS
#define SERVO_MIN_PULSE						1000 // uS
#define SERVO_PWM_FREQ						50	 // Hz
#define SERVO_CENTER_POS					0

//Game Time
#define GAME_TIME									138

//Interrupts
#define PRIORITY_0 								0
#define PRIORITY_1 								1
#define PRIORITY_2 								2 
#define PRIORITY_3								3

#define CLOCK_FULL_LOAD 					0xFFFFFFFF

//SPI

#define Query_Command 						0xAA
#define Safety_Time								2
#define NumResponseBytes					4
#define GameStatusCMD 						0xC0
#define QueryResponseCMD 					0x70
#define SendReportCMD 						0x80

#define ReportResponseNOTReady 		0x00
#define ReportResponseReady				0xAA

#define ACK 											0x00
#define INACTIVE									0x02
#define NACK											0x03

//CheckinSM
#define DESIRED_NUM_SAMPLES					200
#define DESIRED_NUM_SAMPLES_BEACON	500
#define TOL													25
#define BEACON_TOL									50

//Driving Speeds
#define FWD_DRIVING_SPEED					35.0
#define REV_DRIVING_SPEED					-30.0
#define FWD_SLOW_SPEED						30.0

#define HALL_EDGES								200
#define BEACON_EDGES							200
#define EXIT_AREA_TIMER						3000 //mS in S

//flywheel shooting
#define FlyRampPeriod							5000		// ~5 seconds
#define CowResultWaitPeriod				3000		// ~3 seconds
#define FlyServoMoveTime					1000		// 
#define FlyControlPeriod					2
#define RPM_MIN										1000						// approximately
#define RPM_MAX										8000						// approximately
#define PER2RPM										400000000				// initial calculation
#define MINDUTY										0								
#define MAXDUTY										100					

#define PF0_UNLOCK								0x4C4F434B

#define FlyWheelStopCheckPeriod		500

//beacon
#define BEACON_DETECT_CONFIRMED		50

//motor drive
#define SEC_PER_MIN 							60

// Other
#define PI												3.1416f

#define SAFETY_TIME  							3 //mS

//sensor
#define TRIG_TIME									10*TicksPerUS
#define ULTRASONIC_SAMPLE_TIME		61 //mS
#define DISTANCE_CONSTANT					148.0 //in cm
#define INCH_TOL									.2 //inches
#define DESIRED_DIST							2.0 //inches

#define LED_DUTY									50
#define LED_FREQ									80

#endif