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

blues / note-arduino / 13448530662

21 Feb 2025 02:05AM UTC coverage: 89.384% (-5.4%) from 94.831%
13448530662

Pull #132

github

web-flow
Merge 728a56b26 into be22b4c5e
Pull Request #132: WIP: Template Singleton `make_` functions

102 of 149 branches covered (68.46%)

Branch coverage included in aggregate %.

20 of 22 new or added lines in 2 files covered. (90.91%)

1 existing line in 1 file now uncovered.

319 of 322 relevant lines covered (99.07%)

15.82 hits per line

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

80.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
NoteTxn *
UNCOV
11
make_note_txn (
×
12
    nullptr_t
13
) {
NEW
14
    const uint8_t invoke_deletion[2] = {0, 0}; // Invalid tuple invokes deletion
×
NEW
15
    return make_note_txn(invoke_deletion);
×
16
}
17

18
template <typename T>
19
NoteTxn *
20
make_note_txn (
7✔
21
    T & txn_pins_
22
) {
23
    // Singleton
24
    static NoteTxn * note_txn = nullptr;
25

26
    if (txn_pins_[0] == txn_pins_[1]) {
7✔
27
        // Invalid tuple invokes deletion
28
        if (note_txn) {
3!
29
            delete note_txn;
3!
30
            note_txn = nullptr;
3✔
31
        }
32
    } else if (!note_txn) {
4✔
33
        note_txn = new NoteTxn_Arduino(txn_pins_[0], txn_pins_[1]);
3!
34
    }
35

36
    return note_txn;
7✔
37
}
38

39
NoteTxn_Arduino::NoteTxn_Arduino
16✔
40
(
41
    uint8_t ctx_pin_,
42
    uint8_t rtx_pin_
43
) :
16✔
44
    _ctx_pin(ctx_pin_),
16✔
45
    _rtx_pin(rtx_pin_)
16✔
46
{
47
    // Float CTX/RTX to conserve energy
48
    ::pinMode(_ctx_pin, INPUT);
16!
49
    ::pinMode(_rtx_pin, INPUT);
16!
50
}
16✔
51

52
bool
53
NoteTxn_Arduino::start (
10✔
54
    uint32_t timeout_ms_
55
)
56
{
57
    bool result = false;
10✔
58

59
    // Signal Request To Transact
60
    ::pinMode(_rtx_pin, OUTPUT);
10✔
61
    ::digitalWrite(_rtx_pin, HIGH);
10✔
62

63
    // Await Clear To Transact Signal
64
    ::pinMode(_ctx_pin, INPUT_PULLUP);
10✔
65
    for (uint32_t timeout = (::millis() + timeout_ms_)
10✔
66
       ; ::millis() < timeout
22✔
67
       ; ::delay(1)
12✔
68
    ) {
69
        if (HIGH == ::digitalRead(_ctx_pin)) {
19✔
70
            result = true;
7✔
71
            break;
7✔
72
        }
73
    }
74

75
    // Float CTX to conserve energy
76
    ::pinMode(_ctx_pin, INPUT);
10✔
77

78
    // Abandon request on timeout
79
    if (!result) {
10✔
80
        stop();
3✔
81
    }
82

83
    return result;
10✔
84
}
85

86
void
87
NoteTxn_Arduino::stop (
4✔
88
    void
89
)
90
{
91
    // Float RTX pin
92
    ::pinMode(_rtx_pin, INPUT);
4✔
93
}
4✔
94

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

© 2026 Coveralls, Inc