Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008-2017. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #pragma once |
| 9 | |
| 10 | #include <set> |
| 11 | |
| 12 | #include "ErrorBase.h" |
| 13 | #include "HAL/cpp/priority_mutex.h" |
| 14 | |
| 15 | namespace frc { |
| 16 | |
| 17 | class MotorSafety; |
| 18 | |
| 19 | class MotorSafetyHelper : public ErrorBase { |
| 20 | public: |
| 21 | explicit MotorSafetyHelper(MotorSafety* safeObject); |
| 22 | ~MotorSafetyHelper(); |
| 23 | void Feed(); |
| 24 | void SetExpiration(double expirationTime); |
| 25 | double GetExpiration() const; |
| 26 | bool IsAlive() const; |
| 27 | void Check(); |
| 28 | void SetSafetyEnabled(bool enabled); |
| 29 | bool IsSafetyEnabled() const; |
| 30 | static void CheckMotors(); |
| 31 | |
| 32 | private: |
| 33 | // the expiration time for this object |
| 34 | double m_expiration; |
| 35 | // true if motor safety is enabled for this motor |
| 36 | bool m_enabled; |
| 37 | // the FPGA clock value when this motor has expired |
| 38 | double m_stopTime; |
| 39 | // protect accesses to the state for this object |
| 40 | mutable priority_recursive_mutex m_syncMutex; |
| 41 | // the object that is using the helper |
| 42 | MotorSafety* m_safeObject; |
| 43 | // List of all existing MotorSafetyHelper objects. |
| 44 | static std::set<MotorSafetyHelper*> m_helperList; |
| 45 | // protect accesses to the list of helpers |
| 46 | static priority_recursive_mutex m_listMutex; |
| 47 | }; |
| 48 | |
| 49 | } // namespace frc |