blob: 51fd94ce259af00106ac23cb178e84b26cad11bf [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* Open Source Software - may be modified and shared by FRC teams. The code */
Brian Silverman1a675112016-02-20 20:42:49 -05004/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
Brian Silverman26e4e522015-12-17 01:56:40 -05006/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05007
Brian Silverman26e4e522015-12-17 01:56:40 -05008#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 */
20class 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};