コード例 #1
0
  /**
   * Instantiates a new internal debug window.
   *
   * @param displayHoriz the display horiz
   * @param the maximal x size of the window
   */
  public GeneratorGuiCreator(int maximalXSize, int maximalYSize, String version) {
    int nrOfScreens = Collector.getInstance().getAllVisuals().size();
    LOG.log(Level.INFO, "create GUI, nr of screens: " + nrOfScreens);

    Generator g = Collector.getInstance().getPixelControllerGenerator().getGenerator(0);
    float aspect = (float) g.getInternalBufferXSize() / (float) g.getInternalBufferYSize();

    int singleVisualXSize = 0, singleVisualYSize = 1000;

    while (singleVisualYSize > maximalYSize) {
      singleVisualXSize = maximalXSize / nrOfScreens;
      singleVisualYSize = (int) (maximalXSize / nrOfScreens / aspect);
      maximalXSize -= 100;
    }

    int windowXSize = singleVisualXSize * nrOfScreens;
    int windowYSize = singleVisualYSize + 350;

    // ugly boarder stuff
    windowXSize += 20;

    if (windowXSize < MINIMAL_WINDOW_X_SIZE) {
      windowXSize = MINIMAL_WINDOW_X_SIZE;
    }

    // connect the new PApplet to our frame
    gui = new GeneratorGui(windowXSize, windowYSize, singleVisualXSize, singleVisualYSize);
    gui.init();

    // create new window for child
    LOG.log(
        Level.INFO,
        "create frame with size " + windowXSize + "/" + windowYSize + ", aspect: " + aspect);
    JFrame childFrame = new JFrame("PixelController Generator Window " + version);
    childFrame.setResizable(false);
    childFrame.setIconImage(GeneratorGuiCreator.createLargeIcon());

    childFrame.add(gui);

    childFrame.setBounds(0, 0, windowXSize, windowYSize + 30);
    gui.setBounds(0, 0, windowXSize, windowYSize + 30);

    // important to call this whenever embedding a PApplet.
    // It ensures that the animation thread is started and
    // that other internal variables are properly set.
    childFrame.setVisible(true);

    // childFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    childFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    childFrame.addWindowListener(new WindowHandler());
  }
コード例 #2
0
 /**
  * helper function to load the large pixelinvaders logo
  *
  * @return
  */
 public static Image createLargeIcon() {
   PImage img = Collector.getInstance().getPapplet().loadImage("pics/logoBig.jpg");
   if (img != null) {
     return img.getImage();
   }
   img = new PImage(400, 400);
   return img.getImage();
 }
コード例 #3
0
 @Override
 public String getConnectionStatus() {
   if (initialized) {
     return "Target IP: "
         + targetAdress
         + ", # of universe: "
         + nrOfUniverse * Collector.getInstance().getNrOfScreens();
   }
   return "Not connected!";
 }
コード例 #4
0
  /* (non-Javadoc)
   * @see com.neophob.sematrix.output.Output#update()
   */
  @Override
  public void update() {
    int universeOfs = 0;

    if (initialized) {
      int nrOfScreens = Collector.getInstance().getNrOfScreens();
      for (int nr = 0; nr < nrOfScreens; nr++) {
        // get the effective panel buffer
        int panelNr = this.panelOrder.get(nr);

        // get buffer data
        int[] transformedBuffer =
            RotateBuffer.transformImage(
                super.getBufferForScreen(nr),
                displayOptions.get(panelNr),
                this.matrixData.getDeviceXSize(),
                this.matrixData.getDeviceYSize());

        if (this.snakeCabeling) {
          // flip each 2nd scanline
          transformedBuffer =
              OutputHelper.flipSecondScanline(
                  transformedBuffer,
                  this.matrixData.getDeviceXSize(),
                  this.matrixData.getDeviceYSize());
        } else if (this.mapping.length > 0) {
          // do manual mapping
          transformedBuffer =
              OutputHelper.manualMapping(transformedBuffer, mapping, xResolution, yResolution);
        }

        byte[] rgbBuffer =
            OutputHelper.convertBufferTo24bit(transformedBuffer, colorFormat.get(panelNr));

        // send out
        int remainingBytes = rgbBuffer.length; // 510
        int ofs = 0;
        for (int i = 0; i < this.nrOfUniverse; i++) {
          int tmp = pixelsPerUniverse * 3; // tmp=510
          if (remainingBytes <= pixelsPerUniverse * 3) {
            tmp = remainingBytes;
          }
          byte[] buffer = new byte[tmp];
          System.arraycopy(rgbBuffer, ofs, buffer, 0, tmp);
          remainingBytes -= tmp;
          ofs += tmp;
          sendBufferToReceiver(this.firstUniverseId + universeOfs, buffer);

          universeOfs++;
        }
      }
    }
  }
コード例 #5
0
  protected void calculateNrOfUniverse() {
    // check how many universe we need
    this.nrOfUniverse = 1;
    int bufferSize = xResolution * yResolution;
    if (bufferSize > pixelsPerUniverse) {
      while (bufferSize > pixelsPerUniverse) {
        this.nrOfUniverse++;
        bufferSize -= pixelsPerUniverse;
      }
    }

    LOG.log(Level.INFO, "\tPixels per universe: " + pixelsPerUniverse);
    LOG.log(Level.INFO, "\tFirst universe ID: " + firstUniverseId);
    LOG.log(
        Level.INFO, "\t# of universe: " + nrOfUniverse * Collector.getInstance().getNrOfScreens());
    LOG.log(Level.INFO, "\tOutput Mapping entry size: " + this.mapping.length);
    LOG.log(Level.INFO, "\tTarget address: " + targetAdress);
  }
コード例 #6
0
  /**
   * init the Stealth devices.
   *
   * @param controller the controller
   * @param displayOptions the display options
   * @param colorFormat the color format
   */
  public StealthDevice(ApplicationConfigurationHelper ph, PixelControllerOutput controller) {
    super(OutputDeviceEnum.STEALTH, ph, controller, 5);

    this.displayOptions = ph.getStealthDevice();
    this.colorFormat = ph.getColorFormat();
    this.initialized = false;
    try {
      stealth = new Stealth(Collector.getInstance().getPapplet());
      this.initialized = stealth.ping();
      LOG.log(Level.INFO, "ping result: " + this.initialized);
    } catch (NoSerialPortFoundException e) {
      LOG.log(Level.WARNING, "failed to initialize serial port!");
    } catch (Throwable e) {
      // catch really ALL excetions here!
      LOG.log(Level.SEVERE, "\n\n\n\nSERIOUS ERROR, check your RXTX installation!", e);
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e1) {
      }
    }
  }
コード例 #7
0
  /* (non-Javadoc)
   * @see com.neophob.sematrix.output.Output#update()
   */
  public void update() {

    if (initialized) {
      for (int ofs = 0; ofs < Collector.getInstance().getNrOfScreens(); ofs++) {
        // draw only on available screens!
        int[] transformedBuffer =
            RotateBuffer.transformImage(
                super.getBufferForScreen(ofs),
                displayOptions.get(ofs),
                Stealth.NR_OF_LED_HORIZONTAL,
                Stealth.NR_OF_LED_VERTICAL);

        if (stealth.sendRgbFrame((byte) ofs, transformedBuffer, colorFormat.get(ofs))) {
          needUpdate++;
        } else {
          noUpdate++;
        }
      }

      if ((noUpdate + needUpdate) % 100 == 0) {
        float f = noUpdate + needUpdate;
        float result = (100.0f / f) * needUpdate;
        LOG.log(
            Level.INFO,
            "sended frames: {0}% {1}/{2}, ack Errors: {3} last Error: {4}, arduino buffer size: {5}",
            new Object[] {
              result,
              needUpdate,
              noUpdate,
              stealth.getAckErrors(),
              stealth.getArduinoErrorCounter(),
              stealth.getArduinoBufferSize()
            });
      }
    }
  }
コード例 #8
0
 /** refresh gui if we selected a new visual. */
 public void sendStatusToGuiMini() {
   for (String s : Collector.getInstance().getCurrentMiniStatus()) {
     sendFudiMsg(s);
   }
 }
コード例 #9
0
  /** tcp server thread. */
  public void run() {
    LOG.log(Level.INFO, "Ready receiving messages...");
    while (Thread.currentThread() == runner) {

      if (tcpServer != null) {
        try {

          // check if client is available
          if (client != null && client.active()) {
            // do not send sound status to gui - very cpu intensive!
            // sendSoundStatus();

            if ((count % 20) == 2 && Collector.getInstance().isRandomMode()) {
              sendStatusToGui();
            }
          }

          Client c = tcpServer.available();
          if (c != null && c.available() > 0) {

            // clean message
            String msg = lastMsg + StringUtils.replace(c.readString(), "\n", "");
            // add replacement end string
            msg = StringUtils.replace(msg, FUDI_ALTERNATIVE_END_MARKER, FUDI_MSG_END_MARKER);
            msg = StringUtils.trim(msg);

            int msgCount = StringUtils.countMatches(msg, FUDI_MSG_END_MARKER);
            LOG.log(Level.INFO, "Got Message: <{0}> cnt: {1}", new Object[] {msg, msgCount});

            // work around bug - the puredata gui sends back a message as soon we send one
            long delta = System.currentTimeMillis() - lastMessageSentTimestamp;
            if (delta < FLOODING_TIME) {
              LOG.log(
                  Level.INFO,
                  "Ignore message, flooding protection ({0}<{1})",
                  new String[] {"" + delta, "" + FLOODING_TIME});
              // delete message
              msgCount = 0;
              msg = "";
            }

            // ideal, one message receieved
            if (msgCount == 1) {
              msg = StringUtils.removeEnd(msg, FUDI_MSG_END_MARKER);
              lastMsg = "";
              processMessage(StringUtils.split(msg, ' '));
            } else if (msgCount == 0) {
              // missing end of message... save it
              lastMsg = msg;
            } else {
              // more than one message received, split it
              // TODO: reuse partial messages
              lastMsg = "";
              String[] msgs = msg.split(FUDI_MSG_END_MARKER);
              for (String s : msgs) {
                s = StringUtils.trim(s);
                s = StringUtils.removeEnd(s, FUDI_MSG_END_MARKER);
                processMessage(StringUtils.split(s, ' '));
              }
            }
          }
        } catch (Exception e) {
        }
      }

      count++;
      try {
        Thread.sleep(50);
      } catch (InterruptedException e) {
        // Ignored
      }
    }
  }