ControlP5 How to create Multiple ControlFrame's using Separate Setup/Draws

edited April 2014 in Library Questions

I am trying to create multiple controlframe's where one is running GWOptics and the second Peasycam where the main sketch passes data to the controlframes. I have the GWOptics running no problem but running into issue on how to setup the second controlframe to run Peasycam. I did find this post https://discussions.zoho.com/processing/topic/controlp5-multiple-sketch-frame-windows-and-controls-on-each but can not for the life of me figure out how to get separate sketches running. I am a newbie so the problem may be me. Any help would be appreciated. I did try and use PFrame to create the second window, it worked to create the window but froze the whole sketch.

Any help would be appreciated. Mike

Answers

  • Update to my post. I am finally able to get Peasycam in the second applet after I cam across this post https://github.com/processing/processing/issues/2197. The second applet works fine but it crashes the calling or main sketch. As you can tell I am a newbie. Here is the test code for the second applet that I am using:

    public void GPStrace() {
      //frameRate(120);
      eSketch = new EmbeddedSketch(child);
      cp5.get(Button.class, "GPStrace").setVisible(false);
    }
    
    //The JFrame which will contain the child applet
    public class EmbeddedSketch extends JFrame {
      PApplet sketch;
      public EmbeddedSketch(PApplet p) {
        add(p);
        p.init();
        sketch = p;
        setVisible(true);
        setBounds(100, 100, 900, 600);
    
        setLocation(100, 100);
        //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }
    }
    
    
    public class ChildApplet extends PApplet {
    
        public void setup() {
          size(900, 600, P3D);
          smooth();
          background(0);
          colorMode(HSB, 360, 100, 100);
          fill(180); //colour of title & instructions
    
          cam = new PeasyCam(this, 100);
          cam.reset();
          //cam.setMinimumDistance(50);
          //cam.setMaximumDistance(500);
        }
    
        public void draw() {
          background(0);
          println(lat);
          box(50, 200, 100);
          // map lat and long to height & width of screen display
          /*float screen_X = map(longt*10000, west*10000, east*10000, 0, width);
          float screen_Y = map(lat*10000, north*10000, south*10000, 0, height);
    
          //map elevation to appropriate vertical scale for z-axis
          float screen_Z = map(gpsalt, lowest, highest, 0, 50);
    
          stroke(map(screen_Z, 0, 50, 240, 50), 99, 99); //otherwise map point colour to elevation
    
          // call function to display the points
          point(screen_X, screen_Y, screen_Z);*/
    
        }
    } 
    

    Here are the extracts of the calling applet (primary):

     import processing.serial.*;
    import processing.opengl.*;
    import java.awt.Frame;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    
    import javax.swing.JFrame;
    EmbeddedSketch eSketch;
    ChildApplet child = new ChildApplet();
    
    import peasy.*;
    PeasyCam cam, cam2;
    

    in setup()

          //add button to open gps trace window
          cp5.addButton("GPStrace")
             .setPosition(500,420)
             .setSize(240,30)
             .setCaptionLabel("Open Rolling Trace Frame")
             ;
    

    Still would like to implement the second window with controlFrame and get the gps trace window working at the same time, The IMU GUI reads data from Arduino and does the visualization and when I press the gpstrace button I want the second applet to run at the same time using the gps data. Here is a link to a video that will give you an idea of what I done so far:

    thanks in advance

Sign In or Register to comment.