BRT Community

General Category => Discussion - Cleo => Topic started by: Chris/ on December 10, 2018, 03:54:20 PM

Title: CleO file write append to new line
Post by: Chris/ on December 10, 2018, 03:54:20 PM
Hi,

I'm trying to append some information to a new line within the same .txt file using the CleO file system however i seem to just be overwriting the same line each time.

Code: [Select]
#include <SPI.h>
#include <CleO.h>

void setup() {
  char STR1[] = "ABCDEFG";
  char STR2[] = "HHHHHHH";
  char STR3[] = "IIIIIII";
  int16_t actual;

  CleO.begin();

  int16_t f = CleO.FOpen("test.txt", FILE_OPEN_EXISTING | FILE_WRITE);
  CleO.FWrite(f, strlen(STR1) + 1, (uint8_t*)STR1, actual);
  CleO.FClose(f);

  CleO.FOpen("test.txt", FILE_OPEN_EXISTING | FILE_WRITE);
  CleO.FWrite(f, strlen(STR2) + 1, (uint8_t*)STR2, actual);
  CleO.FClose(f);

  CleO.FOpen("test.txt", FILE_OPEN_EXISTING | FILE_WRITE);
  CleO.FWrite(f, strlen(STR3) + 1, (uint8_t*)STR3, actual);
  CleO.FClose(f);
}

void loop() {}

I'm after a file that gives:

  ABCDEFG
  HHHHHHH
  IIIIIII

but the code above gives:

IIIIIII

Is there a way of achieving what I'm after?

thanks,

Chris
Title: Re: CleO file write append to new line
Post by: Chris/ on December 13, 2018, 08:08:43 AM
I guess i should have read through the filing system tutorials better!

Here's a solution to this saving it into a .csv file:

Code: [Select]
#include <SPI.h>
#include <CleO.h>


char STR1[] = "A,B,C,D,E,F,G\n";
char STR2[] = "H,H,H,H,H,H,H\n";
char STR3[] = "I,I,I,I,I,I,I\n";
int16_t actual;
int16_t f;
uint32_t pointer = 0;


void setup() {
 
  CleO.begin();
 
  f = CleO.FOpen("test.csv", FILE_OPEN_ALWAYS | FILE_WRITE);
  while (!CleO.FEOF(f)) {                                      // Moves pointer position through the file until end of file is found
    CleO.FSeek(f, pointer);
    pointer++;
  }
  CleO.FWrite(f, strlen(STR1) + 1, (uint8_t*)STR1, actual);
  CleO.FClose(f);

  CleO.FOpen("test.csv", FILE_OPEN_ALWAYS | FILE_WRITE);
  while (!CleO.FEOF(f)) {
    CleO.FSeek(f, pointer);
    pointer++;
  }
  CleO.FWrite(f, strlen(STR2) + 1, (uint8_t*)STR2, actual);
  CleO.FClose(f);
 
  CleO.FOpen("test.csv", FILE_OPEN_ALWAYS | FILE_WRITE);
  while (!CleO.FEOF(f)) {
    CleO.FSeek(f, pointer);
    pointer++;
  }
  CleO.FWrite(f, strlen(STR3) + 1, (uint8_t*)STR3, actual);
  CleO.FClose(f);


}

void loop() {}
Title: Re: CleO file write append to new line
Post by: BRT Community on January 22, 2019, 02:26:57 PM
Hello,

Thanks for you solution!

Best Regards,
BRT Community