@@ -321,16 +321,19 @@ class QueueStream : public BaseStream {
321
321
// / Activates the output
322
322
virtual bool begin () {
323
323
TRACED ();
324
+ total_written = 0 ;
324
325
active = true ;
325
326
return true ;
326
327
}
327
328
328
329
// / Activate only when filled buffer reached %
329
330
virtual bool begin (size_t activeWhenPercentFilled) {
331
+ total_written = 0 ;
330
332
// determine total buffer size in bytes
331
333
size_t size = callback_buffer_ptr->size () * sizeof (T);
332
334
// calculate limit
333
335
active_limit = size * activeWhenPercentFilled / 100 ;
336
+ LOGI (" activate after: %d bytes" , active_limit);
334
337
return true ;
335
338
}
336
339
@@ -345,15 +348,19 @@ class QueueStream : public BaseStream {
345
348
}
346
349
347
350
int availableForWrite () override {
351
+ if (!active && active_limit > 0 ) return DEFAULT_BUFFER_SIZE;
348
352
return callback_buffer_ptr->availableForWrite () * sizeof (T);
349
353
}
350
354
351
355
virtual size_t write (const uint8_t *data, size_t len) override {
356
+ if (len == 0 ) return 0 ;
352
357
if (active_limit == 0 && !active) return 0 ;
353
358
354
359
// activate automaticaly when limit has been reached
355
- if (active_limit > 0 && !active && available () >= active_limit) {
360
+ total_written += len;
361
+ if (!active && active_limit > 0 && total_written >= active_limit) {
356
362
this ->active = true ;
363
+ LOGI (" setting active" );
357
364
}
358
365
359
366
// make space by deleting oldest entries
@@ -388,9 +395,10 @@ class QueueStream : public BaseStream {
388
395
protected:
389
396
BaseBuffer<T> *callback_buffer_ptr;
390
397
size_t active_limit = 0 ;
391
- bool active;
392
- bool remove_oldest_data;
393
- bool owns_buffer;
398
+ size_t total_written = 0 ;
399
+ bool active = false ;
400
+ bool remove_oldest_data = false ;
401
+ bool owns_buffer = false ;
394
402
};
395
403
396
404
#if USE_OBSOLETE
0 commit comments