/* ROVLIB.H, Rover Library Header */

#ifndef		__rovlib_H
#define		__rovlib_H

#include <stdlib.h>
#include "rovlib.h"
#include "rovsys.h"
#include "rovint.h"
#include "rovfile.h"

#ifdef AZTEC_C    /* Include if compiler is Aztec C */
#include <sim.h>
#include <pins.h>
#include <atod.h>
#include <tpu.h>
#include <tt7.h>
#include <timing.h>
#include <excepts.h>
#include <serio.h>
#include "tserial.h"
#define IOPORT1   ((uspv) (0xE00000))
#define IOPORT2   ((uspv) (0xE00002))

#else			/* Include if Turbo C */
#include "tt7pclib.h"
#include "conio.h"
#endif


#define		CLEARBIT	0
#define		SETBIT		1

/* Function Prototypes */

void outauxport(short port, short setclear, unsigned short outdata);
int inauxport(unsigned short portbit);
void reset(void);
int heading(void);
void setcomchan(short chan);
void setanachan(short chan);
int move_rov(char direction);
int move_rack(char direction);
int move_currmet(char direction);
int TPUiorelay(char chan);
int TPUGetPinES(short chan, short edge);
short cmvane(void);
int timer(long starttime, long maxtime);
int turn_rov(int new_heading);
int transit_rov(int transit_dist);
int rack_down_cycle(void);
void delaysecs(unsigned long delay_time);
int get_ad_counts(int chan);
void transpond_out(void);
int currmet_up(void);
int currmet_down(void);
void sleep_with_break(unsigned long delay_time);
void clear_auxports(void);


/*************Power Control Board Macros****************/

#define sensor_pwr_on()		outauxport(3, SETBIT, POWER6)
#define sensor_pwr_off()	outauxport(3, CLEARBIT, POWER6)
#define transponder_pwr_on()    outauxport(3, SETBIT, POWER4)
#define transponder_pwr_off()   outauxport(3, CLEARBIT, POWER4)


/**************Analog Port Macros************************/

#define batt_volt()  		(float)get_ad_counts(BATTCHAN)/BATTCAL)
#define hp_current()		(float)get_ad_counts(HPCURRCHAN)/HPCURRCAL)
#define lp_current()            (float)get_ad_counts(HPCURRCHAN)/HPCURRCAL)
#define gf_volt()               (float)get_ad_counts(GFVOLTCHAN)/GFVOLTCAL)
#define tiltx_deg()	 ((float)get_ad_counts(TILTX_CHAN)/TILTX_CAL - TILTX_OFFSET)
#define tilty_deg()      ((float)get_ad_counts(TILTY_CHAN)/TILTY_CAL - TILTY_OFFSET)


/*************Film/Video Camera Macros******************/

#define strobe_pwr_on()		outauxport(2, SETBIT, AUX1)
#define strobe_pwr_off()	outauxport(2, CLEARBIT, AUX1)
#define filmcam_trig_on()   	TPUSetPin(1,1)
#define filmcam_trig_off() 	TPUSetPin(1,0)

#define flood1_pwr_on()		outauxport(1, SETBIT, AUX1)
#define flood1_pwr_off()	outauxport(1, CLEARBIT, AUX1)
#define flood2_pwr_on()		outauxport(1, SETBIT, AUX2)
#define flood2_pwr_off()	outauxport(1, CLEARBIT, AUX2)

/***************** Sensor Macros *************************/

#define rack_up()		!inauxport(RACKUP)
#define limit_up()		!inauxport(LIMITUP)
#define limit_dwn()		!inauxport(LIMITDWN)
#define limit_pad1()		!inauxport(LIMITPAD1)
#define limit_pad2()		!inauxport(LIMITPAD2)
#define cm_limit()		!inauxport(CMLIMIT)

/******************* Current Meter Macros *****************/

#define cmvane_pwr_on()  	TPUSetPin(CMVANE_PWR, 1)
#define cmvane_pwr_off()  	TPUSetPin(CMVANE_PWR, 0)
#define cmvane_dir()            ((short)(cmvane()/CMVANECAL+180)%360)

#endif