Skip to content

Commit

Permalink
added changes to device.hpp, distance.hpp and
Browse files Browse the repository at this point in the history
imu.hpp
  • Loading branch information
aaryan-gautam committed Mar 30, 2023
1 parent 74fe2af commit 380a2de
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 47 deletions.
51 changes: 6 additions & 45 deletions include/pros/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* This file should not be modified by users, since it gets replaced whenever
* a kernel upgrade occurs.
*
* \copyright (c) 2017-2021, Purdue University ACM SIGBots.
* \copyright (c) 2017-2023, Purdue University ACM SIGBots.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -22,59 +22,24 @@
namespace pros {
inline namespace v5 {

/*
* Enum of possible v5 devices.
*
* Contains all current V5 Devices.
*/
enum class DeviceType {
none = 0,
motor = 2,
rotation = 4,
imu = 6,
distance = 7,
radio = 8,
vision = 11,
adi = 12,
optical = 16,
gps = 20,
serial = 129,
undefined = 255
};

class Device {
public:
/**
* Creates a Device object.
*
* \param port The V5 port number from 1-21
*/
explicit Device(const std::uint8_t port);

/**
* Gets the port number of the Smart Device.
*
* \return The smart device's port number.
*/
std::uint8_t get_port(void);

/**
* Checks if the device is installed.
*
* \return true if the corresponding device is installed, false otherwise.
*/
virtual bool is_installed();
std::uint8_t get_port(void) {
return _port;
}

/**
* Gets the type of device.
*
* This function uses the following values of errno when an error state is
* reached:
* EACCES - Mutex of port cannot be taken (access denied).
*
* \return The device type as an enum.
*/
pros::DeviceType get_plugged_type() const;
virtual pros::DeviceType get_type() const = 0;


protected:
Expand All @@ -83,15 +48,11 @@ class Device {
*
* \param port The V5 port number from 1-21
*
* \param deviceType The type of the constructed device
*/
Device(const std::uint8_t port, const enum DeviceType deviceType) :
_port(port),
_deviceType(deviceType) {}
explicit Device(const std::uint8_t port) : _port(port) {}

protected:
const std::uint8_t _port;
const enum DeviceType _deviceType = pros::DeviceType::none;
};
} // namespace v5
} // namespace pros
Expand Down
8 changes: 7 additions & 1 deletion include/pros/distance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ class Distance : public Device {
* object size: (object size), object velocity: (object velocity)]
*/
friend std::ostream& operator<<(std::ostream& os, pros::Distance& distance);


/**
* Returns the type of device
*
*/
pros::DeviceType get_type() const;

private:
///@}
};
Expand Down
7 changes: 6 additions & 1 deletion include/pros/imu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Imu : public Device {


public:
explicit Imu(const std::uint8_t port) : Device(port, DeviceType::imu) {};
Imu(const std::uint8_t port) : Device(port) {};

/**
* Calibrate IMU
Expand Down Expand Up @@ -496,6 +496,11 @@ class Imu : public Device {
*/
friend std::ostream& operator<<(std::ostream& os, const pros::Imu& imu);

/**
* Returns the type of device
*
*/
pros::DeviceType get_type() const;
///@}
};

Expand Down

0 comments on commit 380a2de

Please sign in to comment.