File tree 2 files changed +27
-20
lines changed
2 files changed +27
-20
lines changed Original file line number Diff line number Diff line change 1
1
#include " Connection.h"
2
2
3
- // Constructors
3
+ // Empty constructor
4
4
Connection::Connection () {
5
- left = 255 ;
6
- right = 255 ;
5
+ left = 0 ;
6
+ right = 0 ;
7
+ connected = false ;
7
8
}
8
9
9
- // Create via provided values
10
+ // Constructor with provided pegs
10
11
Connection::Connection (byte a, byte b) {
11
- // Ensure that the smaller of the
12
- // two values is the left side
13
- if (a < b) {
14
- left = a;
15
- right = b;
16
- }
17
- else {
18
- left = b;
19
- right = a;
20
- }
12
+ // Ensure that the smaller of the
13
+ // two values is the left side
14
+ if (a < b) {
15
+ left = a;
16
+ right = b;
17
+ connected = true ;
18
+ } else if (b > a) {
19
+ left = b;
20
+ right = a;
21
+ connected = true ;
22
+ } else {
23
+ left = a;
24
+ right = a;
25
+ connected = false ;
26
+ }
21
27
}
22
28
23
29
// Overload equals comparator
24
30
boolean Connection::operator ==(const Connection &rhs) {
25
- return (left==rhs.left && right==rhs.right );
31
+ return (left==rhs.left && right==rhs.right );
26
32
}
27
33
28
34
// Returns true if connection is connected
29
35
boolean Connection::isConnected () {
30
- return (left != 255 && right != 255 ) ;
36
+ return connected ;
31
37
}
32
38
33
39
// Prints connection to Serial port
34
40
void Connection::print () {
41
+ if (connected) {
35
42
Serial.print (" (" );
36
43
Serial.print (left);
37
44
Serial.print (" ," );
38
45
Serial.print (right);
39
46
Serial.print (" )" );
47
+ } else {
48
+ Serial.print (" Not connected" );
49
+ }
40
50
}
41
-
Original file line number Diff line number Diff line change 7
7
8
8
"left", and "right", are the two pegs participating
9
9
in the connection.
10
-
11
- Values of [-1, -1] for left and right, imply no active
12
- connection
13
10
*/
14
11
15
12
class Connection {
16
13
private:
17
14
byte left;
18
15
byte right;
16
+ boolean connected;
19
17
20
18
public:
21
19
// Constructors
You can’t perform that action at this time.
0 commit comments