#include <rccl.h>
#include "manex.560.h"

#define THRESHOLD 500

touchFxn(mid, mnp)
int mid;
MANIP *mnp;
{
        HOW *how;
        static int count = 0;
#ifdef VXWORKS_CFG
        static int initDone = 0;
        if (!initDone)
         { initDone = 1;
           count = 0;
           requestFlagInit(&initDone);
         }
#endif  
        how = mnp->how;                                         /*17*/

        /* *if* we have an ADC channel, use it for sensor readings.
           Otherwise, fake the touch function using the motion
           scale value */

        if (how->numAdc > 0)
         { if (how->adc & 0x1 && how->adcInput[0] > THRESHOLD)
            { stopMotion (mid, 1);                              /*18*/
            }
         }
        else
         { if (motionScale(mid) > (count == 0 ? 0.2 : 0.6))     /*19*/
            { stopMotion (mid, 1);
              count++;
            }
         }
}
