Timer.Alarm nested in another Timer.Alarm possible?



  • Hi.

    I am able to use the Timer.Alarm() without any problems normally.

    But i run into problems when i have a Timer.Alarm() nested inside of a method that is called by another Timer.Alarm().

    I am creating a program, which is supposed to use lightsleep mode until a wakeup from the accelerometer.

    The program has two Timer.Alarms running in main() which starts when it wakes up. One of these runs a method which initiates yet another alarm to take measurements from the accelerometer. But it seems this alarm is never activated. So is this sort of "nesting" of Timer.Alarms not possible / bad practice, and what is the alternatives?

    I am posting a example here, i hope it is understandable without you needing the whole of my main().

    #Initial Alarm
    activity_alarm = Timer.Alarm(lambda y: timer_sampler(), s = 1, periodic = True)
    
    #The method that the activity_alarm uses, which starts yet another alarm (ignore the prints for debugging)
    def timer_sampler():
        print("Entering timer_sampler() method!")
        global is_active
        acc.set_odr(6)
        acc.set_full_scale(3)
        acc.enable_activity_interrupt(126, 10)
        if acc.activity():
            print("There is activity in timer_sampler() method!")
            if is_active == False:
                is_active = True
                print("Starting ALARM!!")
                alarm = Timer.Alarm(lambda x: sample(), ms = 10, periodic = True)
        #elif not acc.activity():
        print("There is now NO activity in timer_sampler() method!")
        if is_active == True:
            is_active = False
            alarm.cancel()
    
    
    

Log in to reply
 

Pycom on Twitter