| 19 | */ |
| 20 | |
| 21 | export class Sleep { |
| 22 | static install(handler) { |
| 23 | // this dance allows handlers to be installed both at preload and run time |
| 24 | if (Object.isFrozen(Sleep.prototype.handlers)) |
| 25 | Sleep.prototype.handlers = Array.from(Sleep.prototype.handlers); |
| 26 | Sleep.prototype.handlers.push(handler); |
| 27 | } |
| 28 | |
| 29 | static getPersistentValue(index) @ "xs_get_persistent_value"; |
| 30 | static setPersistentValue(index, value) @ "xs_set_persistent_value"; |
| 31 | static deep(ms) { |
| 32 | Sleep.prototype.handlers.forEach(handler => (handler)()); |
| 33 | this.doSleepEM4(ms); |
| 34 | } |
| 35 | static doSleepEM4(ms) @ "xs_sleep_enter_em4"; |
| 36 | static getWakeupCause() @ "xs_sleep_get_reset_cause"; |
| 37 | static getWakeupPin() @ "xs_sleep_get_wakeup_pin"; |
| 38 | |
| 39 | static getIdleSleepLevel() @ "xs_sleep_get_idle_sleep_level"; |
| 40 | static setIdleSleepLevel(level) @ "xs_sleep_set_idle_sleep_level"; |
| 41 | }; |
| 42 | |
| 43 | Sleep.PowerOnReset = 0b00000001; // power applied |
| 44 | Sleep.ExternalReset = 0b00000010; // reset button |
no outgoing calls
no test coverage detected