🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Guidance on running multiple programs

    UIFlow
    3
    5
    6.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      joefly
      last edited by

      Hi all, I am still trying to figure out a lot about UIFLOW. I have gotten two independent programs to function using UIFLOW. One is to control my speakers and one as a clock and weather. My goal is to have a touch that allows me to switch between the "functions"/"screen"

      I can write it as all one program under UIFLOW, but I would have to rewrite one of the programs by repeating all the code of the second program, since there is no copy and past program.

      So I am thinking to call it out as a sub-routine. But how do I call the PROGRAM B from PROGRAM A? Similarly, using the Download function, the programs gets uploaded to FLASH RAM, can this only function as a startup program of M5Paper or can I call these programs from within another program that is running?

      Looking for some guidance, hopefully my explanation is understandable... Thanks all.

      1 Reply Last reply Reply Quote 0
      • ajb2k3A
        ajb2k3
        last edited by

        You create function loops for each function and then in the main loop you add an action that triggers the matching function call block which triggers the separate function.
        0_1642322584594_Screenshot 2022-01-16 at 08.42.54.png

        UIFlow, so easy an adult can learn it!
        If I don't know it, be patient!
        I've ether not learned it or am too drunk to remember it!
        Author of the WIP UIFlow Handbook!
        M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

        J 1 Reply Last reply Reply Quote 1
        • J
          joefly @ajb2k3
          last edited by

          @ajb2k3 Thanks for responding. I am familiar with that function. What I meant is if I have to separate programs. Is there away to call up the other program already residing in the flash. Or another words switch between two separate programs within flash memory, and to call from within one program to the other. If so how do I program it to do so.

          Sorry if I was not clear.

          1 Reply Last reply Reply Quote 1
          • R
            robalstona
            last edited by

            Programs on the device are saved in two files
            program_name.m5b (used only by uiflow to put the project back into the editor)
            program_name.py (generated python code based on your project in uiflow). This file is run on the target device.

            You can use the import program_name.py statement in your program in the execute block. Then it will be loaded and run.
            But this method has its drawbacks, because the initialization instructions at the beginning of the program will be reloaded. You have to be careful what variable names you use, so that you don't overwrite the variable values with new ones from the imported file.
            The import statement imports the code the first time and runs it, subsequent imports of the same file just load it into memory without running it (you can find a solution to this problem on google.
            Ewentually you could edit your python code before upload to device with this way to solve above problem

            def main():
              # place whole generated python
              # file in this function with
              # proper intend
            
            main()
            
            J 1 Reply Last reply Reply Quote 0
            • J
              joefly @robalstona
              last edited by

              @robalstona thank you for the guidance as it saves me a lot of trial and error. Appreciate it.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post