Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 2 | /* Copyright (c) FIRST 2008-2016. All Rights Reserved. */ |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 6 | /*----------------------------------------------------------------------------*/ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 7 | |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 8 | #pragma once |
| 9 | |
| 10 | #include "ErrorBase.h" |
| 11 | #include <stdio.h> |
| 12 | #include "Base.h" |
| 13 | |
| 14 | /** |
| 15 | * Base class for all sensors. |
| 16 | * Stores most recent status information as well as containing utility functions |
| 17 | * for checking |
| 18 | * channels and error processing. |
| 19 | */ |
| 20 | class SensorBase : public ErrorBase { |
| 21 | public: |
| 22 | SensorBase(); |
| 23 | virtual ~SensorBase() = default; |
| 24 | |
| 25 | SensorBase(const SensorBase&) = delete; |
| 26 | SensorBase& operator=(const SensorBase&) = delete; |
| 27 | |
| 28 | static void DeleteSingletons(); |
| 29 | |
| 30 | static uint32_t GetDefaultSolenoidModule() { return 0; } |
| 31 | |
| 32 | static bool CheckSolenoidModule(uint8_t moduleNumber); |
| 33 | static bool CheckDigitalChannel(uint32_t channel); |
| 34 | static bool CheckRelayChannel(uint32_t channel); |
| 35 | static bool CheckPWMChannel(uint32_t channel); |
| 36 | static bool CheckAnalogInput(uint32_t channel); |
| 37 | static bool CheckAnalogOutput(uint32_t channel); |
| 38 | static bool CheckSolenoidChannel(uint32_t channel); |
| 39 | static bool CheckPDPChannel(uint32_t channel); |
| 40 | |
| 41 | static const uint32_t kDigitalChannels = 26; |
| 42 | static const uint32_t kAnalogInputs = 8; |
| 43 | static const uint32_t kAnalogOutputs = 2; |
| 44 | static const uint32_t kSolenoidChannels = 8; |
| 45 | static const uint32_t kSolenoidModules = 2; |
| 46 | static const uint32_t kPwmChannels = 20; |
| 47 | static const uint32_t kRelayChannels = 8; |
| 48 | static const uint32_t kPDPChannels = 16; |
| 49 | static const uint32_t kChassisSlots = 8; |
| 50 | |
| 51 | protected: |
| 52 | void AddToSingletonList(); |
| 53 | |
| 54 | static void* m_digital_ports[kDigitalChannels]; |
| 55 | static void* m_relay_ports[kRelayChannels]; |
| 56 | static void* m_pwm_ports[kPwmChannels]; |
| 57 | |
| 58 | private: |
| 59 | static SensorBase* m_singletonList; |
| 60 | SensorBase* m_nextSingleton = nullptr; |
| 61 | }; |