/****************************************************************************
 Template header file for Hierarchical Sate Machines AKA StateCharts

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

#ifndef SMBeaconDetection_H
#define SMBeaconDetection_H

// Event Definitions
#include "SMEvents.h"

// typedefs for the states
// State definitions for use with the query function
typedef enum { Beacon_Running } BeaconState_t ;

typedef enum
{
	Beacon_None = 0,
	Beacon_Dispenser0,
	Beacon_Dispenser1,
	Beacon_Dispenser2,
	Beacon_Dispenser3,
	Beacon_GreenHoop,
	Beacon_RedHoop
} Beacon_t;

typedef enum
{
	Beacon_NeverSeen = 0,
	Beacon_LostLeft,
	Beacon_Left,
	Beacon_Straight,
	Beacon_Right,
	Beacon_LostRight
} BeaconDirection_t;

#define DETECTOR0 0
#define DETECTOR1 1

typedef enum
{
	Beacon_DetectorLeft = DETECTOR0,
	Beacon_DetectorRight = DETECTOR1
} BeaconDetector_t;

// Public Function Prototypes

//State machine Prototypes
Event_t RunBeaconDetectionSM( Event_t CurrentEvent );
void StartBeaconDetectionSM ( Event_t CurrentEvent );
BeaconState_t QueryBeaconDetectionSM ( void );

//Other Prototypes
/****************************************************************************
 Function
 ClearBeaconDirection

 Description
 Resets the history of each beacon direction.  Useful for clearing possible
 identification errors due to being very close to a beacon.
 ****************************************************************************/
void ClearBeaconDirection(void);

/****************************************************************************
 Function
 QueryBeaconTracking

 Returns
 Beacon_t - the current beacon being tracked by both detectors

 Notes
 Will return Beacon_None if no beacon is currently identified
 ****************************************************************************/
Beacon_t QueryBeaconTracking (void);

/****************************************************************************
 Function
 QueryBeaconLastTracked

 Returns
 Beacon_t - the last beacon that was being tracked by both detectors

 Notes
 Identical to QueryBeaconTracking, but will return a valid beacon once one has
 been identified.
 ****************************************************************************/
Beacon_t QueryBeaconLastTracked (void);

/****************************************************************************
 Function
 QueryBeaconDirection

 Parameters
 Beacon_t - the beacon whose direction we wish to check

 Returns
 BeaconDirection_t - the direction of the beacon, as recorded in the history

 Description
 Checks history for beacon's direction
 ****************************************************************************/
BeaconDirection_t QueryBeaconDirection (Beacon_t Beacon);

#endif