#include "AnT.hpp"

#define a parameters[0]
#define b parameters[1]
#define c parameters[2]
#define d parameters[3]
#define X     currentContinuousState[0]
#define mode  currentDiscreteState[0]
#define LEFT  1
#define RIGHT 2

bool lr_map_C (const Array<real_t>& currentContinuousState,
	       const Array<int>& currentDiscreteState,
	       const Array<real_t>& parameters,
	       Array<real_t>& RHS)
{
    if (mode == LEFT)
	RHS[0] = c * X + d;
    else
	RHS[0] = a * X - b;
    
    return true;
}

bool lr_map_D (const Array<real_t>& currentContinuousState,
	       const Array<int>& currentDiscreteState,
	       const Array<real_t>& parameters,
	       Array<int>& RHS)
{
    if (X < 0.5)
	RHS[0] = LEFT;
    else
	RHS[0] = RIGHT;

    return true;
}

#undef a
#undef b 
#undef c
#undef d 
#undef X    
#undef mode 
#undef LEFT 
#undef RIGHT

extern "C" 
{

void connectSystem ()
{
  HybridMapProxy::systemFunction = lr_map_C;
  HybridMapProxy::hybridFunction = lr_map_D;
}

}




