blob: cee15b603d98dfedc5e51c0365106e927fca13a9 [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
5/*----------------------------------------------------------------------------*/
6
7#ifndef __MOTOR_SAFETY_HELPER__
8#define __MOTOR_SAFETY_HELPER__
9
10#include "ErrorBase.h"
11#include "Synchronized.h"
12#include <semLib.h>
13
14class MotorSafety;
15
16class MotorSafetyHelper : public ErrorBase
17{
18public:
19 MotorSafetyHelper(MotorSafety *safeObject);
20 ~MotorSafetyHelper();
21 void Feed();
22 void SetExpiration(float expirationTime);
23 float GetExpiration();
24 bool IsAlive();
25 void Check();
26 void SetSafetyEnabled(bool enabled);
27 bool IsSafetyEnabled();
28 static void CheckMotors();
29private:
30 double m_expiration; // the expiration time for this object
31 bool m_enabled; // true if motor safety is enabled for this motor
32 double m_stopTime; // the FPGA clock value when this motor has expired
33 ReentrantSemaphore m_syncMutex; // protect accesses to the state for this object
34 MotorSafety *m_safeObject; // the object that is using the helper
35 MotorSafetyHelper *m_nextHelper; // next object in the list of MotorSafetyHelpers
36 static MotorSafetyHelper *m_headHelper; // the head of the list of MotorSafetyHelper objects
37 static ReentrantSemaphore m_listMutex; // protect accesses to the list of helpers
38};
39
40#endif