Skip to content

Commit 6f4b3f3

Browse files
Doom app: set boot_partition in fri3d.sys of NVS
1 parent e64f031 commit 6f4b3f3

File tree

1 file changed

+21
-2
lines changed
  • internal_filesystem/apps/com.micropythonos.doom/assets

1 file changed

+21
-2
lines changed

internal_filesystem/apps/com.micropythonos.doom/assets/doom.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Doom(Activity):
88
configdir = retrogodir + "/config"
99
bootfile = configdir + "/boot.json"
1010
partition_label = "prboom-go"
11+
esp32_partition_type_ota_0 = 16
1112
#partition_label = "retro-core"
1213
# Widgets:
1314
status_label = None
@@ -22,7 +23,9 @@ def onCreate(self):
2223
self.setContentView(screen)
2324

2425
def onResume(self, screen):
25-
self.start_wad(self.doomdir + '/Doom v1.9 Free Shareware.zip')
26+
# Do it in a separate task so the UI doesn't hang (shows progress, status_label) and the serial console keeps showing prints
27+
from mpos import TaskManager
28+
TaskManager.create_task(self.start_wad(self.doomdir + '/Doom v1.9 Free Shareware.zip'))
2629

2730
def mkdir(self, dirname):
2831
# Would be better to only create it if it doesn't exist
@@ -32,7 +35,7 @@ def mkdir(self, dirname):
3235
except Exception as e:
3336
self.status_label.set_text(f"Info: could not create directory {dirname} because: {e}")
3437

35-
def start_wad(self, wadfile):
38+
async def start_wad(self, wadfile):
3639
self.mkdir(self.romdir)
3740
self.mkdir(self.doomdir)
3841
self.mkdir(self.retrogodir)
@@ -73,6 +76,22 @@ def start_wad(self, wadfile):
7376
vfs.umount('/')
7477
except Exception as e:
7578
print(f"Warning: could not unmount internal filesystem from /: {e}")
79+
# Write the currently booted OTA partition number to NVS, so that retro-go's apps know where to go back to:
80+
try:
81+
from esp32 import NVS
82+
nvs = NVS('fri3d.sys')
83+
boot_partition = nvs.get_i32('boot_partition')
84+
print(f"boot_partition in fri3d.sys of NVS: {boot_partition}")
85+
running_partition = Partition(Partition.RUNNING)
86+
running_partition_nr = running_partition.info()[1] - self.esp32_partition_type_ota_0
87+
print(f"running_partition_nr: {running_partition_nr}")
88+
if running_partition_nr != boot_partition:
89+
print(f"setting boot_partition in fri3d.sys of NVS to {running_partition_nr}")
90+
nvs.set_i32('boot_partition', running_partition_nr)
91+
else:
92+
print("No need to update boot_partition")
93+
except Exception as e:
94+
print(f"Warning: could not write currently booted partition to boot_partition in fri3d.sys of NVS: {e}")
7695
try:
7796
import machine
7897
machine.reset()

0 commit comments

Comments
 (0)