Go Down

Topic: __FILE__ string uses alot of ram? Can I move that data into the internal eeprom? (Read 144 times) previous topic - next topic

EKMallon

I've been recording the name of the compiled script using the __FILE__ string with code from this thread:

https://forum.arduino.cc/index.php?topic=359468.0


Code: [Select]
  char u[] =__FILE__; //contains entire path name in addition to file name!
  byte b = sizeof(u);
  while ((b > 0)&&(u[b]!= '\\'))b--;
  char *codebuild = &u[++b];
  file.println(codebuild);


but that gobbles up a huge amount of dynamic memory, and even the pared down 'codebuild' char string varies in size quite a bit.

So I was wondering if there was any simple way to store that variable length string in the internal eeprom in setup, and then retrieve it later on in the program when I'm printing data file headers?

Delta_G

You could put it in progmem just like any other string constant. 
If at first you don't succeed, up - home - sudo - enter.

EKMallon

Because I have yet to find a PROGMEM tutorial that I can understand. Even Nick's page : http://www.gammon.com.au/progmem left me in the dust, and his stuff is usually my first go-to.


And in this case, I have no idea what the whole string length is, and all I want to store is the actual file name (it the stuff at the end pointed at by *codebuild)

By comparison, putting stuff in eeproms & then retrieving it seems much easier.
(And I want to start using the internal eeprom for other data as well with things like Unit# and some longer sensor calibration constants - then I could just copy the entire 512 bytes to the header files on the SD cards without using any other memory resources)

Delta_G

If you want to put it in EEPROM, then it will have to be done by the sketch.  You can't use a separate sketch because it would put the wrong file name. 

If you have to put it in EEPROM from the sketch, then you'll have to have the string constant in the sketch.  And it will use all the same memory that it did when you weren't putting it in EEPROM.  So there's nothing to gain there. 

Looks like it is time to learn PROGMEM.  "I don't understand it" is a bullshit statement.  Nobody can help you from that.  Talk about what exactly you didn't understand or what part confused you and maybe someone could help. 
If at first you don't succeed, up - home - sudo - enter.

EKMallon

The problem is I often run into places where several concepts that are new to me come into conflict at the same time, and I get lost in the syntax.

So using the example I posted here, where I get stuck is:


Code: [Select]
//at beginning of script
const char codebuild[] PROGMEM =__FILE__; //the compile filename & path

//just before printing the headers
byte b = strlen_P(codebuild);  // https://forum.arduino.cc/index.php?topic=359468.0 
while ((b > 0)&&(pgm_read_byte_near(codebuild[b])!= '\\'))b--;
char *filenameonly = &codebuild[++b];  // this line fails @ compile

file.print(F("CodeBuild:,"));file.println(filenameonly);



char *filenameonly = &codebuild[++b]; generates an error:
invalid conversion from 'const char*' to 'char*' [-fpermissive]

but I thought that  char *filenameonly was just a pointer rather than a variable, so what is being converted?  I'm sure I will figure out where my mistake is eventually, but for now this is still hard for me to follow.

---

And I'd still like to store calibration constants in the internal eeprom, because the whole point would be putting those very large numbers (eg: thermistor coefficients) somewhere that is persistent through the lifetime of a datalogger, independent of which code is running at any given time. If I could copy just the file name from PROGMEM stored __FILE__ to that same eeprom space, then the routine to flush the eeprom to the SD card would be a simple read & save loop of 512 characters, and the filename could tag along for the ride.

Delta_G

It's complaining because you created a pointer to a char and tried to make it point to a const char.  Make your pointer of type const char and you won't have that error. 
If at first you don't succeed, up - home - sudo - enter.

Go Up