-
-
Save vladak/2365e02473ff2be87a596bd6c5a0480d to your computer and use it in GitHub Desktop.
CircuitPython 8 safemode.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SPDX-FileCopyrightText: 2023 anecdata | |
# | |
# SPDX-License-Identifier: MIT | |
import json | |
import microcontroller | |
import supervisor | |
from ⚙️ import * | |
# safemode.py is the entry point for SAFE MODE (hard fault, etc.) | |
# store supervisor.runtime.safe_mode_reason since it won't be available during boot.py or code.py | |
# NVM Safe Mode - to cross-check against safemode reason | |
if microcontroller.nvm[NVM_INDEX_SAFEMODE] != SAFEMODESET: | |
microcontroller.nvm[NVM_INDEX_SAFEMODE] = SAFEMODESET | |
# set up the safemode dict | |
safemode_dict = {} | |
safemode_dict["safemode_reason"] = str(supervisor.runtime.safe_mode_reason) | |
update_restart_dict_time(safemode_dict) # add timestamp | |
# write dict as JSON | |
precode_file_write("/safemode.json", json.dumps(safemode_dict)) # use storage.remount() | |
if False: # check for any safemode conditions where we shouldn't RESET | |
pass | |
else: | |
# RESET out of safe mode | |
microcontroller.reset() # or alarm.exit_and_deep_sleep() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment