
class GenjiTimer:
    def __init__(self, gnjAPI, user_code, dngNr):
        self.gnjAPI = gnjAPI
        self.dngNr = dngNr
        self.user_code = user_code
        self.started=False
        self.gnjAPI.set_timer(self.user_code,  0, self.dngNr)

    def start(self):
        if 1 == self.gnjAPI.start_timer( self.user_code, self.dngNr):
            self.started=True
        
        return self.started

    def stop(self):
        if self.started==True:
            counter=[0]
            if 1 == self.gnjAPI.get_timer( self.user_code, counter, self.dngNr):
                if 1 == self.gnjAPI.stop_timer(self.user_code, self.dngNr):
                    return int((counter[0] * 64. * 1000.)  / 24000000. )
        
        return -1