/** trsw_timed.cpp -- timer-task transistor switch operation
 * 				for schip's L298 ardPro board.
 **/
#include "L298.h"

// get the prototypes for the schip-scheduler
#include "schip_scheduler.h"

/** Posted/called to shut off specified switch.
 *  Uses external USE_TswDone() hook to execute User code if so configed.
 *
 *  @param tnum -- transistor switch pin number
 */
void trswOffTask( uint16_t tnum )
{
	// diddle the right switch
	digitalWrite( tnum, LOW );

#ifdef USE_TswDone // not impl yet...
	// call the User
	USE_TswDone( (uint16_t)tnum );
#endif //USE_TswDone

	return;
}

/** Diddle switch state HIGH with auto-off timer.
 *  Posts the appropriate trswOffTask().
 *
 *  @param tnum -- switch bit tnum 0-7, where out2A is x01 and out1A is 0x10
 *  @param time -- clock ticks for ON, 0xffff==forever, ignored for OFF
 */
void Trsw::timedON( uint8_t tnum, uint16_t ticks )
{
	digitalWrite( tnum, HIGH );

	// if this is not a forever thing, post the OFF time...
	if( (ticks != 0xffff) )
		postTask( ticks, trswOffTask, tnum );

	return;
}
