Skip to content

Commit 926a8de

Browse files
author
Ryan Calme
committed
Adding attribute
1 parent def8f90 commit 926a8de

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

Diff for: Arduino/Puzzle_Box/Connection.cpp

+26-17
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,50 @@
11
#include "Connection.h"
22

3-
// Constructors
3+
// Empty constructor
44
Connection::Connection() {
5-
left = 255;
6-
right = 255;
5+
left = 0;
6+
right = 0;
7+
connected = false;
78
}
89

9-
// Create via provided values
10+
// Constructor with provided pegs
1011
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+
}
2127
}
2228

2329
// Overload equals comparator
2430
boolean Connection::operator==(const Connection &rhs) {
25-
return (left==rhs.left && right==rhs.right);
31+
return (left==rhs.left && right==rhs.right);
2632
}
2733

2834
// Returns true if connection is connected
2935
boolean Connection::isConnected() {
30-
return (left != 255 && right != 255);
36+
return connected;
3137
}
3238

3339
// Prints connection to Serial port
3440
void Connection::print() {
41+
if (connected) {
3542
Serial.print("(");
3643
Serial.print(left);
3744
Serial.print(",");
3845
Serial.print(right);
3946
Serial.print(")");
47+
} else {
48+
Serial.print("Not connected");
49+
}
4050
}
41-

Diff for: Arduino/Puzzle_Box/Connection.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
88
"left", and "right", are the two pegs participating
99
in the connection.
10-
11-
Values of [-1, -1] for left and right, imply no active
12-
connection
1310
*/
1411

1512
class Connection {
1613
private:
1714
byte left;
1815
byte right;
16+
boolean connected;
1917

2018
public:
2119
// Constructors

0 commit comments

Comments
 (0)