Skip to content
This repository was archived by the owner on May 3, 2026. It is now read-only.

Commit 8147465

Browse files
committed
document SmartPort class
1 parent e9db499 commit 8147465

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

include/pros/devices/port.hpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,68 @@
33
#include <cstdint>
44

55
namespace zest {
6+
7+
/**
8+
* @brief Smart Port class. Represents a Smart Port on the V5 brain.
9+
*
10+
* @details Smart Ports may be represented as a 1-indexed number or a 0-indexed number. While the
11+
* user expects a 1-indexed number (matching the labels on the brain), treating it as an index makes
12+
* development easier. This class abstracts that away so we don't have to worry about it.
13+
*
14+
*/
615
class SmartPort {
716
public:
17+
/**
18+
* @brief Construct a Smart Port from its number
19+
*
20+
* @note the smart port labelled "1" on the brain has a port number of 1
21+
*
22+
* @param port_number the port number, 1-indexed
23+
* @return constexpr SmartPort
24+
*/
825
static constexpr SmartPort from_number(uint8_t port_number) {
926
return SmartPort(port_number - 1);
1027
}
1128

29+
/**
30+
* @brief Construct a Smart Port from its index
31+
*
32+
* @note the smart port labelled "1" on the brain has a port index of 0
33+
*
34+
* @param port_index the port index, 0-indexed
35+
* @return constexpr SmartPort
36+
*/
1237
static constexpr SmartPort from_index(uint8_t port_index) {
1338
return SmartPort(port_index);
1439
}
1540

41+
/**
42+
* @brief Get the Smart Port as a number (1-indexed)
43+
*
44+
* @return constexpr uint8_t
45+
*/
1646
constexpr uint8_t as_number() const {
1747
return m_index + 1;
1848
}
1949

50+
/**
51+
* @brief Get the Smart Port as an index (0-indexed)
52+
*
53+
* @return constexpr uint8_t
54+
*/
2055
constexpr uint8_t as_index() const {
2156
return m_index;
2257
}
2358

2459
private:
25-
constexpr SmartPort(int port_index)
60+
/**
61+
* @brief construct a Smart Port from an index
62+
*
63+
* This constructor is private to enforce the use of the `from_number` and `from_index` member
64+
* functions. Having this construct be public defeats the purpose of this class, which is to
65+
* prevent bugs by abstracting the port index.
66+
*/
67+
explicit constexpr SmartPort(uint8_t port_index)
2668
: m_index(port_index) {}
2769

2870
uint8_t m_index;

0 commit comments

Comments
 (0)