//WebbotLib includes
#include "hardware.h"
#include "Axon_Mote_utils.h" //Axon Mote special code features

//comment out if you aren't using a microSD
//(it'll hang if you don't have one plugged in)
//#define USE_uSD //make sure you used Project Designer to enable spiBus for the proper hardware.h file

#ifdef USE_uSD
	FILE f;
	FILE g;
#endif

#include "demos.h"				//example demo programs to help you out



// Initialise the hardware
void appInitHardware(void) {
	initHardware();
}

// Initialise the software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){

	delay_ms(100);//let caps charge up

	//LED_on(&Green_LED);

	//determine selected mode
	if(SWITCH_pressed(&Switch_Left))
		{
		LED_on(&Green_LED);//do something
		MODE=LEFT;
		}
	if(SWITCH_pressed(&Switch_Right))
		{
		LED_on(&Red_LED);//do something
		MODE=RIGHT;
		}

	//let capacitors and stuff fully charge up and stabilize
	delay_ms(100);

	//initiate wireless
	wireless_reset();

	//set channel
	wireless_SetChannel(CHANNEL);//the program xmpl_trx_tx.hex uses channel 17

	//declare Axon Mote initiated
	rprintf("\n\nAxon Mote initiated.\nTransmit on Channel %d.\n\n",wireless_ReadChannel());

	//if you are not using the transmitter, you can save power by putting it in sleep mode
	//wireless_SLEEP();//you can later go into wake mode with wireless_WAKE()

	return 0;
}

// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {

	//demo_0();//wireless debug
	demo_1();//store sensor/timer data to uSD
	//demo_2();//wiggle servo around
	//demo_3();//use USB/hyperterminal to control servo
	//demo_4();//wirelessly reset the Axon Mote
	//demo_5();//write to two uSD files
	//demo_6();//remote control a robot with two Motes

	return 0;
}

