Show Posts
Pages: [1]
1  Development / Suggestions for the Arduino Project / Re: Sketch name as PreProcessor value? on: August 17, 2012, 10:14:13 am
Good idea about the sticker  smiley

Yes, revision control is a lot of it. Also, as a hobbyist, I currently have only one Arduino. So, if I "borrow" it from one project, tinker, then want to put it back the way it was, that is why it would be nice to have it echo back the sketch name before I re-upload an alternate sketch. But, yeah, I'd already be connected and in the IDE.


So - given the numerous ways this could be accomplished, both efficiently and inefficiently, I return to my original idea of there being an "easy" way to include the sketch name.

It would be great if the functionality were something like a reserved word that the Arduino IDE uses, so the IDE handles any filename or path manipulation, and then simply injects the sketch name into the sketch as if it were hand typed by the developer. That way, the IDE does the work, and the sketch is only bloated by 30 or so bytes to contain the sketch name. I don't think there is a dynamic (programatic) way to do the same task in less space than that. (And yes, the concept would possibly break in alternate IDE like XCode or Eclipse)

Thanks to everyone for your input. This is great stuff.
2  Development / Suggestions for the Arduino Project / Re: Sketch name as PreProcessor value? on: August 15, 2012, 09:37:42 am
Thanks again AWOL for the tip.

I threw together this little function to display what I need. Maybe someone else will find it helpful as well.

Code:
// displays at startup the Sketch running in the Arduino
void display_Running_Sketch (void){
  String the_path = __FILE__;
  int slash_loc = the_path.lastIndexOf('/');
  String the_cpp_name = the_path.substring(slash_loc+1);
  int dot_loc = the_cpp_name.lastIndexOf('.');
  String the_sketchname = the_cpp_name.substring(0, dot_loc);

  Serial.print("\nArduino is running Sketch: ");
  Serial.println(the_sketchname);
  Serial.print("Compiled on: ");
  Serial.print(__DATE__);
  Serial.print(" at ");
  Serial.print(__TIME__);
  Serial.print("\n");
}

I call it like this in setup()

Code:
void setup() {     
  Serial.begin(9600);
  display_Running_Sketch();
}


My output in the Serial Monitor looks like this:

Arduino is running Sketch: MyTestSketch_ver_2
Compiled on: Aug 15 2012 at 09:36:27


(It could, of course, be used without the function, just copy/paste directly into setup() )
3  Development / Suggestions for the Arduino Project / Re: Sketch name as PreProcessor value? on: August 15, 2012, 07:06:41 am
Thanks, I'll give that a try.

Where could I find a list of available macros or predefined "defines" like that? I'm not very familiar with the use of the compiler flags, settings, or (clearly) available variables.

Thanks!

4  Development / Suggestions for the Arduino Project / Sketch name as PreProcessor value? on: August 14, 2012, 09:52:11 pm
Hi,
   I've found that once I upload code into my Arduino, and run it for days, weeks, months, I usually forget what the name of the running sketch is.
Would it be possible to add a few pre-precessor reserved words, something like the #defines (all caps below) to allow us to have the sketch name and modification timestamp auto-inserted at compile time?

If I were to include in the setup() code something like:

Serial.print("You are running sketch: ");
Serial.print( THIS_SKETCH_NAME );
Serial.print(" modified: ");
Serial.println( THIS_SKETCH_TIMESTAMP );

Then I could take my Arduino offline, plug it into USB, hit the reset button, check the serial monitor, and have it tell me the name of the sketch it's running!

I do the same thing right now by manually entering that information, but it would be cool to have it auto-fill.

Maybe this is already possible?

Thanks for reading!
J


Pages: [1]