Esempio n. 1
0
def trysuspend():
    global evtime

    ## Do nothing if sleep is disabled
    timeout = settings.sleeptimeout
    if not timeout:
        return False

    ## Detect motion via the accelerometer
    dx = imu.x() - xyz[0]
    dy = imu.y() - xyz[1]
    dz = imu.z() - xyz[2]
    delta = (dx * dx) + (dy * dy) + (dz * dz)
    xyz[0] += dx
    xyz[1] += dy
    xyz[2] += dz
    if delta > (sensitivity * sensitivity):
        evtime = pyb.millis()
        return False

    ## Never suspend when USB VBus is present
    if vbus.value():
        evtime = pyb.millis()
        return False
    ## Don't sleep unless a timeout has elapsed.
    if (evtime + timeout) > pyb.millis():
        return False
    ## Turn off the display and go to deep sleep, with PA0 wakeup enabled.
    ble_enable.value(0)
    dcfurs.clear()
    pyb.standby(True)  # NOTE: pyb.standby API modified to enable PA0 wakeup.
Esempio n. 2
0
def shut_down():
    #machine.deepsleep()
    # turn off power to I2C, USB and SD
    led_R.off()
    led_G.off()
    led_B.off()
    machine.Pin('EN_3V3').off()
    # put in deep sleep - clock will wake back up
    standby()
def test(*pin_names, rising=True):
    wups = [
        upower.WakeupPin(pyb.Pin(name), rising=rising) for name in pin_names
    ]
    reason = machine.reset_cause()  # Why have we woken?
    if reason in (machine.PWRON_RESET, machine.HARD_RESET,
                  machine.SOFT_RESET):  # first boot
        rtc.datetime(
            (2020, 8, 6, 4, 13, 0, 0, 0))  # Code to run on 1st boot only
        upower.savetime()
        if upower.bkpram_ok():  # backup RAM holds valid data: battery backed
            light(2)  # Blue only
        else:  # Boot with no backup battery, data is garbage
            light(0, 1, 2)  # White
    elif reason == machine.DEEPSLEEP_RESET:
        reason = upower.why()
        if reason == 'WAKEUP':
            light(0, 1, 2)  # White on timer wakeup
            upower.savetime()
        elif reason == 'X3':  # red
            light(0)
        elif reason == 'X1':  # green
            light(1)
        elif reason == 'C1':
            light(2)  # Blue
        elif reason == 'C13':
            light(0, 1)  # Red and green
        else:
            upower.cprint('Unknown: reset?')  # Prints if a UART is configured

    upower.lpdelay(500)  # ensure LEDs visible before standby turns it off
    while any((p.state() for p in wups)):
        upower.lpdelay(50)  # Wait for wakeup signals to go away
    upower.lpdelay(50)  # Wait out any contact bounce

    # demo of not resetting the wakeup timer after a pin interrupt
    try:  # ms_left can fail in response to various coding errors
        timeleft = upower.ms_left(10000)
    except upower.RTCError:
        timeleft = 10000  # Coding error: uninitialised - just restart the timer
    # Set a minimum sleep duration: too short and it uses less power to stay awake
    # In real apps this might be longer or you might deal with it in other ways.
    timeleft = max(timeleft, 1000)
    rtc.wakeup(timeleft)
    # These calls reconfigure hardware and should be done last, shortly before standby()
    for p in wups:
        p.enable()
    if not upower.usb_connected:
        pyb.standby()  # Set pins hi-z and turn LEDs off
    else:
        light(1)  # Green LED: debugging session.
Esempio n. 4
0
def trysuspend():
    global evtime

    ## Do nothing if sleep is disabled
    timeout = settings.sleeptimeout
    if not timeout:
        return False

    ## Never suspend when USB VBus is present
    if vbus.value():
        evtime = pyb.millis()
        return False
    ## Don't sleep unless a timeout has elapsed.
    if (evtime + timeout) > pyb.millis():
        return False
    ## Turn off the display and go to deep sleep, with PA0 wakeup enabled.
    ble_enable.value(0)
    dcfurs.clear()
    pyb.standby(True)  # NOTE: pyb.standby API modified to enable PA0 wakeup.
Esempio n. 5
0
def dostandby():
    while True:
        pyb.standby()  # wakeup causes reset
Esempio n. 6
0
""" Module for executing code on embedded device

This module runs the logger program.  It flashes the blue led once, for one seccond, if there is an error, then
goes into standby and will try again after the appropriate logging interval.

"""

import pyb,time
log_interval = 30 #seconds
try:
    import logger_ctd
    logger_ctd.log(log_interval)
except:
    pyb.led(4).on()
    time.sleep(1)
    pyb.RTC.wakeup(log_interval*1000)
    pyb.standby()
Esempio n. 7
0
        leds[2].on()
        upower.savetime()
    elif reason == "TAMPER":  # red
        leds[0].on()
    elif reason == "X1":  # red and green on X1 rising edge
        leds[0].on()
        leds[1].on()
    else:
        upower.cprint("Unknown: reset?")  # Prints if a UART is configured

t = rtc.datetime()[4:7]
upower.cprint("{:02d}.{:02d}.{:02d}".format(t[0], t[1], t[2]))

upower.lpdelay(500)  # ensure LED visible before standby turns it off
tamper.wait_inactive()  # Wait for tamper signal to go away
wkup.wait_inactive()
upower.lpdelay(50)  # Wait out any contact bounce
# demo of not resetting the wakeup timer after a pin interrupt
try:  # ms_left can fail in response to various coding errors
    timeleft = upower.ms_left(10000)
except upower.RTCError:
    timeleft = 10000  # Coding error: uninitialised - just restart the timer
timeleft = max(timeleft, 1000)  # Set a minimum sleep duration: too short and it uses less power to stay awake
# In real apps this might be longer or you might deal with it in other ways.
rtc.wakeup(timeleft)
# These calls reconfigure hardware and should be done last, shortly before standby()
tamper.enable()
wkup.enable()
if not upower.usb_connected:
    pyb.standby()  # This will set pins hi-z and turn LEDs off
Esempio n. 8
0
                # host invia dati a pyBoard - host send deta to pyBoard.
                uart.write('Invio dato a pyBoard :'+'\n')
                uart.write(inBuffer_rx+'\n')
                bkram[0] = len(inBuffer_rx)
                ba[4: 4+len(inBuffer_rx)] = inBuffer_rx
              
                restore_data()
                uart.write('Settaggio RTC'+'\n')
               
                set_rtc() # sincronizzo RTC con orario host -sync MCU RTC with host time.

                set_allarms() # imposto allarmi secondo dati ricevuti da host -set alarms based on host input.
                reason=''
                upower.wkup.enable()
                pin_FF_reset.low()
                pyb.standby()  
     
    if reason=='ALARM_A':
       uart.write('Evento Alarm A'+'\n') 
       verde.on()
       pyb.delay(30)
       verde.off()
       print('Gestione Alarm A')
       restore_data()
       uart.write('Relay A :'+pkl['relay_a']+ '\n')
            
       if enable_sonda_a==True:
          uart.write('Soglia Lettura A :'+ '\n') 
          lettura_sonda_a=leggi_sonda_a()
          uart.write('Lettura Sonda  A :'+str(lettura_sonda_a)+ '\n')
          uart.write('Soglia Lettura A :'+pkl['tr_sonda_a']+ '\n')
Esempio n. 9
0
elif reason == 'TAMPER':  # red
    leds[0].on()
elif reason == 'X1':  # red and green on X1 rising edge
    leds[0].on()
    leds[1].on()
else:
    upower.cprint('Unknown: reset?')  # Prints if a UART is configured

t = rtc.datetime()[4:7]
upower.cprint('{:02d}.{:02d}.{:02d}'.format(t[0], t[1], t[2]))

upower.lpdelay(500)  # ensure LED visible before standby turns it off
tamper.wait_inactive()  # Wait for tamper signal to go away
wkup.wait_inactive()
upower.lpdelay(50)  # Wait out any contact bounce
# demo of not resetting the wakeup timer after a pin interrupt
try:  # ms_left can fail in response to various coding errors
    timeleft = upower.ms_left(10000)
except upower.RTCError:
    timeleft = 10000  # Coding error: uninitialised - just restart the timer
timeleft = max(
    timeleft, 1000
)  # Set a minimum sleep duration: too short and it uses less power to stay awake
# In real apps this might be longer or you might deal with it in other ways.
rtc.wakeup(timeleft)
# These calls reconfigure hardware and should be done last, shortly before standby()
tamper.enable()
wkup.enable()
if not upower.usb_connected:
    pyb.standby()  # This will set pins hi-z and turn LEDs off