44
55#include < array>
66#include < cstdint>
7- #include < limits>
87
98namespace zest {
109
@@ -135,38 +134,6 @@ class SmartPort {
135134 uint8_t m_index;
136135};
137136
138- namespace ports {
139- /*
140- * Physical smart ports have a number from 1 to 21 (inclusive). While compile-time error checking
141- * could prevent an invalid port being constructed, the error messages that would be produced
142- * wouldn't be very concise.
143- * However, if the user tried constructing a device on the imaginary port 42, the project wouldn't
144- * compile since PORT_42 isn't declared. This error message is much clearer.
145- */
146- constexpr auto PORT_1 = SmartPort::from_number(1 );
147- constexpr auto PORT_2 = SmartPort::from_number(2 );
148- constexpr auto PORT_3 = SmartPort::from_number(3 );
149- constexpr auto PORT_4 = SmartPort::from_number(4 );
150- constexpr auto PORT_5 = SmartPort::from_number(5 );
151- constexpr auto PORT_6 = SmartPort::from_number(6 );
152- constexpr auto PORT_7 = SmartPort::from_number(7 );
153- constexpr auto PORT_8 = SmartPort::from_number(8 );
154- constexpr auto PORT_9 = SmartPort::from_number(9 );
155- constexpr auto PORT_10 = SmartPort::from_number(10 );
156- constexpr auto PORT_11 = SmartPort::from_number(11 );
157- constexpr auto PORT_12 = SmartPort::from_number(12 );
158- constexpr auto PORT_13 = SmartPort::from_number(13 );
159- constexpr auto PORT_14 = SmartPort::from_number(14 );
160- constexpr auto PORT_15 = SmartPort::from_number(15 );
161- constexpr auto PORT_16 = SmartPort::from_number(16 );
162- constexpr auto PORT_17 = SmartPort::from_number(17 );
163- constexpr auto PORT_18 = SmartPort::from_number(18 );
164- constexpr auto PORT_19 = SmartPort::from_number(19 );
165- constexpr auto PORT_20 = SmartPort::from_number(20 );
166- constexpr auto PORT_21 = SmartPort::from_number(21 );
167- constexpr auto INVALID_SMART_PORT = SmartPort::from_index(std::numeric_limits<uint8_t >::max());
168- } // namespace ports
169-
170137/* *
171138 * @brief ADI Port class. Represents an ADI Port on a the brain or on a 3-wire expander.
172139 *
@@ -185,7 +152,7 @@ class AdiPort {
185152 * @param adi_port the ADI port. Can be lowercase or lowercase
186153 */
187154 constexpr AdiPort (SmartPort expander_port, AdiPort adi_port)
188- : m_expander_port (expander_port),
155+ : m_host_port (expander_port),
189156 m_index(adi_port.as_index()) {}
190157
191158 /* *
@@ -244,7 +211,7 @@ class AdiPort {
244211 * @return constexpr SmartPort
245212 */
246213 constexpr SmartPort get_expander_port () const {
247- return m_expander_port ;
214+ return m_host_port ;
248215 }
249216
250217 /* *
@@ -256,10 +223,11 @@ class AdiPort {
256223 * @return pros::RecursiveMutex&
257224 */
258225 pros::RecursiveMutex& get_mutex () const {
259- if (m_expander_port.as_number () > 22 || m_index > 7 ) {
260- return ports::INVALID_SMART_PORT.get_mutex ();
226+ if (m_host_port.as_number () > 22 || m_index > 7 ) {
227+ // return a reference to the invalid port mutex
228+ return SmartPort::from_number (33 ).get_mutex ();
261229 } else {
262- return m_expander_port .get_mutex ();
230+ return m_host_port .get_mutex ();
263231 }
264232 }
265233
@@ -275,27 +243,10 @@ class AdiPort {
275243 * prevent bugs by abstracting the port index.
276244 */
277245 explicit constexpr AdiPort (uint8_t index)
278- : m_expander_port (INTEGRATED_PORT),
246+ : m_host_port (INTEGRATED_PORT),
279247 m_index(index) {}
280248
281- SmartPort m_expander_port ;
249+ SmartPort m_host_port ;
282250 uint8_t m_index;
283251};
284-
285- namespace ports {
286- /*
287- * ADI ports have a char from 'A' to 'H'. While compile-time error checking could prevent an invalid
288- * port being constructed, the error messages that would be produced wouldn't be very concise.
289- * However, if the user tried constructing a device on the imaginary port I, the project wouldn't
290- * compile since PORT_I isn't declared. This error message is much clearer.
291- */
292- constexpr auto PORT_A = AdiPort::from_char(' A' );
293- constexpr auto PORT_B = AdiPort::from_char(' B' );
294- constexpr auto PORT_C = AdiPort::from_char(' C' );
295- constexpr auto PORT_D = AdiPort::from_char(' D' );
296- constexpr auto PORT_E = AdiPort::from_char(' E' );
297- constexpr auto PORT_F = AdiPort::from_char(' F' );
298- constexpr auto PORT_G = AdiPort::from_char(' G' );
299- constexpr auto PORT_H = AdiPort::from_char(' H' );
300- } // namespace ports
301252} // namespace zest
0 commit comments