Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Better Code Organization #225

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
69897fa
Added inline namespaces as detailed in issue #223 (Branch is WIP)
WillXuCodes Jul 14, 2020
fa2a21f
Added ADI namespace, and backwards compatibility for the reorganized ADI
WillXuCodes Jul 14, 2020
5714c8c
Removed ADI from a constructor header.
WillXuCodes Jul 14, 2020
d890e7d
Added v5 namespace to controller.
WillXuCodes Jul 14, 2020
8c92796
Changed the v5 namespace properly to v5
WillXuCodes Jul 15, 2020
db3fc20
Moved backwards compatibility to area after the adi classes were
WillXuCodes Jul 15, 2020
4dd8612
Removed code related to pull request #222 and issue #217 related to
WillXuCodes Jul 15, 2020
929605e
Added a better comments
WillXuCodes Jul 16, 2020
00d4e9c
Merge branch 'develop' into reorganize
WillXuCodes Jun 7, 2021
a6fd67d
Added accidentally deleted class declaration
WillXuCodes Jun 7, 2021
71f3e24
Named port correctly
WillXuCodes Jun 7, 2021
784bef4
Deleted extraneous port class declaration
WillXuCodes Jun 7, 2021
e42f63f
Removed ADI in ADIDigitalOut
WillXuCodes Jun 7, 2021
9937ba2
Updated comments
WillXuCodes Jun 7, 2021
6d3f22c
Fixed compilation error
WillXuCodes Jun 7, 2021
dd3547a
Fixed version
WillXuCodes Jun 7, 2021
347ed3a
Merge branch 'develop' into reorganize
ayushuk Jan 18, 2022
1b1e097
Fix version numbers
ayushuk Jan 18, 2022
fc96973
Minor formatting
ayushuk Jan 18, 2022
40addc6
Added new sensors to v5 namespace
WillXuCodes Mar 14, 2022
3c9dc30
Merge branch 'develop' into reorganize
WillXuCodes Mar 14, 2022
21df7a8
Revert Version File
WillXuCodes Mar 14, 2022
2ef3311
Merge branch 'develop' into reorganize
WillXuCodes Mar 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 87 additions & 61 deletions include/pros/adi.hpp

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions include/pros/distance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "pros/distance.h"

namespace pros {
inline namespace v5 {

class Distance {
public:
/**
Expand Down Expand Up @@ -109,6 +111,8 @@ class Distance {
private:
const std::uint8_t _port;
};

}
} // namespace pros

#endif
2 changes: 2 additions & 0 deletions include/pros/gps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "pros/gps.h"

namespace pros {
inline namespace v5 {
class Gps {
const std::uint8_t _port;

Expand Down Expand Up @@ -277,6 +278,7 @@ class Gps {
virtual pros::c::gps_accel_s_t get_accel() const;

}; // Gps Class
}

using GPS = Gps;

Expand Down
6 changes: 4 additions & 2 deletions include/pros/imu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "pros/imu.h"

namespace pros {
inline namespace v5 {
class Imu {
const std::uint8_t _port;

Expand Down Expand Up @@ -446,9 +447,10 @@ class Imu {
*/
virtual bool is_calibrating() const;
};

using IMU = Imu;


} //namespace v5
} // namespace pros

#endif
2 changes: 1 addition & 1 deletion include/pros/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ int32_t usd_is_installed(void);

#ifdef __cplusplus
}
}
} // namespace pros
}
#endif

Expand Down
2 changes: 2 additions & 0 deletions include/pros/misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <string>

namespace pros {
inline namespace v5 {
class Controller {
public:
/**
Expand Down Expand Up @@ -258,6 +259,7 @@ class Controller {
private:
controller_id_e_t _id;
};
} // namespace v5

namespace battery {
/**
Expand Down
2 changes: 2 additions & 0 deletions include/pros/motors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "pros/motors.h"

namespace pros {
inline namespace v5 {
class Motor {
public:
/**
Expand Down Expand Up @@ -838,5 +839,6 @@ namespace literals {
const pros::Motor operator"" _mtr(const unsigned long long int m);
const pros::Motor operator"" _rmtr(const unsigned long long int m);
} // namespace literals
} // namespace v5
} // namespace pros
#endif // _PROS_MOTORS_HPP_
2 changes: 2 additions & 0 deletions include/pros/optical.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "pros/optical.h"

namespace pros {
inline namespace v5 {
class Optical {
public:
/**
Expand Down Expand Up @@ -229,6 +230,7 @@ class Optical {
private:
const std::uint8_t _port;
};
}
} // namespace pros

#endif
2 changes: 2 additions & 0 deletions include/pros/rotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "pros/rotation.h"

namespace pros {
inline namespace v5 {
class Rotation {
const std::uint8_t _port;

Expand Down Expand Up @@ -185,6 +186,7 @@ class Rotation {
*/
virtual std::int32_t get_reversed();
};
}
} // namespace pros

#endif
3 changes: 2 additions & 1 deletion include/pros/rtos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <type_traits>

namespace pros {
inline namespace rtos {
class Task {
public:
/**
Expand Down Expand Up @@ -522,7 +523,7 @@ class Mutex {
return take(std::max(static_cast<uint32_t>(0), (abs_time - Clock::now()).count()));
}
};

}
/**
* Gets the number of milliseconds since PROS initialized.
*
Expand Down
2 changes: 2 additions & 0 deletions include/pros/vision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <cstdint>

namespace pros {
inline namespace v5 {
class Vision {
public:
/**
Expand Down Expand Up @@ -441,5 +442,6 @@ class Vision {
private:
std::uint8_t _port;
};
} // namespace v5
} // namespace pros
#endif // _PROS_VISION_HPP_
2 changes: 1 addition & 1 deletion src/devices/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "v5_api.h"
#include "vdml/vdml.h"

#define CONTROLLER_MAX_COLS 19
#define CONTROLLER_MAX_COLS 15

// From enum in misc.h
#define NUM_BUTTONS 12
Expand Down
2 changes: 2 additions & 0 deletions src/devices/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "kapi.h"

namespace pros {
inline namespace v5 {
using namespace pros::c;

Controller::Controller(pros::controller_id_e_t id) : _id(id) {}
Expand Down Expand Up @@ -80,4 +81,5 @@ std::uint8_t is_disabled(void) {
return competition_is_disabled();
}
} // namespace competition
} // namespace v5
} // namespace pros
74 changes: 37 additions & 37 deletions src/devices/vdml_adi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,148 +15,148 @@
#include "vdml/port.h"

namespace pros {
namespace adi{
using namespace pros::c;

ADIPort::ADIPort(std::uint8_t adi_port, adi_port_config_e_t type)
Port::Port(std::uint8_t adi_port, adi_port_config_e_t type)
: _smart_port(INTERNAL_ADI_PORT), _adi_port(adi_port) {
ext_adi_port_set_config(_smart_port, _adi_port, type);
}

ADIPort::ADIPort(ext_adi_port_pair_t port_pair, adi_port_config_e_t type)
Port::Port(ext_adi_port_pair_t port_pair, adi_port_config_e_t type)
: _smart_port(port_pair.first), _adi_port(port_pair.second) {
ext_adi_port_set_config(_smart_port, _adi_port, type);
}

std::int32_t ADIPort::set_config(adi_port_config_e_t type) const {
std::int32_t Port::set_config(adi_port_config_e_t type) const {
return ext_adi_port_set_config(_smart_port, _adi_port, type);
}

std::int32_t ADIPort::get_config() const {
std::int32_t Port::get_config() const {
return ext_adi_port_get_config(_smart_port, _adi_port);
}

std::int32_t ADIPort::set_value(std::int32_t value) const {
std::int32_t Port::set_value(std::int32_t value) const {
return ext_adi_port_set_value(_smart_port, _adi_port, value);
}

std::int32_t ADIPort::get_value() const {
std::int32_t Port::get_value() const {
return ext_adi_port_get_value(_smart_port, _adi_port);
}

AnalogIn::AnalogIn(std::uint8_t adi_port) : Port(adi_port, E_ADI_ANALOG_IN) {}
AnalogIn::AnalogIn(ext_adi_port_pair_t port_pair) : Port(port_pair, E_ADI_ANALOG_IN) {}

ADIAnalogIn::ADIAnalogIn(std::uint8_t adi_port) : ADIPort(adi_port, E_ADI_ANALOG_IN) {}
ADIAnalogIn::ADIAnalogIn(ext_adi_port_pair_t port_pair) : ADIPort(port_pair, E_ADI_ANALOG_IN) {}

std::int32_t ADIAnalogIn::calibrate() const {
std::int32_t AnalogIn::calibrate() const {
return ext_adi_analog_calibrate(_smart_port, _adi_port);
}

std::int32_t ADIAnalogIn::get_value_calibrated() const {
std::int32_t AnalogIn::get_value_calibrated() const {
return ext_adi_analog_read_calibrated(_smart_port, _adi_port);
}

std::int32_t ADIAnalogIn::get_value_calibrated_HR() const {
std::int32_t AnalogIn::get_value_calibrated_HR() const {
return ext_adi_analog_read_calibrated_HR(_smart_port, _adi_port);
}

ADIAnalogOut::ADIAnalogOut(std::uint8_t adi_port) : ADIPort(adi_port, E_ADI_ANALOG_OUT) {}
ADIAnalogOut::ADIAnalogOut(ext_adi_port_pair_t port_pair) : ADIPort(port_pair, E_ADI_ANALOG_OUT) {}
AnalogOut::AnalogOut(std::uint8_t adi_port) : Port(adi_port, E_ADI_ANALOG_OUT) {}
AnalogOut::AnalogOut(ext_adi_port_pair_t port_pair) : Port(port_pair, E_ADI_ANALOG_OUT) {}

ADIDigitalIn::ADIDigitalIn(std::uint8_t adi_port) : ADIPort(adi_port, E_ADI_DIGITAL_IN) {}
ADIDigitalIn::ADIDigitalIn(ext_adi_port_pair_t port_pair) : ADIPort(port_pair, E_ADI_DIGITAL_IN) {}
DigitalIn::DigitalIn(std::uint8_t adi_port) : Port(adi_port, E_ADI_DIGITAL_IN) {}
DigitalIn::DigitalIn(ext_adi_port_pair_t port_pair) : Port(port_pair, E_ADI_DIGITAL_IN) {}

std::int32_t ADIDigitalIn::get_new_press() const {
std::int32_t DigitalIn::get_new_press() const {
return ext_adi_digital_get_new_press(_smart_port, _adi_port);
}

ADIDigitalOut::ADIDigitalOut(std::uint8_t adi_port, bool init_state) : ADIPort(adi_port, E_ADI_DIGITAL_OUT) {
DigitalOut::DigitalOut(std::uint8_t adi_port, bool init_state) : Port(adi_port, E_ADI_DIGITAL_OUT) {
set_value(init_state);
}

ADIDigitalOut::ADIDigitalOut(ext_adi_port_pair_t port_pair, bool init_state) : ADIPort(port_pair, E_ADI_DIGITAL_OUT) {
DigitalOut::DigitalOut(ext_adi_port_pair_t port_pair, bool init_state) : ADIPort(port_pair, E_ADI_DIGITAL_IN) {
set_value(init_state);
}

ADIMotor::ADIMotor(std::uint8_t adi_port) : ADIPort(adi_port, E_ADI_LEGACY_PWM) {
Motor::Motor(std::uint8_t adi_port) : Port(adi_port, E_ADI_LEGACY_PWM) {
stop();
}

ADIMotor::ADIMotor(ext_adi_port_pair_t port_pair) : ADIPort(port_pair, E_ADI_LEGACY_PWM) {
Motor::Motor(ext_adi_port_pair_t port_pair) : Port(port_pair, E_ADI_LEGACY_PWM) {
stop();
}

std::int32_t ADIMotor::stop() const {
std::int32_t Motor::stop() const {
return ext_adi_motor_stop(_smart_port, _adi_port);
}

ADIEncoder::ADIEncoder(std::uint8_t adi_port_top, std::uint8_t adi_port_bottom, bool reversed) : ADIPort(adi_port_top) {
Encoder::Encoder(std::uint8_t adi_port_top, std::uint8_t adi_port_bottom, bool reversed) : Port(adi_port_top) {
std::int32_t _port = ext_adi_encoder_init(INTERNAL_ADI_PORT, adi_port_top, adi_port_bottom, reversed);
get_ports(_port, _smart_port, _adi_port);
}

ADIEncoder::ADIEncoder(ext_adi_port_tuple_t port_tuple, bool reversed) : ADIPort(std::get<1>(port_tuple)) {
Encoder::Encoder(ext_adi_port_tuple_t port_tuple, bool reversed) : Port(std::get<1>(port_tuple)) {
std::int32_t _port =
ext_adi_encoder_init(std::get<0>(port_tuple), std::get<1>(port_tuple), std::get<2>(port_tuple), reversed);
get_ports(_port, _smart_port, _adi_port);

}

std::int32_t ADIEncoder::reset() const {
std::int32_t Encoder::reset() const {
return adi_encoder_reset(merge_adi_ports(_smart_port, _adi_port));
}

std::int32_t ADIEncoder::get_value() const {
std::int32_t Encoder::get_value() const {
return adi_encoder_get(merge_adi_ports(_smart_port, _adi_port));
}

ADIUltrasonic::ADIUltrasonic(std::uint8_t adi_port_ping, std::uint8_t adi_port_echo) : ADIPort(adi_port_ping) {
Ultrasonic::Ultrasonic(std::uint8_t adi_port_ping, std::uint8_t adi_port_echo) : Port(adi_port_ping) {
std::int32_t _port = ext_adi_ultrasonic_init(INTERNAL_ADI_PORT, adi_port_ping, adi_port_echo);
get_ports(_port, _smart_port, _adi_port);
}

ADIUltrasonic::ADIUltrasonic(ext_adi_port_tuple_t port_tuple) : ADIPort(std::get<1>(port_tuple)) {
Ultrasonic::Ultrasonic(ext_adi_port_tuple_t port_tuple) : Port(std::get<1>(port_tuple)) {
std::int32_t _port =
ext_adi_ultrasonic_init(std::get<0>(port_tuple), std::get<1>(port_tuple), std::get<2>(port_tuple));
get_ports(_port, _smart_port, _adi_port);
}

std::int32_t ADIUltrasonic::get_value() const {
std::int32_t Ultrasonic::get_value() const {
return adi_ultrasonic_get(merge_adi_ports(_smart_port, _adi_port));
}

ADIGyro::ADIGyro(std::uint8_t adi_port, double multiplier) : ADIPort(adi_port) {
Gyro::Gyro(std::uint8_t adi_port, double multiplier) : Port(adi_port) {
std::int32_t _port = ext_adi_gyro_init(INTERNAL_ADI_PORT, adi_port, multiplier);
get_ports(_port, _smart_port, _adi_port);
}

ADIGyro::ADIGyro(ext_adi_port_pair_t port_pair, double multiplier) : ADIPort(std::get<1>(port_pair)) {
Gyro::Gyro(ext_adi_port_pair_t port_pair, double multiplier) : ADIPort(std::get<1>(port_pair)) {
std::int32_t _port = ext_adi_gyro_init(port_pair.first, port_pair.second, multiplier);
get_ports(_port, _smart_port, _adi_port);
}

double ADIGyro::get_value() const {
double Gyro::get_value() const {
return adi_gyro_get(merge_adi_ports(_smart_port, _adi_port));
}

std::int32_t ADIGyro::reset() const {
std::int32_t Gyro::reset() const {
return adi_gyro_reset(merge_adi_ports(_smart_port, _adi_port));
}

ADIPotentiometer::ADIPotentiometer(std::uint8_t adi_port, adi_potentiometer_type_e_t potentiometer_type) : ADIAnalogIn(adi_port) {
Potentiometer::Potentiometer(std::uint8_t adi_port, adi_potentiometer_type_e_t potentiometer_type) : AnalogIn(adi_port) {
std::int32_t _port = ext_adi_potentiometer_init(INTERNAL_ADI_PORT, adi_port, potentiometer_type);
get_ports(_port, _smart_port, _adi_port);
_smart_port++; // for inherited functions this is necessary
}

ADIPotentiometer::ADIPotentiometer(ext_adi_port_pair_t port_pair, adi_potentiometer_type_e_t potentiometer_type) : ADIAnalogIn(std::get<1>(port_pair)) {
Potentiometer::Potentiometer(ext_adi_port_pair_t port_pair, adi_potentiometer_type_e_t potentiometer_type) : AnalogIn(std::get<1>(port_pair)) {
std::int32_t _port = ext_adi_potentiometer_init(port_pair.first, port_pair.second, potentiometer_type);
get_ports(_port, _smart_port, _adi_port);
_smart_port++; // for inherited functions this is necessary
}

double ADIPotentiometer::get_angle() const {
double Potentiometer::get_angle() const {
uint8_t temp_smart = _smart_port - 1;
return ext_adi_potentiometer_get_angle(merge_adi_ports(temp_smart, _adi_port));
}

} // namespace adi
} // namespace pros
5 changes: 4 additions & 1 deletion src/devices/vdml_distance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include "pros/distance.hpp"

namespace pros {

inline namespace v5{

Distance::Distance(const std::uint8_t port) : _port(port) {}

std::int32_t Distance::get() {
Expand All @@ -35,4 +36,6 @@ double Distance::get_object_velocity() {
std::uint8_t Distance::get_port() {
return _port;
}

}
} // namespace pros
2 changes: 2 additions & 0 deletions src/devices/vdml_gps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "pros/gps.hpp"

namespace pros {
inline namespace v5 {

std::int32_t Gps::initialize_full(double xInitial, double yInitial, double headingInitial, double xOffset,
double yOffset) const {
Expand Down Expand Up @@ -71,4 +72,5 @@ pros::c::gps_accel_s_t Gps::get_accel() const {
return pros::c::gps_get_accel(_port);
}

}
} // namespace pros
Loading