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

blues / note-arduino / 13523375661

25 Feb 2025 02:18PM CUT coverage: 90.526% (-4.3%) from 94.831%
13523375661

Pull #132

github

web-flow
Merge 94f998ff5 into 2efe3032e
Pull Request #132: WIP: Template Singleton `make_` functions

98 of 137 branches covered (71.53%)

Branch coverage included in aggregate %.

28 of 33 new or added lines in 3 files covered. (84.85%)

1 existing line in 1 file now uncovered.

332 of 338 relevant lines covered (98.22%)

15.22 hits per line

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

75.0
/src/NoteTxn_Arduino.cpp
1
#include "NoteTxn_Arduino.hpp"
2

3
#ifndef NOTE_MOCK
4
  #include <Arduino.h>
5
#else
6
  #include "mock/mock-arduino.hpp"
7
  #include "mock/mock-parameters.hpp"
8
#endif
9

10
// Singleton instance of the NoteTxn_Arduino class
11
namespace instance {
12
    inline NoteTxn* & note_txn (void) {
7✔
13
        static NoteTxn* note_txn = nullptr;
14
        return note_txn;
7✔
15
    }
16
};
17

18
NoteTxn *
UNCOV
19
make_note_txn (
×
20
    nullptr_t
21
) {
NEW
22
    NoteTxn* & note_txn = instance::note_txn();
×
NEW
23
    if (note_txn) {
×
NEW
24
        delete note_txn;
×
NEW
25
        note_txn = nullptr;
×
26
    }
NEW
27
    return note_txn;
×
28
}
29

30
template <typename T>
31
NoteTxn *
32
make_note_txn (
7✔
33
    T & txn_pins_
34
) {
35
    NoteTxn* & note_txn = instance::note_txn();
7✔
36

37
    if (txn_pins_[0] == txn_pins_[1]) {
7✔
38
        // Invalid tuple invokes deletion
39
        if (note_txn) {
3!
40
            delete note_txn;
3!
41
            note_txn = nullptr;
3✔
42
        }
43
    } else if (!note_txn) {
4✔
44
        note_txn = new NoteTxn_Arduino(txn_pins_[0], txn_pins_[1]);
3!
45
    }
46

47
    return note_txn;
7✔
48
}
49

50
NoteTxn_Arduino::NoteTxn_Arduino
16✔
51
(
52
    uint8_t ctx_pin_,
53
    uint8_t rtx_pin_
54
) :
16✔
55
    _ctx_pin(ctx_pin_),
16✔
56
    _rtx_pin(rtx_pin_)
16✔
57
{
58
    // Float CTX/RTX to conserve energy
59
    ::pinMode(_ctx_pin, INPUT);
16!
60
    ::pinMode(_rtx_pin, INPUT);
16!
61
}
16✔
62

63
bool
64
NoteTxn_Arduino::start (
10✔
65
    uint32_t timeout_ms_
66
)
67
{
68
    bool result = false;
10✔
69

70
    // Signal Request To Transact
71
    ::pinMode(_rtx_pin, OUTPUT);
10✔
72
    ::digitalWrite(_rtx_pin, HIGH);
10✔
73

74
    // Await Clear To Transact Signal
75
    ::pinMode(_ctx_pin, INPUT_PULLUP);
10✔
76
    for (uint32_t timeout = (::millis() + timeout_ms_)
10✔
77
       ; ::millis() < timeout
22✔
78
       ; ::delay(1)
12✔
79
    ) {
80
        if (HIGH == ::digitalRead(_ctx_pin)) {
19✔
81
            result = true;
7✔
82
            break;
7✔
83
        }
84
    }
85

86
    // Float CTX to conserve energy
87
    ::pinMode(_ctx_pin, INPUT);
10✔
88

89
    // Abandon request on timeout
90
    if (!result) {
10✔
91
        stop();
3✔
92
    }
93

94
    return result;
10✔
95
}
96

97
void
98
NoteTxn_Arduino::stop (
4✔
99
    void
100
)
101
{
102
    // Float RTX pin
103
    ::pinMode(_rtx_pin, INPUT);
4✔
104
}
4✔
105

106
// Explicitly instantiate the template function for array types
107
template NoteTxn * make_note_txn<uint8_t[2]>(uint8_t(&)[2]);
108
template NoteTxn * make_note_txn<const uint8_t[2]>(const uint8_t(&)[2]);
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