Guidance on running multiple programs



  • 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.



  • 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



  • @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.



  • 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()
    


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