blob: 367fb8073b7b31494af2d01146e9a3e89fc55535 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. All Rights Reserved.
3 */
4/* Open Source Software - may be modified and shared by FRC teams. The code */
5/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
6/*----------------------------------------------------------------------------*/
7#pragma once
8
9#include "DigitalSource.h"
10#include "LiveWindow/LiveWindowSendable.h"
11#include "tables/ITableListener.h"
12
13#include <memory>
14
15/**
16 * Class to write to digital outputs.
17 * Write values to the digital output channels. Other devices implemented
18 * elsewhere will allocate
19 * channels automatically so for those devices it shouldn't be done here.
20 */
21class DigitalOutput : public DigitalSource,
22 public ITableListener,
23 public LiveWindowSendable {
24 public:
25 explicit DigitalOutput(uint32_t channel);
26 virtual ~DigitalOutput();
27 void Set(uint32_t value);
28 uint32_t GetChannel() const;
29 void Pulse(float length);
30 bool IsPulsing() const;
31 void SetPWMRate(float rate);
32 void EnablePWM(float initialDutyCycle);
33 void DisablePWM();
34 void UpdateDutyCycle(float dutyCycle);
35
36 // Digital Source Interface
37 virtual uint32_t GetChannelForRouting() const;
38 virtual uint32_t GetModuleForRouting() const;
39 virtual bool GetAnalogTriggerForRouting() const;
40
41 virtual void ValueChanged(ITable* source, llvm::StringRef key,
42 std::shared_ptr<nt::Value> value, bool isNew);
43 void UpdateTable();
44 void StartLiveWindowMode();
45 void StopLiveWindowMode();
46 std::string GetSmartDashboardType() const;
47 void InitTable(std::shared_ptr<ITable> subTable);
48 std::shared_ptr<ITable> GetTable() const;
49
50 private:
51 uint32_t m_channel;
52 void *m_pwmGenerator;
53
54 std::shared_ptr<ITable> m_table;
55};