From 1cab1519e5ad905d2a657a25a6d8e71fd5e1ec19 Mon Sep 17 00:00:00 2001 From: Davide Bettio Date: Sat, 22 Jul 2023 15:57:30 +0200 Subject: [PATCH] ESP32: add option option for starting always dev mode Add (opt-in) NVS setting for enabling always ALISP console and web server. Signed-off-by: Davide Bettio --- libs/esp32boot/esp32init.erl | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libs/esp32boot/esp32init.erl b/libs/esp32boot/esp32init.erl index 32386fcc0..19a898ac9 100644 --- a/libs/esp32boot/esp32init.erl +++ b/libs/esp32boot/esp32init.erl @@ -61,9 +61,22 @@ loop() -> loop() end. +maybe_start_dev_mode(SystemStatus) -> + case {SystemStatus, esp:nvs_get_binary(atomvm, dev_mode)} of + {_, <<"always">>} -> + start_dev_mode(); + {_, <<"never">>} -> + not_started; + {ok, undefined} -> + not_started; + {failed_app_start, undefined} -> + start_dev_mode() + end. + start_dev_mode() -> avm_pubsub:start(default_pubsub), - spawn(?MODULE, maybe_start_network, []). + spawn(?MODULE, maybe_start_network, []), + started. %% %% Boot handling @@ -78,10 +91,11 @@ boot() -> case atomvm:add_avm_pack_file(BootPath, [{name, app}]) of ok -> StartModule = get_start_module(), + maybe_start_dev_mode(ok), StartModule:start(); {error, Reason} -> io:format("Failed app start: ~p.~n", [Reason]), - start_dev_mode() + maybe_start_dev_mode(failed_app_start) end. get_boot_path() ->