diff --git a/tasmota/berry/modules/partition.be b/tasmota/berry/modules/partition.be index b5d90aa4f..631a05fd3 100644 --- a/tasmota/berry/modules/partition.be +++ b/tasmota/berry/modules/partition.be @@ -110,6 +110,15 @@ class Partition_info end + # check if the parition is an OTA partition + # if yes, return OTA number (starting at 0) + # if no, return nil + def is_ota() + if self.type == 0 && (self.subtype >= 0x10 && self.subtype < 0x20) + return self.subtype - 0x10 + end + end + def tostring() import string var type_s = "" @@ -418,14 +427,13 @@ end partition.Partition = Partition return partition -#Example -#- + +#- Example import partition -Partition = partition.Partition # read -p = Partition() +p = partition.Partition() print(p) -# \ No newline at end of file diff --git a/tasmota/berry/modules/partition_manager.be b/tasmota/berry/modules/partition_manager.be new file mode 100644 index 000000000..7db4b16f5 --- /dev/null +++ b/tasmota/berry/modules/partition_manager.be @@ -0,0 +1,100 @@ +#------------------------------------------------------------- + - Parser manager for ESP32 + - + -------------------------------------------------------------# + +import flash +import string +import partition +import webserver + +class Partition_manager : Driver + + def init() + end + + # create a method for adding a button to the main menu + # the button 'Partition Manager' redirects to '/part_mgr?' + def web_add_button() + webserver.content_send( + "
") + end + + # + # Show a single OTA Partition + # + def page_show_partition(slot, active) + webserver.content_send("") + end + + + # + # Show a single OTA Partition + # + def page_show_spiffs(slot, free_mem) + webserver.content_send("") + end + + def page_show_partitions() + var p = partition.Partition() + + # display ota partitions + for slot: p.slots + # is the slot app? + var ota_num = slot.is_ota() + if ota_num != nil + # we have an OTA partition + self.page_show_partition(slot, ota_num == p.otadata.active_otadata) + elif slot.type == 1 && slot.subtype == 130 + var flash_size = tasmota.memory()['flash'] * 1024 + var used_size = (slot.start + slot.size) + self.page_show_spiffs(slot, slot == p.slots[-1] ? flash_size - used_size : nil) + end + end + end + + #- this method displays the web page -# + def page_part_mgr() + if !webserver.check_privileged_access() return nil end + + webserver.content_start("Partition Manager") #- title of the web page -# + webserver.content_send_style() #- send standard Tasmota styles -# + + webserver.content_send("Esp32 Partition Manager
") #- send any html -# + self.page_show_partitions() + + webserver.content_button(webserver.BUTTON_MANAGEMENT) #- button back to management page -# + webserver.content_stop() #- end of web page -# + end + + #- this is called at Tasmota start-up, as soon as Wifi/Eth is up and web server running -# + def web_add_handler() + #- we need to register a closure, not just a function, that captures the current instance -# + webserver.on("/part_mgr", / -> self.page_part_mgr()) + end + +end + +#- create and register driver in Tasmota -# +partition_manager = Partition_manager() +tasmota.add_driver(partition_manager) +## to be removed if put in 'autoexec.bat' +partition_manager.web_add_handler() \ No newline at end of file