Now appending main() to the user's sketch in preparation for making the Arduino core a library (.a) file.

This commit is contained in:
David A. Mellis 2007-01-12 17:58:39 +00:00
parent 2e1776862e
commit 41d50ae572
5 changed files with 37 additions and 26 deletions

View File

@ -1451,7 +1451,7 @@ public class Sketch {
// java mode, since that's required // java mode, since that's required
String className = String className =
preprocessor.write(bigCode.toString(), buildPath, preprocessor.write(bigCode.toString(), buildPath,
suggestedClassName, codeFolderPackages); suggestedClassName, codeFolderPackages, target);
if (className == null) { if (className == null) {
throw new RunnerException("Could not find main class"); throw new RunnerException("Could not find main class");
// this situation might be perfectly fine, // this situation might be perfectly fine,

View File

@ -104,7 +104,8 @@ public class PdePreprocessor {
//public String write(String program, String buildPath, String name, //public String write(String program, String buildPath, String name,
// String extraImports[]) throws java.lang.Exception { // String extraImports[]) throws java.lang.Exception {
public String write(String program, String buildPath, public String write(String program, String buildPath,
String name, String codeFolderPackages[]) String name, String codeFolderPackages[],
Target target)
throws java.lang.Exception { throws java.lang.Exception {
// if the program ends with no CR or LF an OutOfMemoryError will happen. // if the program ends with no CR or LF an OutOfMemoryError will happen.
// not gonna track down the bug now, so here's a hack for it: // not gonna track down the bug now, so here's a hack for it:
@ -344,7 +345,7 @@ public class PdePreprocessor {
//emitter.print(rootNode); //emitter.print(rootNode);
//emitter.translationUnit(parser.getAST()); //emitter.translationUnit(parser.getAST());
writeFooter(stream); writeFooter(stream, target);
stream.close(); stream.close();
// if desired, serialize the parse tree to an XML file. can // if desired, serialize the parse tree to an XML file. can
@ -457,20 +458,23 @@ public class PdePreprocessor {
* *
* @param out PrintStream to write it to. * @param out PrintStream to write it to.
*/ */
void writeFooter(PrintStream out) { void writeFooter(PrintStream out, Target target) throws java.lang.Exception {
//out.print("}"); // Open the file main.cxx and copy its entire contents to the bottom of the
// generated sketch .cpp file...
/* if (programType == STATIC) { String mainFileName = target.getPath() + File.separator + "main.cxx";
// close off draw() definition FileReader reader = null;
out.print("noLoop(); "); reader = new FileReader(mainFileName);
out.print("}");
LineNumberReader mainfile = new LineNumberReader(reader);
String line;
while ((line = mainfile.readLine()) != null) {
out.print(line + "\n");
} }
if (programType < JAVA) { mainfile.close();
// close off the class definition }
out.print("}");
}
*/ }
static String advClassName = ""; static String advClassName = "";

12
targets/arduino/main.cxx Executable file
View File

@ -0,0 +1,12 @@
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}

View File

@ -549,7 +549,7 @@ void shiftOut(int dataPin, int clockPin, int bitOrder, byte val) {
} }
} }
int main(void) void init()
{ {
// this needs to be called before setup() or some functions won't // this needs to be called before setup() or some functions won't
// work there // work there
@ -626,11 +626,4 @@ int main(void)
#else #else
UCSRB = 0; UCSRB = 0;
#endif #endif
}
setup();
for (;;)
loop();
return 0;
}

View File

@ -66,6 +66,8 @@ extern "C"{
typedef uint8_t boolean; typedef uint8_t boolean;
typedef uint8_t byte; typedef uint8_t byte;
void init(void);
void pinMode(int, int); void pinMode(int, int);
void digitalWrite(int, int); void digitalWrite(int, int);
int digitalRead(int); int digitalRead(int);
@ -74,9 +76,9 @@ void analogWrite(int, int);
void beginSerial(long); void beginSerial(long);
void serialWrite(unsigned char); void serialWrite(unsigned char);
int serialAvailable(); int serialAvailable(void);
int serialRead(); int serialRead(void);
void serialFlush(); void serialFlush(void);
void printMode(int); void printMode(int);
void printByte(unsigned char c); void printByte(unsigned char c);
void printNewline(); void printNewline();