package jp.co.ribig.genji;

public class ELTimer{
    boolean init=false;

    boolean started=false;
    short  dngNr;
    int    UserCode;

    public ELTimer(int _UserCode, short _dngNr)
    {
        UserCode = _UserCode;
        dngNr = _dngNr;

        if (1 != ELGenji.Dongle_SetTimer(UserCode, (short)0, dngNr, (short)85))
            return;

        init=true;
    }

    public boolean start()
    {
        if( init == false ) return false;

        if (1 == ELGenji.Dongle_StartTimer(UserCode, dngNr, (short)85))
            started = true;

        return started;
    }

    public boolean stop()
    {
        if( started == true && init==true )
        {
            if (1 == ELGenji.Dongle_StopTimer(UserCode, dngNr, (short)85))
                started=false;
        }

        return !started;
    }

    public double interval() 
    {
        if( started == true && init==true )
        {
            int[] dwCount = new int[1];
            if (1 == ELGenji.Dongle_GetTimer(UserCode, dwCount, dngNr,(short)85))
                return (dwCount[0] * 64.) / 24000000. * 1000.;
        }

        return -1;
    }
}