• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bblanchon / ArduinoStreamUtils / 4332192079

pending completion
4332192079

push

github

Benoit Blanchon
Fix "__FlashStringHelper is ambiguous" with arduino-pico

840 of 853 relevant lines covered (98.48%)

1269.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/src/StreamUtils/Policies/WriteWaitingPolicy.hpp
1
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
2
// Copyright Benoit Blanchon 2019-2023
3
// MIT License
4

5
#pragma once
6

7
#include <Arduino.h>
8

9
#include "../Buffers/LinearBuffer.hpp"
10
#include "../Configuration.hpp"
11
#include "../Polyfills.hpp"
12

13
namespace StreamUtils {
14

15
struct WriteWaitingPolicy {
16
 public:
17
  WriteWaitingPolicy(Polyfills::function wait)
210✔
18
      : _wait(Polyfills::move(wait)), _timeout(1000) {}
210✔
19

20
  size_t write(Print &target, const uint8_t *data, size_t size) {
120✔
21
    unsigned long startTime = millis();
120✔
22
    size_t totalWritten = 0;
120✔
23

24
    for (;;) {
25
      size_t n = target.write(data, size);
210✔
26
      size -= n;
210✔
27
      data += n;
210✔
28
      totalWritten += n;
210✔
29
      if (size == 0 || millis() - startTime >= _timeout)
210✔
30
        return totalWritten;
120✔
31
      _wait();
90✔
32
    }
90✔
33
  }
34

35
  size_t write(Print &target, uint8_t data) {
450✔
36
    unsigned long startTime = millis();
450✔
37

38
    for (;;) {
39
      if (target.write(data))
480✔
40
        return 1;
420✔
41
      if (millis() - startTime >= _timeout)
60✔
42
        return 0;
30✔
43
      _wait();
30✔
44
    }
45
  }
46

47
  template <typename TTarget>
48
  void flush(TTarget &target) {
×
49
    target.flush();
×
50
  }
×
51

52
  void implicitFlush(Print &) {}
210✔
53

54
  void setTimeout(unsigned long timeout) {
60✔
55
    _timeout = timeout;
60✔
56
  }
60✔
57

58
 private:
59
  Polyfills::function _wait;
60
  unsigned long _timeout;
61
};
62

63
}  // namespace StreamUtils
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc