blob: 84311915065bd1a8d48ef5be04ac1f7745cd11c8 [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008-2017. 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 the root directory of */
5/* the project. */
6/*----------------------------------------------------------------------------*/
7
8#pragma once
9
10#include <memory>
11#include <string>
12
13#include "DigitalSource.h"
14#include "HAL/Types.h"
15#include "LiveWindow/LiveWindowSendable.h"
16#include "tables/ITableListener.h"
17
18namespace frc {
19
20/**
21 * Class to write to digital outputs.
22 * Write values to the digital output channels. Other devices implemented
23 * elsewhere will allocate channels automatically so for those devices it
24 * shouldn't be done here.
25 */
26class DigitalOutput : public DigitalSource,
27 public ITableListener,
28 public LiveWindowSendable {
29 public:
30 explicit DigitalOutput(int channel);
31 virtual ~DigitalOutput();
32 void Set(bool value);
33 bool Get() const;
34 int GetChannel() const override;
35 void Pulse(double length);
36 bool IsPulsing() const;
37 void SetPWMRate(double rate);
38 void EnablePWM(double initialDutyCycle);
39 void DisablePWM();
40 void UpdateDutyCycle(double dutyCycle);
41
42 // Digital Source Interface
43 HAL_Handle GetPortHandleForRouting() const override;
44 AnalogTriggerType GetAnalogTriggerTypeForRouting() const override;
45 bool IsAnalogTrigger() const override;
46
47 void ValueChanged(ITable* source, llvm::StringRef key,
48 std::shared_ptr<nt::Value> value, bool isNew) override;
49 void UpdateTable();
50 void StartLiveWindowMode();
51 void StopLiveWindowMode();
52 std::string GetSmartDashboardType() const;
53 void InitTable(std::shared_ptr<ITable> subTable);
54 std::shared_ptr<ITable> GetTable() const;
55
56 private:
57 int m_channel;
58 HAL_DigitalHandle m_handle;
59 HAL_DigitalPWMHandle m_pwmGenerator;
60
61 std::shared_ptr<ITable> m_table;
62};
63
64} // namespace frc