Configuration File on Local Filesystem

30 Nov 2010

Can anyone think of a simple way to read a text file from the local filesystem and use that to assign pin numbers and the like for I/O? An example might be that I have a file where the first line reads "PIR_MODULE: P23", the mbed opens that file...reads that line and decides that the 'DigitalIn PIR(Pxx);' should be 'DigitalIn PIR(P23);'...

I'm sure I could have been a little more concise with the example, but I think it gets the point across... I'm guessing there's got to be some work required... but this would be very useful for a couple projects I'm trying to make as user friendly as possible.. I'd really like the user to be able to connect a peripheral and then tell the mbed where it's at using a text file...

Any help is greatly appreciated!

01 Dec 2010

Hi Mark,

Here is something that might help. Basically uses dynamic creation of an object, plus a function that is part of the RPC library to convert a pin name string to a PinName:

#include "mbed.h"
#include "rpc.h"

DigitalOut *output;
char pinname[] = "p5";

int main() {
    PinName pin = parse_pins(pinname);
    output = new DigitalOut(pin);
    
    output->write(1);
}
I have to admit, I haven't tested it on the hardware, but it should work fine...

Simon

01 Dec 2010

Check this out: ConfigFile.

01 Dec 2010

Thanks so much to the both of you for the quick replies! It's greatly appreciated... I will take a look at both options and see where it leads me..

I'll check back in once I wrap my head around it!

01 Dec 2010

Ok, so I've had a few minutes now.... Simon, thanks for the help... That example will actually help me for another portion... Igor, I don't know how I missed it but that configfile example is exactly what I was looking for... That along with Simon's input is perfect.

Thanks guys for the great help and patience! -mark