public boolean avrdude(Collection params) throws RunnerException {
    List commandDownloader = new ArrayList();
    commandDownloader.add("avrdude");

    // Point avrdude at its config file since it's in a non-standard location.
    if (Base.isMacOS()) {
      commandDownloader.add("-C" + "hardware/tools/avr/etc/avrdude.conf");
    } else if (Base.isWindows()) {
      String userdir = System.getProperty("user.dir") + File.separator;
      commandDownloader.add("-C" + userdir + "hardware/tools/avr/etc/avrdude.conf");
    } else {
      // ???: is it better to have Linux users install avrdude themselves, in
      // a way that it can find its own configuration file?
      commandDownloader.add("-C" + "hardware/tools/avrdude.conf");
    }

    if (Preferences.getBoolean("upload.verbose")) {
      commandDownloader.add("-v");
      commandDownloader.add("-v");
      commandDownloader.add("-v");
      commandDownloader.add("-v");
    } else {
      commandDownloader.add("-q");
      commandDownloader.add("-q");
    }
    // XXX: quick hack to chop the "atmega" off of "atmega8" and "atmega168",
    // then shove an "m" at the beginning.  won't work for attiny's, etc.
    commandDownloader.add(
        "-pm" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu").substring(6));
    commandDownloader.addAll(params);

    return executeUploadCommand(commandDownloader);
  }
 // XXX: add support for uploading sketches using a programmer
 public boolean uploadUsingPreferences(String buildPath, String className) throws RunnerException {
   String uploadUsing = Preferences.get("boards." + Preferences.get("board") + ".upload.using");
   if (uploadUsing == null) {
     // fall back on global preference
     uploadUsing = Preferences.get("upload.using");
   }
   if (uploadUsing.equals("bootloader")) {
     return uploadViaBootloader(buildPath, className);
   } else {
     Collection params = getProgrammerCommands(uploadUsing);
     params.add("-Uflash:w:" + buildPath + File.separator + className + ".hex:i");
     return avrdude(params);
   }
 }
Exemplo n.º 3
0
 static synchronized String getpref(String prefname, String def) {
   try {
     if (prefs == null) prefs = Preferences.userNodeForPackage(Utils.class);
     return (prefs.get(prefname, def));
   } catch (SecurityException e) {
     return (def);
   }
 }
  private Collection getProgrammerCommands(String programmer) {
    List params = new ArrayList();
    params.add("-c" + Preferences.get("programmers." + programmer + ".protocol"));

    if ("usb".equals(Preferences.get("programmers." + programmer + ".communication"))) {
      params.add("-Pusb");
    } else if ("serial".equals(Preferences.get("programmers." + programmer + ".communication"))) {
      params.add("-P" + (Base.isWindows() ? "\\\\.\\" : "") + Preferences.get("serial.port"));
      // XXX: add support for specifying the baud rate for serial programmers.
    }
    // XXX: add support for specifying the port address for parallel
    // programmers, although avrdude has a default that works in most cases.

    if (Preferences.get("programmers." + programmer + ".force") != null
        && Preferences.getBoolean("programmers." + programmer + ".force")) params.add("-F");

    if (Preferences.get("programmers." + programmer + ".delay") != null)
      params.add("-i" + Preferences.get("programmers." + programmer + ".delay"));

    return params;
  }
  private boolean uploadViaBootloader(String buildPath, String className) throws RunnerException {
    List commandDownloader = new ArrayList();
    String protocol = Preferences.get("boards." + Preferences.get("board") + ".upload.protocol");

    // avrdude wants "stk500v1" to distinguish it from stk500v2
    if (protocol.equals("stk500")) protocol = "stk500v1";
    commandDownloader.add("-c" + protocol);
    commandDownloader.add(
        "-P" + (Base.isWindows() ? "\\\\.\\" : "") + Preferences.get("serial.port"));
    commandDownloader.add(
        "-b" + Preferences.getInteger("boards." + Preferences.get("board") + ".upload.speed"));
    commandDownloader.add("-D"); // don't erase
    commandDownloader.add("-Uflash:w:" + buildPath + File.separator + className + ".hex:i");

    if (Preferences.get("boards." + Preferences.get("board") + ".upload.disable_flushing") == null
        || Preferences.getBoolean("boards." + Preferences.get("board") + ".upload.disable_flushing")
            == false) {
      flushSerialBuffer();
    }

    return avrdude(commandDownloader);
  }
Exemplo n.º 6
0
  protected String[] getSketchParams(boolean presenting) {
    ArrayList<String> params = new ArrayList<String>();

    // It's dangerous to add your own main() to your code,
    // but if you've done it, we'll respect your right to hang yourself.
    // http://processing.org/bugs/bugzilla/1446.html
    if (build.getFoundMain()) {
      params.add(build.getSketchClassName());

    } else {
      params.add("processing.core.PApplet");

      // get the stored device index (starts at 0)
      int runDisplay = Preferences.getInteger("run.display");

      // If there was a saved location (this guy has been run more than once)
      // then the location will be set to the last position of the sketch window.
      // This will be passed to the PApplet runner using something like
      // --location=30,20
      // Otherwise, the editor location will be passed, and the applet will
      // figure out where to place itself based on the editor location.
      // --editor-location=150,20
      if (editor != null) { // if running processing-cmd, don't do placement
        GraphicsDevice editorDevice = editor.getGraphicsConfiguration().getDevice();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = ge.getScreenDevices();

        // Make sure the display set in Preferences actually exists
        GraphicsDevice runDevice = editorDevice;
        if (runDisplay >= 0 && runDisplay < devices.length) {
          runDevice = devices[runDisplay];
        } else {
          runDevice = editorDevice;
          for (int i = 0; i < devices.length; i++) {
            if (devices[i] == runDevice) {
              runDisplay = i;
              break;
              // Don't set the pref, might be a temporary thing. Users can
              // open/close Preferences to reset the device themselves.
              //              Preferences.setInteger("run.display", runDisplay);
            }
          }
        }

        Point windowLocation = editor.getSketchLocation();
        //        if (windowLocation != null) {
        //          // could check to make sure the sketch location is on the device
        //          // that's specified in Preferences, but that's going to be annoying
        //          // if you move a sketch to another window, then it keeps jumping
        //          // back to the specified window.
        ////          Rectangle screenRect =
        ////            runDevice.getDefaultConfiguration().getBounds();
        //        }
        if (windowLocation == null) {
          if (editorDevice == runDevice) {
            // If sketches are to be shown on the same display as the editor,
            // provide the editor location so the sketch's main() can place it.
            Point editorLocation = editor.getLocation();
            params.add(
                PApplet.ARGS_EDITOR_LOCATION + "=" + editorLocation.x + "," + editorLocation.y);
          } else {
            // The sketch's main() will set a location centered on the new
            // display. It has to happen in main() because the width/height
            // of the sketch are not known here.
            //             Set a location centered on the other display
            //            Rectangle screenRect =
            //              runDevice.getDefaultConfiguration().getBounds();
            //            int runX =
            //            params.add(PApplet.ARGS_LOCATION + "=" + runX + "," + runY);
          }
        } else {
          params.add(PApplet.ARGS_LOCATION + "=" + windowLocation.x + "," + windowLocation.y);
        }
        params.add(PApplet.ARGS_EXTERNAL);
      }

      params.add(PApplet.ARGS_DISPLAY + "=" + runDisplay);

      if (presenting) {
        params.add(PApplet.ARGS_FULL_SCREEN);
        //        if (Preferences.getBoolean("run.present.exclusive")) {
        //          params.add(PApplet.ARGS_EXCLUSIVE);
        //        }
        params.add(PApplet.ARGS_STOP_COLOR + "=" + Preferences.get("run.present.stop.color"));
        params.add(PApplet.ARGS_BGCOLOR + "=" + Preferences.get("run.present.bgcolor"));
      }

      params.add(build.getSketchClassName());
      params.add(PApplet.ARGS_SKETCH_FOLDER + "=" + build.getSketchPath());
      // Adding sketch path in the end coz it's likely to
      // contain spaces and things go wrong on UNIX systems.
    }

    //    String outgoing[] = new String[params.size()];
    //    params.toArray(outgoing);
    //    return outgoing;
    return params.toArray(new String[0]);
  }
Exemplo n.º 7
0
  protected String[] getMachineParams() {
    ArrayList<String> params = new ArrayList<String>();

    // params.add("-Xint"); // interpreted mode
    // params.add("-Xprof");  // profiler
    // params.add("-Xaprof");  // allocation profiler
    // params.add("-Xrunhprof:cpu=samples");  // old-style profiler

    // TODO change this to use run.args = true, run.args.0, run.args.1, etc.
    // so that spaces can be included in the arg names
    String options = Preferences.get("run.options");
    if (options.length() > 0) {
      String pieces[] = PApplet.split(options, ' ');
      for (int i = 0; i < pieces.length; i++) {
        String p = pieces[i].trim();
        if (p.length() > 0) {
          params.add(p);
        }
      }
    }

    //    params.add("-Djava.ext.dirs=nuffing");

    if (Preferences.getBoolean("run.options.memory")) {
      params.add("-Xms" + Preferences.get("run.options.memory.initial") + "m");
      params.add("-Xmx" + Preferences.get("run.options.memory.maximum") + "m");
    }

    if (Base.isMacOS()) {
      params.add("-Xdock:name=" + build.getSketchClassName());
      //      params.add("-Dcom.apple.mrj.application.apple.menu.about.name=" +
      //                 sketch.getMainClassName());
    }
    // sketch.libraryPath might be ""
    // librariesClassPath will always have sep char prepended
    params.add(
        "-Djava.library.path="
            + build.getJavaLibraryPath()
            + File.pathSeparator
            + System.getProperty("java.library.path"));

    params.add("-cp");
    params.add(build.getClassPath());
    //    params.add(sketch.getClassPath() +
    //        File.pathSeparator +
    //        Base.librariesClassPath);

    // enable assertions
    // http://dev.processing.org/bugs/show_bug.cgi?id=1188
    params.add("-ea");
    // PApplet.println(PApplet.split(sketch.classPath, ':'));

    String outgoing[] = new String[params.size()];
    params.toArray(outgoing);

    //    PApplet.println(outgoing);
    //    PApplet.println(PApplet.split(outgoing[0], ":"));
    //    PApplet.println();
    //    PApplet.println("class path");
    //    PApplet.println(PApplet.split(outgoing[2], ":"));

    return outgoing;
    // return (String[]) params.toArray();

    //  System.out.println("sketch class path");
    //  PApplet.println(PApplet.split(sketch.classPath, ';'));
    //  System.out.println();
    //  System.out.println("libraries class path");
    //  PApplet.println(PApplet.split(Base.librariesClassPath, ';'));
    //  System.out.println();
  }
  protected boolean burnBootloader(Collection params) throws RunnerException {
    List fuses = new ArrayList();
    fuses.add("-e"); // erase the chip
    fuses.add(
        "-Ulock:w:"
            + Preferences.get("boards." + Preferences.get("board") + ".bootloader.unlock_bits")
            + ":m");
    if (Preferences.get("boards." + Preferences.get("board") + ".bootloader.extended_fuses")
        != null)
      fuses.add(
          "-Uefuse:w:"
              + Preferences.get("boards." + Preferences.get("board") + ".bootloader.extended_fuses")
              + ":m");
    fuses.add(
        "-Uhfuse:w:"
            + Preferences.get("boards." + Preferences.get("board") + ".bootloader.high_fuses")
            + ":m");
    fuses.add(
        "-Ulfuse:w:"
            + Preferences.get("boards." + Preferences.get("board") + ".bootloader.low_fuses")
            + ":m");

    if (!avrdude(params, fuses)) return false;

    List bootloader = new ArrayList();
    bootloader.add(
        "-Uflash:w:"
            + "hardware"
            + File.separator
            + "bootloaders"
            + File.separator
            + Preferences.get("boards." + Preferences.get("board") + ".bootloader.path")
            + File.separator
            + Preferences.get("boards." + Preferences.get("board") + ".bootloader.file")
            + ":i");
    bootloader.add(
        "-Ulock:w:"
            + Preferences.get("boards." + Preferences.get("board") + ".bootloader.lock_bits")
            + ":m");

    return avrdude(params, bootloader);
  }
Exemplo n.º 9
0
  protected String[] getSketchParams(boolean presenting) {
    ArrayList<String> params = new ArrayList<String>();

    // It's dangerous to add your own main() to your code,
    // but if you've done it, we'll respect your right to hang yourself.
    // http://processing.org/bugs/bugzilla/1446.html
    if (build.getFoundMain()) {
      params.add(build.getSketchClassName());

    } else {
      params.add("processing.core.PApplet");

      // get the stored device index (starts at 1)
      int runDisplay = Preferences.getInteger("run.display");

      // If there was a saved location (this guy has been run more than once)
      // then the location will be set to the last position of the sketch window.
      // This will be passed to the PApplet runner using something like
      // --location=30,20
      // Otherwise, the editor location will be passed, and the applet will
      // figure out where to place itself based on the editor location.
      // --editor-location=150,20
      if (editor != null) { // if running processing-cmd, don't do placement
        GraphicsDevice editorDevice = editor.getGraphicsConfiguration().getDevice();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = ge.getScreenDevices();

        // Make sure the display set in Preferences actually exists
        GraphicsDevice runDevice = editorDevice;
        if (runDisplay > 0 && runDisplay <= devices.length) {
          runDevice = devices[runDisplay - 1];
        } else {
          // If a bad display is selected, use the same display as the editor
          if (runDisplay > 0) { // don't complain about -1 or 0
            System.err.println("Display " + runDisplay + " not available.");
          }
          runDevice = editorDevice;
          for (int i = 0; i < devices.length; i++) {
            if (devices[i] == runDevice) {
              // Wasn't setting the pref to avoid screwing things up with
              // something temporary. But not setting it makes debugging one's
              // setup just too damn weird, so changing that behavior.
              runDisplay = i + 1;
              System.err.println(
                  "Setting 'Run Sketches on Display' preference to display " + runDisplay);
              Preferences.setInteger("run.display", runDisplay);
              break;
            }
          }
        }

        Point windowLocation = editor.getSketchLocation();
        //        if (windowLocation != null) {
        //          // could check to make sure the sketch location is on the device
        //          // that's specified in Preferences, but that's going to be annoying
        //          // if you move a sketch to another window, then it keeps jumping
        //          // back to the specified window.
        ////          Rectangle screenRect =
        ////            runDevice.getDefaultConfiguration().getBounds();
        //        }
        if (windowLocation == null) {
          if (editorDevice == runDevice) {
            // If sketches are to be shown on the same display as the editor,
            // provide the editor location so the sketch's main() can place it.
            Point editorLocation = editor.getLocation();
            params.add(
                PApplet.ARGS_EDITOR_LOCATION + "=" + editorLocation.x + "," + editorLocation.y);
          } else {
            // The sketch's main() will set a location centered on the new
            // display. It has to happen in main() because the width/height
            // of the sketch are not known here.
            //             Set a location centered on the other display
            //            Rectangle screenRect =
            //              runDevice.getDefaultConfiguration().getBounds();
            //            int runX =
            //            params.add(PApplet.ARGS_LOCATION + "=" + runX + "," + runY);
          }
        } else {
          params.add(PApplet.ARGS_LOCATION + "=" + windowLocation.x + "," + windowLocation.y);
        }
        params.add(PApplet.ARGS_EXTERNAL);
      }

      params.add(PApplet.ARGS_DISPLAY + "=" + runDisplay);

      if (presenting) {
        params.add(PApplet.ARGS_PRESENT);
        //        if (Preferences.getBoolean("run.present.exclusive")) {
        //          params.add(PApplet.ARGS_EXCLUSIVE);
        //        }
        params.add(PApplet.ARGS_STOP_COLOR + "=" + Preferences.get("run.present.stop.color"));
        params.add(PApplet.ARGS_WINDOW_COLOR + "=" + Preferences.get("run.present.bgcolor"));
      }

      // There was a PDE X hack that put this after the class name, but it was
      // removed for 3.0a6 because it would break the args passed to sketches.
      params.add(PApplet.ARGS_SKETCH_FOLDER + "=" + build.getSketchPath());

      params.add(build.getSketchClassName());
    }

    //    String outgoing[] = new String[params.size()];
    //    params.toArray(outgoing);
    //    return outgoing;
    return params.toArray(new String[0]);
  }