local file system trap

13 Nov 2011

while trying to learn how things work I wrote this little program. I'm on a mac

#include "mbed.h"

// LED1 = P1.18  LED2 = P1.20  LED3 = P1.21  LED4 = P1.23
#define LED_MASK 0x00140000
PortInOut ledport(Port1, LED_MASK);

Serial pcscreen( USBTX,USBRX);  // when you start, in terminal type:
//   screen /dev/tty.usbmodemfa132

PwmOut myled(LED1);

float brightness =0.5;
LocalFileSystem local("local");               // Create the local filesystem under the name "local"
FILE *fp;


void setup()  {
    pcscreen.printf("b to make it brighter, d to make it dimmer\n");
    ledport=LED_MASK;
    fp = fopen("/local/out.txt", "w");  // Open "out.txt" on the local file system for writing
}

void loop ( ) {
    myled = brightness;
    char c;
    c = pcscreen.getc();
    if (c == 'b') brightness += 0.02;
    if (c == 'd') brightness -= 0.02;
    if (c == 'n') ledport.write(LED_MASK);
    if (c == 'f') ledport = 0;
    if (c == 'q') fclose(fp);
    ledport.input();
    int p= (ledport );
    ledport.output();
    pcscreen.printf("read: %X%c%c",p,'\n','\r');
    
    fprintf(fp, "%d\n\r",p);
}

int main() {
    setup();
    while (1) {
        loop ();
    }
}

I have gotten into a situation where I seem unable to mount the mbed onto the mac's filesystem. I THINK what is going on is that it disconnects from the file system as soon as it starts to run the above program. If I hold down the reset button while I plug it into the USB port, I do see it appear briefly in the finder, with an error box that says it was ejected improperly last time, then it unmounts itself as the program on the mbed starts to run, I think. Help!

13 Nov 2011

Yeah I think that is what is going on. You need to put in

fclose(fp); 

somewhere to close the file.

13 Nov 2011

But I can't figure out how to modify what is on the mbed unless it is mounted on the filesystem!

The idea was that I'd always type 'q'

13 Nov 2011

ah, I was just not reading the info in the handbook carefully. by keeping the reset button down until it downloaded another program it did mount and the problem is resolved.