/** * Add a zone to the zone picker. * * @param zone the zone to enable picking on. */ public void add(Zone zone) { // check if we already have this zone if (zoneMap.containsValue(zone)) return; if (zoneMap.size() == POSSIBLE_COLORS) { // We've run out of pick colours :( oh no System.err.printf( "The number of zones has exceeded the maximum number of pickable zones (%d). This recently added zone (%s) will not be pickable.", POSSIBLE_COLORS, zone); return; } // get a new colour zone.setPickColor(new Color(currentColor, false)); int pixelColor = 0xff + (currentColor << 8); zoneMap.put(pixelColor, zone); // dont bother searching if we're out of colours anyways if (zoneMap.size() < POSSIBLE_COLORS) { while (zoneMap.containsKey(pixelColor)) { currentColor += 1; pixelColor = 0xff + (currentColor << 8); } } // add all of the zone's child zones for (Zone child : zone.getChildren()) this.add(child); }
static private List getCommandCompilerCPP(String avrBasePath, List includePaths, String sourceName, String objectName, Map<String, String> boardPreferences) { List baseCommandCompilerCPP = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-g++", "-c", // compile, don't link "-g", // include debugging info (so errors include line numbers) "-Os", // optimize for size Preferences.getBoolean("build.verbose") ? "-Wall" : "-w", // show warnings if verbose "-fno-exceptions", "-ffunction-sections", // place each function in its own section "-fdata-sections", "-mmcu=" + boardPreferences.get("build.mcu"), "-DF_CPU=" + boardPreferences.get("build.f_cpu"), "-MMD", // output dependancy info "-DUSB_VID=" + boardPreferences.get("build.vid"), "-DUSB_PID=" + boardPreferences.get("build.pid"), "-DARDUINO=" + Base.REVISION, })); for (int i = 0; i < includePaths.size(); i++) { baseCommandCompilerCPP.add("-I" + (String) includePaths.get(i)); } baseCommandCompilerCPP.add(sourceName); baseCommandCompilerCPP.add("-o"); baseCommandCompilerCPP.add(objectName); return baseCommandCompilerCPP; }
/** * Get the Zone under the specified coordinates. * * @param x x coordinate of the specified pixel * @param y y coordinate of the specified pixel * @return If there is a Zone at the specified coordinates, that zone, otherwise null. */ public Zone pick(int x, int y) { // clamp x and y if (y >= picking_context.height) y = picking_context.height - 1; if (x >= picking_context.width) x = picking_context.width - 1; if (y < 0) y = 0; if (x < 0) x = 0; PGL pgl = picking_context.beginPGL(); int pixel; // force fallback until 2.0b10 if (!SMT.fastPickingEnabled() || pgl == null) { // really slow way(max 70 fps on a high end card vs 200+ fps with readPixels), with loadPixels // at the end of render() pixel = picking_context.pixels[x + y * picking_context.width]; } else { buffer.clear(); pgl.readPixels(x, picking_context.height - y, 1, 1, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buffer); pixel = buffer.getInt(); } picking_context.endPGL(); if (zoneMap.containsKey(pixel)) { // if mapped it is either a Zone or null (background) Zone picked = zoneMap.get(pixel); Zone current = picked; while (current != null) { if (current.stealChildrensTouch) return current; current = current.getParent(); } return picked; } else return null; }
/** * Remove the specified zone from the zone picker * * @param zone the zone to remove * @return The zone that was removed */ public Zone remove(Zone zone) { Color color = zone.getPickColor(); int pixelColor = color.getAlpha() + (color.getRGB() << 8); Zone removed = zoneMap.remove(pixelColor); zone.setPickColor(null); return removed; }
static private List getCommandCompilerS(String avrBasePath, List includePaths, String sourceName, String objectName, Map<String, String> boardPreferences) { List baseCommandCompiler = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-gcc", "-c", // compile, don't link "-g", // include debugging info (so errors include line numbers) "-assembler-with-cpp", "-mmcu=" + boardPreferences.get("build.mcu"), "-DF_CPU=" + boardPreferences.get("build.f_cpu"), "-DARDUINO=" + Base.REVISION, "-DUSB_VID=" + boardPreferences.get("build.vid"), "-DUSB_PID=" + boardPreferences.get("build.pid"), })); for (int i = 0; i < includePaths.size(); i++) { baseCommandCompiler.add("-I" + (String) includePaths.get(i)); } baseCommandCompiler.add(sourceName); baseCommandCompiler.add("-o"+ objectName); return baseCommandCompiler; }
public boolean launchVirtualMachine(boolean presenting) { String[] vmParams = getMachineParams(); String[] sketchParams = getSketchParams(presenting); int port = 8000 + (int) (Math.random() * 1000); String portStr = String.valueOf(port); // Older (Java 1.5 and earlier) version, go figure // String jdwpArg = "-Xrunjdwp:transport=dt_socket,address=" + portStr + // ",server=y,suspend=y"; // String debugArg = "-Xdebug"; // Newer (Java 1.5+) version that uses JVMTI String jdwpArg = "-agentlib:jdwp=transport=dt_socket,address=" + portStr + ",server=y,suspend=y"; // Everyone works the same under Java 7 (also on OS X) String[] commandArgs = new String[] {Base.getJavaPath(), jdwpArg}; /* String[] commandArgs = null; if (!Base.isMacOS()) { commandArgs = new String[] { Base.getJavaPath(), jdwpArg }; } else { // Decided to just set this to 1.6 only, because otherwise it's gonna // be a shitshow if folks are getting Apple's 1.6 with 32-bit and // Oracle's 1.7 when run in 64-bit mode. ("Why does my sketch suck in // 64-bit? Why is retina broken?) // The --request flag will prompt to install Apple's 1.6 JVM if none is // available. We're specifying 1.6 so that we can get support for both // 32- and 64-bit, because Oracle won't be releasing Java 1.7 in 32-bit. // Helpfully, the --request flag is not present on Mac OS X 10.6 // (luckily it is also not needed, because 1.6 is installed by default) // but it requires an additional workaround to not use that flag, // otherwise will see an error about an unsupported option. The flag is // available with 10.7 and 10.8, the only other supported versions of // OS X at this point, because we require 10.6.8 and higher. That also // means we don't need to check for any other OS versions, the user is // a douchebag and modifies Info.plist to get around the restriction. if (false) { if (System.getProperty("os.version").startsWith("10.6")) { commandArgs = new String[] { "/usr/libexec/java_home", "--version", "1.6", "--exec", "java", "-d" + Base.getNativeBits(), jdwpArg }; } else { // for 10.7, 10.8, etc commandArgs = new String[] { "/usr/libexec/java_home", "--request", // install on-demand "--version", "1.6", "--exec", "java", "-d" + Base.getNativeBits(), // debugArg, jdwpArg }; } } else { // testing jdk-7u40 commandArgs = new String[] { //"/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/java", Base.getJavaPath(), jdwpArg }; } } */ commandArgs = PApplet.concat(commandArgs, vmParams); commandArgs = PApplet.concat(commandArgs, sketchParams); // PApplet.println(commandArgs); // commandArg.setValue(commandArgs); launchJava(commandArgs); AttachingConnector connector = (AttachingConnector) findConnector("com.sun.jdi.SocketAttach"); // PApplet.println(connector); // gets the defaults Map arguments = connector.defaultArguments(); // Connector.Argument addressArg = // (Connector.Argument)arguments.get("address"); // addressArg.setValue(addr); Connector.Argument portArg = (Connector.Argument) arguments.get("port"); portArg.setValue(portStr); // Connector.Argument timeoutArg = // (Connector.Argument)arguments.get("timeout"); // timeoutArg.setValue("10000"); // PApplet.println(connector); // prints the current // com.sun.tools.jdi.AbstractLauncher al; // com.sun.tools.jdi.RawCommandLineLauncher rcll; // System.out.println(PApplet.javaVersion); // http://java.sun.com/j2se/1.5.0/docs/guide/jpda/conninv.html#sunlaunch try { // boolean available = false; // while (!available) { while (true) { try { vm = connector.attach(arguments); // vm = connector.attach(arguments); if (vm != null) { // generateTrace(); // available = true; return true; } } catch (IOException e) { // System.out.println("waiting"); // e.printStackTrace(); try { Thread.sleep(100); } catch (InterruptedException e1) { e1.printStackTrace(); } } } // } catch (IOException exc) { // throw new Error("Unable to launch target VM: " + exc); } catch (IllegalConnectorArgumentsException exc) { throw new Error("Internal error: " + exc); } }
/** * Compile with avr-gcc. * * @param sketch Sketch object to be compiled. * @param buildPath Where the temporary files live and will be built from. * @param primaryClassName the name of the combined sketch file w/ extension * @return true if successful. * @throws RunnerException Only if there's a problem. Only then. * * [ROBOTIS]Changed prototype to support ARM Cortex-M3 based CM-900 Pandora project * 2012-09-26 [email protected] * */ public boolean compile(Sketch sketch, //change return type[ROBOTIS] String buildPath, String primaryClassName, boolean verbose, List<String> ignored) throws RunnerException { this.sketch = sketch; this.buildPath = buildPath; this.primaryClassName = primaryClassName; //예를 들면 cpp파일로 변환된 AnalogReadSerial.cpp this.verbose = verbose; this.sketchIsCompiled = false; System.out.println("Compiler.compile() sketch ="+sketch.getName()+"buildpath ="+buildPath+"primaryClassName ="+primaryClassName); // the pms object isn't used for anything but storage MessageStream pms = new MessageStream(this); String avrBasePath = Base.getAvrBasePath(); System.out.println("[ROBOTIS]avrBasePath ="+avrBasePath); Map<String, String> boardPreferences = Base.getBoardPreferences(); String core = boardPreferences.get("build.core"); System.out.println("[ROBOTIS]build.core ="+core); if (core == null) { RunnerException re = new RunnerException(_("No board selected; please choose a board from the Tools > Board menu.")); re.hideStackTrace(); throw re; } String corePath; if (core.indexOf(':') == -1) { Target t = Base.getTarget(); File coreFolder = new File(new File(t.getFolder(), "cores"), core); corePath = coreFolder.getAbsolutePath(); } else { Target t = Base.targetsTable.get(core.substring(0, core.indexOf(':'))); File coreFolder = new File(t.getFolder(), "cores"); coreFolder = new File(coreFolder, core.substring(core.indexOf(':') + 1)); corePath = coreFolder.getAbsolutePath(); } System.out.println("[ROBOTIS]corePath ="+corePath); String variant = boardPreferences.get("build.variant"); String variantPath = null; if (variant != null) { if (variant.indexOf(':') == -1) { Target t = Base.getTarget(); File variantFolder = new File(new File(t.getFolder(), "variants"), variant); variantPath = variantFolder.getAbsolutePath(); } else { Target t = Base.targetsTable.get(variant.substring(0, variant.indexOf(':'))); File variantFolder = new File(t.getFolder(), "variants"); variantFolder = new File(variantFolder, variant.substring(variant.indexOf(':') + 1)); variantPath = variantFolder.getAbsolutePath(); } } List<File> objectFiles = new ArrayList<File>(); // 0. include paths for core + all libraries sketch.setCompilingProgress(20); List includePaths = new ArrayList(); includePaths.add(corePath); if (variantPath != null) includePaths.add(variantPath); for (File file : sketch.getImportedLibraries()) { includePaths.add(file.getPath()); } // 1. compile the sketch (already in the buildPath) sketch.setCompilingProgress(30); objectFiles.addAll( compileFiles(avrBasePath, buildPath, includePaths, findFilesInPath(buildPath, "S", false), findFilesInPath(buildPath, "c", false), findFilesInPath(buildPath, "cpp", false), boardPreferences)); sketchIsCompiled = true; // 2. compile the libraries, outputting .o files to: <buildPath>/<library>/ sketch.setCompilingProgress(40); for (File libraryFolder : sketch.getImportedLibraries()) { File outputFolder = new File(buildPath, libraryFolder.getName()); File utilityFolder = new File(libraryFolder, "utility"); createFolder(outputFolder); // this library can use includes in its utility/ folder includePaths.add(utilityFolder.getAbsolutePath()); objectFiles.addAll( compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths, findFilesInFolder(libraryFolder, "S", false), findFilesInFolder(libraryFolder, "c", false), findFilesInFolder(libraryFolder, "cpp", false), boardPreferences)); outputFolder = new File(outputFolder, "utility"); createFolder(outputFolder); objectFiles.addAll( compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths, findFilesInFolder(utilityFolder, "S", false), findFilesInFolder(utilityFolder, "c", false), findFilesInFolder(utilityFolder, "cpp", false), boardPreferences)); // other libraries should not see this library's utility/ folder includePaths.remove(includePaths.size() - 1); } // 3. compile the core, outputting .o files to <buildPath> and then // collecting them into the core.a library file. sketch.setCompilingProgress(50); includePaths.clear(); includePaths.add(corePath); // include path for core only if (variantPath != null) includePaths.add(variantPath); List<File> coreObjectFiles = compileFiles(avrBasePath, buildPath, includePaths, findFilesInPath(corePath, "S", true), findFilesInPath(corePath, "c", true), findFilesInPath(corePath, "cpp", true), boardPreferences); String runtimeLibraryName = buildPath + File.separator + "core.a"; List baseCommandAR = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-ar", "rcs", runtimeLibraryName })); for(File file : coreObjectFiles) { List commandAR = new ArrayList(baseCommandAR); commandAR.add(file.getAbsolutePath()); execAsynchronously(commandAR); } // 4. link it all together into the .elf file // For atmega2560, need --relax linker option to link larger // programs correctly. String optRelax = ""; String atmega2560 = new String ("atmega2560"); if ( atmega2560.equals(boardPreferences.get("build.mcu")) ) { optRelax = new String(",--relax"); } sketch.setCompilingProgress(60); List baseCommandLinker = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-gcc", "-Os", "-Wl,--gc-sections"+optRelax, "-mmcu=" + boardPreferences.get("build.mcu"), "-o", buildPath + File.separator + primaryClassName + ".elf" })); for (File file : objectFiles) { baseCommandLinker.add(file.getAbsolutePath()); } baseCommandLinker.add(runtimeLibraryName); baseCommandLinker.add("-L" + buildPath); baseCommandLinker.add("-lm"); execAsynchronously(baseCommandLinker); List baseCommandObjcopy = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-objcopy", "-O", "-R", })); List commandObjcopy; // 5. extract EEPROM data (from EEMEM directive) to .eep file. sketch.setCompilingProgress(70); commandObjcopy = new ArrayList(baseCommandObjcopy); commandObjcopy.add(2, "ihex"); commandObjcopy.set(3, "-j"); commandObjcopy.add(".eeprom"); commandObjcopy.add("--set-section-flags=.eeprom=alloc,load"); commandObjcopy.add("--no-change-warnings"); commandObjcopy.add("--change-section-lma"); commandObjcopy.add(".eeprom=0"); commandObjcopy.add(buildPath + File.separator + primaryClassName + ".elf"); commandObjcopy.add(buildPath + File.separator + primaryClassName + ".eep"); execAsynchronously(commandObjcopy); // 6. build the .hex file sketch.setCompilingProgress(80); commandObjcopy = new ArrayList(baseCommandObjcopy); commandObjcopy.add(2, "ihex"); commandObjcopy.add(".eeprom"); // remove eeprom data commandObjcopy.add(buildPath + File.separator + primaryClassName + ".elf"); commandObjcopy.add(buildPath + File.separator + primaryClassName + ".hex"); execAsynchronously(commandObjcopy); sketch.setCompilingProgress(90); return true; }
public boolean launchVirtualMachine(boolean presenting) { String[] vmParams = getMachineParams(); String[] sketchParams = getSketchParams(presenting); // PApplet.printArray(sketchParams); int port = 8000 + (int) (Math.random() * 1000); String portStr = String.valueOf(port); // Older (Java 1.5 and earlier) version, go figure // String jdwpArg = "-Xrunjdwp:transport=dt_socket,address=" + portStr + // ",server=y,suspend=y"; // String debugArg = "-Xdebug"; // Newer (Java 1.5+) version that uses JVMTI String jdwpArg = "-agentlib:jdwp=transport=dt_socket,address=" + portStr + ",server=y,suspend=y"; // Everyone works the same under Java 7 (also on OS X) String[] commandArgs = new String[] {Base.getJavaPath(), jdwpArg}; commandArgs = PApplet.concat(commandArgs, vmParams); commandArgs = PApplet.concat(commandArgs, sketchParams); // PApplet.println(commandArgs); // commandArg.setValue(commandArgs); launchJava(commandArgs); AttachingConnector connector = (AttachingConnector) findConnector("com.sun.jdi.SocketAttach"); // PApplet.println(connector); // gets the defaults Map<String, Argument> arguments = connector.defaultArguments(); // Connector.Argument addressArg = // (Connector.Argument)arguments.get("address"); // addressArg.setValue(addr); Connector.Argument portArg = arguments.get("port"); portArg.setValue(portStr); // Connector.Argument timeoutArg = // (Connector.Argument)arguments.get("timeout"); // timeoutArg.setValue("10000"); // PApplet.println(connector); // prints the current // com.sun.tools.jdi.AbstractLauncher al; // com.sun.tools.jdi.RawCommandLineLauncher rcll; // System.out.println(PApplet.javaVersion); // http://java.sun.com/j2se/1.5.0/docs/guide/jpda/conninv.html#sunlaunch try { // boolean available = false; // while (!available) { while (true) { try { vm = connector.attach(arguments); // vm = connector.attach(arguments); if (vm != null) { // generateTrace(); // available = true; return true; } } catch (IOException e) { // System.out.println("waiting"); // e.printStackTrace(); try { Thread.sleep(100); } catch (InterruptedException e1) { e1.printStackTrace(sketchErr); } } } // } catch (IOException exc) { // throw new Error("Unable to launch target VM: " + exc); } catch (IllegalConnectorArgumentsException exc) { throw new Error("Internal error: " + exc); } }
/** * Check whether this zone picker has already registered a zone * * @param zone a zone * @return whether the specified zone has already been added to the zone picker */ public boolean contains(Zone zone) { return zoneMap.containsValue(zone); }