WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
ExpansionHub.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <memory>
8#include <string_view>
9
10#include "wpi/util/mutex.hpp"
11
12namespace wpi {
15
16/** This class controls a REV ExpansionHub plugged in over USB to Systemcore. */
18 public:
19 /**
20 * Constructs a new ExpansionHub for a given USB ID
21 *
22 * Multiple instances can be constructed, but will point to the same backing
23 * object with a ref count.
24 *
25 * @param usbId The USB Port ID the hub is plugged into.
26 */
27 explicit ExpansionHub(int usbId);
28 ~ExpansionHub() noexcept = default;
29
30 friend class ExpansionHubServo;
31 friend class ExpansionHubMotor;
32
33 /**
34 * Constructs a servo at the requested channel on this hub.
35 *
36 * Only a single instance of each servo per hub can be constructed at a time.
37 *
38 * @param channel The servo channel
39 * @return Servo object
40 */
42
43 /**
44 * Constructs a motor at the requested channel on this hub.
45 *
46 * Only a single instance of each motor per hub can be constructed at a time.
47 *
48 * @param channel The motor channel
49 * @return Motor object
50 */
52
53 /**
54 * Gets if the hub is currently connected over USB.
55 *
56 * @return True if hub connection, otherwise false
57 */
58 bool IsHubConnected() const;
59
60 /**
61 * Gets the USB ID of this hub.
62 *
63 * @return The USB ID
64 */
65 int GetUsbId() const { return m_usbId; }
66
67 static constexpr int NumUsbPorts = 4;
68 static constexpr int NumServoPorts = 6;
69 static constexpr int NumMotorPorts = 4;
70
71 private:
72 bool CheckAndReserveServo(int channel);
73 void UnreserveServo(int channel);
74
75 bool CheckAndReserveMotor(int channel);
76 void UnreserveMotor(int channel);
77
78 void ReportUsage(std::string_view device, std::string_view data);
79
80 class DataStore;
81 friend class DataStore;
82
83 std::shared_ptr<DataStore> m_dataStore;
84 int m_usbId;
85
86 static wpi::util::mutex m_handleLock;
87 static std::weak_ptr<DataStore> m_storeMap[4];
88
89 static std::shared_ptr<DataStore> GetForUsbId(int usbId);
90};
91
92} // namespace wpi
friend class DataStore
Definition ExpansionHub.hpp:81
int GetUsbId() const
Gets the USB ID of this hub.
Definition ExpansionHub.hpp:65
static constexpr int NumMotorPorts
Definition ExpansionHub.hpp:69
ExpansionHubServo MakeServo(int channel)
Constructs a servo at the requested channel on this hub.
static constexpr int NumUsbPorts
Definition ExpansionHub.hpp:67
bool IsHubConnected() const
Gets if the hub is currently connected over USB.
static constexpr int NumServoPorts
Definition ExpansionHub.hpp:68
ExpansionHubMotor MakeMotor(int channel)
Constructs a motor at the requested channel on this hub.
~ExpansionHub() noexcept=default
friend class ExpansionHubServo
Definition ExpansionHub.hpp:30
ExpansionHub(int usbId)
Constructs a new ExpansionHub for a given USB ID.
friend class ExpansionHubMotor
Definition ExpansionHub.hpp:31
This class controls a specific motor and encoder hooked up to an ExpansionHub.
Definition ExpansionHubMotor.hpp:23
This class controls a specific servo hooked up to an ExpansionHub.
Definition ExpansionHubServo.hpp:18
::std::mutex mutex
Definition mutex.hpp:17
Definition CvSource.hpp:15