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

Commit e9db499

Browse files
committed
port bugfixes
1 parent cff2a5b commit e9db499

2 files changed

Lines changed: 40 additions & 61 deletions

File tree

include/pros/devices/port.hpp

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,34 @@
11
#pragma once
22

3-
#include "pros/rtos.hpp"
4-
5-
#include <cctype>
3+
#include <cstdint>
64

75
namespace zest {
8-
96
class SmartPort {
107
public:
11-
static constexpr SmartPort from_number(uint8_t number) {
12-
return SmartPort(number - 1);
8+
static constexpr SmartPort from_number(uint8_t port_number) {
9+
return SmartPort(port_number - 1);
1310
}
1411

15-
static constexpr SmartPort from_index(uint8_t index) {
16-
return SmartPort(index);
12+
static constexpr SmartPort from_index(uint8_t port_index) {
13+
return SmartPort(port_index);
1714
}
1815

19-
constexpr uint8_t as_number() {
20-
return m_index - 1;
16+
constexpr uint8_t as_number() const {
17+
return m_index + 1;
2118
}
2219

23-
constexpr uint8_t as_index() {
20+
constexpr uint8_t as_index() const {
2421
return m_index;
2522
}
2623

2724
private:
28-
constexpr SmartPort(uint8_t index)
29-
: m_index(index) {}
25+
constexpr SmartPort(int port_index)
26+
: m_index(port_index) {}
3027

3128
uint8_t m_index;
3229
};
3330

3431
namespace ports {
35-
3632
constexpr auto PORT_1 = SmartPort::from_number(1);
3733
constexpr auto PORT_2 = SmartPort::from_number(2);
3834
constexpr auto PORT_3 = SmartPort::from_number(3);
@@ -54,50 +50,51 @@ constexpr auto PORT_18 = SmartPort::from_number(18);
5450
constexpr auto PORT_19 = SmartPort::from_number(19);
5551
constexpr auto PORT_20 = SmartPort::from_number(20);
5652
constexpr auto PORT_21 = SmartPort::from_number(21);
57-
5853
} // namespace ports
5954

6055
class AdiPort {
6156
public:
62-
static constexpr AdiPort from_char(char port) {
63-
return AdiPort(port);
57+
static constexpr AdiPort from_letter(char port) {
58+
// if the index is provided as a character
59+
if (port >= '0' && port <= '9') {
60+
return AdiPort(port - '0');
61+
}
62+
// convert to uppercase if needed
63+
if (port >= 'a' && port <= 'z') {
64+
port -= ('a' - 'A');
65+
}
66+
// 'A' has index 0, 'B' has index 1, etc
67+
return AdiPort(port - 'A');
6468
}
6569

66-
constexpr char as_char() {
67-
return m_port;
70+
static constexpr AdiPort from_index(uint8_t index) {
71+
return AdiPort(index);
6872
}
6973

70-
constexpr uint8_t as_index() {
71-
return static_cast<uint8_t>(m_port) - 65;
74+
constexpr char as_letter() const {
75+
return m_index;
7276
}
7377

74-
private:
75-
constexpr AdiPort(char port) {
76-
// convert lowercase to uppercase if needed
77-
if (port >= 97) {
78-
port -= 32;
79-
}
80-
m_port = port;
78+
constexpr uint8_t as_index() const {
79+
return m_index;
8180
}
8281

83-
char m_port;
82+
private:
83+
uint8_t m_index;
84+
85+
constexpr AdiPort(uint8_t index)
86+
: m_index(index) {}
8487
};
8588

8689
namespace ports {
87-
88-
constexpr auto PORT_A = AdiPort::from_char('A');
89-
constexpr auto PORT_B = AdiPort::from_char('B');
90-
constexpr auto PORT_C = AdiPort::from_char('C');
91-
constexpr auto PORT_D = AdiPort::from_char('D');
92-
constexpr auto PORT_E = AdiPort::from_char('E');
93-
constexpr auto PORT_F = AdiPort::from_char('F');
94-
constexpr auto PORT_G = AdiPort::from_char('G');
95-
constexpr auto PORT_H = AdiPort::from_char('H');
90+
constexpr auto PORT_A = AdiPort::from_letter('A');
91+
constexpr auto PORT_B = AdiPort::from_letter('B');
92+
constexpr auto PORT_C = AdiPort::from_letter('C');
93+
constexpr auto PORT_D = AdiPort::from_letter('D');
94+
constexpr auto PORT_E = AdiPort::from_letter('E');
95+
constexpr auto PORT_F = AdiPort::from_letter('F');
96+
constexpr auto PORT_G = AdiPort::from_letter('G');
97+
constexpr auto PORT_H = AdiPort::from_letter('H');
9698

9799
} // namespace ports
98-
99-
template<typename T>
100-
pros::RecursiveMutex& get_port_mutex(T&&) {
101-
throw("can't get mutex for non-port object!");
102-
}
103100
} // namespace zest

src/devices/port.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)