tsave

save an area of a table to sd-card,defined in samples
Author: Robert Schirmer
License: BSD
Github: rbrt/data/tsave.axo

Inlets

charptr32 file name

bool32.rising trigger

int32 start of area

int32 length of area

Outlets

bool32.pulse done saving

Attributes

objref table

Declaration
int ntrig;
WORKING_AREA(waThreadSD, 800);
Init
ntrig = 0;
Control Rate
outlet_done = 0;

if ((inlet_trig > 0) && !ntrig) {
  ntrig = 1;
  FIL FileObject;
  FRESULT err;
  UINT bytes_written;
  codec_clearbuffer();
  err = f_open(&FileObject, inlet_filename, FA_WRITE | FA_CREATE_ALWAYS);
  if (err != FR_OK) {
    report_fatfs_error(err, inlet_filename);
    return;
  }

  int rem_sz = inlet_length << (attr_table.BITS >> 4);
  int offset = inlet_start << (attr_table.BITS >> 4);
  while (rem_sz > 0) {
    if (rem_sz > sizeof(fbuff)) {
      memcpy((char *)fbuff, (char *)(&attr_table.array[0]) + offset,
             sizeof(fbuff));
      err = f_write(&FileObject, fbuff, sizeof(fbuff), &bytes_written);
      rem_sz -= sizeof(fbuff);
      offset += sizeof(fbuff);
    } else {
      memcpy((char *)fbuff, (char *)(&attr_table.array[0]) + offset, rem_sz);
      err = f_write(&FileObject, fbuff, rem_sz, &bytes_written);
      rem_sz = 0;
    }
  }
  outlet_done = 1;
  if (err != FR_OK)
    report_fatfs_error(err, inlet_filename);
  err = f_close(&FileObject);
  if (err != FR_OK)
    report_fatfs_error(err, inlet_filename);
} else if (!(inlet_trig > 0))
  ntrig = 0;

Privacy

© 2024 Zrna Research