Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 28a6988

Browse files
Voting
1 parent 1f64574 commit 28a6988

File tree

4 files changed

+87
-7
lines changed

4 files changed

+87
-7
lines changed

‎src/eloquentarduino/data_structures/NdQueue.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ namespace Eloquent {
9191
uint8_t sampleIdx = (_head + k) % depth;
9292
uint16_t offset = k * num_features;
9393

94-
memcpy(X + offset, _samples[sampleIdx], sizeof(float) * num_features);
94+
//memcpy(X + offset, _samples[sampleIdx], sizeof(float) * num_features);
9595

96-
//for (uint16_t i = 0; i < num_features; i++) {
97-
// X[offset + i] = _samples[sampleIdx][i];
98-
//}
96+
for (uint16_t i = 0; i < num_features; i++) {
97+
X[offset + i] = _samples[sampleIdx][i];
98+
}
9999
}
100100
}
101101

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#pragma once
2+
3+
4+
namespace Eloquent {
5+
namespace DataStructures {
6+
/**
7+
* Output a robust value when a given number of votes agree
8+
* @tparam votes
9+
* @tparam quorum
10+
*/
11+
template<uint8_t votes, uint8_t quorum>
12+
class MajorityVoting {
13+
public:
14+
15+
/**
16+
* Reset state
17+
*/
18+
void clear() {
19+
_idx = 0;
20+
21+
for (uint8_t i = 0; i < votes; i++)
22+
_votes[i] = 0;
23+
}
24+
25+
/**
26+
* Add vote to voting system
27+
*/
28+
void vote(uint8_t vote) {
29+
_votes[_idx % votes] = vote;
30+
_idx += 1;
31+
}
32+
33+
/**
34+
* Test if quorum was achieved
35+
*/
36+
bool hasMajority() {
37+
_decision = 255;
38+
39+
if (_idx < votes)
40+
return false;
41+
42+
bool majority = false;
43+
44+
for (uint8_t i = 0; i < votes - quorum; i++) {
45+
uint8_t vote = _votes[i];
46+
uint8_t count = 1;
47+
48+
for (uint8_t j = i + 1; j < votes; j++)
49+
if (_votes[j] == vote)
50+
count += 1;
51+
52+
if (count >= quorum) {
53+
_decision = vote;
54+
majority = true;
55+
break;
56+
}
57+
}
58+
59+
return majority;
60+
}
61+
62+
/**
63+
* Get robust decision, if any
64+
*/
65+
uint8_t decision() {
66+
return _decision;
67+
}
68+
69+
protected:
70+
uint8_t _votes[votes] = {0};
71+
uint8_t _idx = 0;
72+
uint8_t _decision;
73+
};
74+
}
75+
}

‎src/eloquentarduino/io/print.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#pragma once
1+
#ifndef ELOQUENTARDUINO_PRINT
2+
#define ELOQUENTARDUINO_PRINT 1
23

34
#if defined(Stream_h)
45

@@ -66,4 +67,5 @@ namespace eloquent {
6667
}
6768
}
6869

70+
#endif
6971
#endif

‎src/eloquentarduino/io/serial_print.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#pragma once
1+
#ifndef ELOQUENTARDUINO_SERIAL_PRINT
2+
#define ELOQUENTARDUINO_SERIAL_PRINT 1
3+
4+
#if defined(Stream_h)
25

36
#include "print.h"
47

5-
#if defined(Stream_h)
68

79
namespace eloquent {
810
namespace io {
@@ -40,4 +42,5 @@ namespace eloquent {
4042
}
4143
}
4244

45+
#endif
4346
#endif

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /