blob: e8bb5140d1fbc91d798e11b39cb3d96360f6cbd3 [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 "DigitalSource.h"
11#include "LiveWindow/LiveWindowSendable.h"
12#include "tables/ITableListener.h"
13
14#include <memory>
15
16/**
17 * Class to write to digital outputs.
18 * Write values to the digital output channels. Other devices implemented
19 * elsewhere will allocate
20 * channels automatically so for those devices it shouldn't be done here.
21 */
22class DigitalOutput : public DigitalSource,
23 public ITableListener,
24 public LiveWindowSendable {
25 public:
26 explicit DigitalOutput(uint32_t channel);
27 virtual ~DigitalOutput();
28 void Set(uint32_t value);
29 uint32_t GetChannel() const;
30 void Pulse(float length);
31 bool IsPulsing() const;
32 void SetPWMRate(float rate);
33 void EnablePWM(float initialDutyCycle);
34 void DisablePWM();
35 void UpdateDutyCycle(float dutyCycle);
36
37 // Digital Source Interface
38 virtual uint32_t GetChannelForRouting() const;
39 virtual uint32_t GetModuleForRouting() const;
40 virtual bool GetAnalogTriggerForRouting() const;
41
42 virtual void ValueChanged(ITable* source, llvm::StringRef key,
43 std::shared_ptr<nt::Value> value, bool isNew);
44 void UpdateTable();
45 void StartLiveWindowMode();
46 void StopLiveWindowMode();
47 std::string GetSmartDashboardType() const;
48 void InitTable(std::shared_ptr<ITable> subTable);
49 std::shared_ptr<ITable> GetTable() const;
50
51 private:
52 uint32_t m_channel;
53 void *m_pwmGenerator;
54
55 std::shared_ptr<ITable> m_table;
56};