2014-06-23 11:51:34 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
2014-06-23 11:51:34 -07:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2014-06-23 11:51:34 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "Solenoid.h"
|
2016-06-05 07:33:37 -07:00
|
|
|
|
2016-07-10 17:47:44 -07:00
|
|
|
#include <sstream>
|
2016-06-05 07:33:37 -07:00
|
|
|
|
2014-06-23 11:51:34 -07:00
|
|
|
#include "LiveWindow/LiveWindow.h"
|
2016-05-20 17:30:37 -07:00
|
|
|
#include "WPIErrors.h"
|
2014-09-25 20:36:59 -04:00
|
|
|
#include "simulation/simTime.h"
|
2014-06-23 11:51:34 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor.
|
|
|
|
|
*
|
|
|
|
|
* @param channel The channel on the solenoid module to control (1..8).
|
|
|
|
|
*/
|
2015-06-29 02:43:44 -07:00
|
|
|
Solenoid::Solenoid(uint32_t channel) : Solenoid(1, channel) {}
|
2014-06-23 11:51:34 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor.
|
|
|
|
|
*
|
|
|
|
|
* @param moduleNumber The solenoid module (1 or 2).
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param channel The channel on the solenoid module to control (1..8).
|
2014-06-23 11:51:34 -07:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
Solenoid::Solenoid(uint8_t moduleNumber, uint32_t channel) {
|
2016-07-10 17:47:44 -07:00
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << "pneumatic/" << moduleNumber << "/" << channel;
|
|
|
|
|
m_impl = new SimContinuousOutput(ss.str());
|
2016-05-20 17:30:37 -07:00
|
|
|
|
|
|
|
|
LiveWindow::GetInstance()->AddActuator("Solenoid", moduleNumber, channel,
|
|
|
|
|
this);
|
2014-06-23 11:51:34 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-13 23:17:19 -07:00
|
|
|
Solenoid::~Solenoid() {
|
2016-05-20 17:30:37 -07:00
|
|
|
if (m_table != nullptr) m_table->RemoveTableListener(this);
|
2015-08-13 23:17:19 -07:00
|
|
|
}
|
|
|
|
|
|
2014-06-23 11:51:34 -07:00
|
|
|
/**
|
|
|
|
|
* Set the value of a solenoid.
|
|
|
|
|
*
|
|
|
|
|
* @param on Turn the solenoid output off or on.
|
|
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
void Solenoid::Set(bool on) {
|
|
|
|
|
m_on = on;
|
|
|
|
|
m_impl->Set(on ? 1 : -1);
|
2014-06-23 11:51:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read the current value of the solenoid.
|
|
|
|
|
*
|
|
|
|
|
* @return The current value of the solenoid.
|
|
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
bool Solenoid::Get() const { return m_on; }
|
2014-06-23 11:51:34 -07:00
|
|
|
|
2015-08-13 23:17:19 -07:00
|
|
|
void Solenoid::ValueChanged(ITable* source, llvm::StringRef key,
|
|
|
|
|
std::shared_ptr<nt::Value> value, bool isNew) {
|
|
|
|
|
if (!value->IsBoolean()) return;
|
2016-05-20 17:30:37 -07:00
|
|
|
Set(value->GetBoolean());
|
2014-06-23 11:51:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Solenoid::UpdateTable() {
|
2016-05-20 17:30:37 -07:00
|
|
|
if (m_table != nullptr) {
|
|
|
|
|
m_table->PutBoolean("Value", Get());
|
|
|
|
|
}
|
2014-06-23 11:51:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Solenoid::StartLiveWindowMode() {
|
2016-05-20 17:30:37 -07:00
|
|
|
Set(false);
|
|
|
|
|
if (m_table != nullptr) {
|
|
|
|
|
m_table->AddTableListener("Value", this, true);
|
|
|
|
|
}
|
2014-06-23 11:51:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Solenoid::StopLiveWindowMode() {
|
2016-05-20 17:30:37 -07:00
|
|
|
Set(false);
|
|
|
|
|
if (m_table != nullptr) {
|
|
|
|
|
m_table->RemoveTableListener(this);
|
|
|
|
|
}
|
2014-06-23 11:51:34 -07:00
|
|
|
}
|
|
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
std::string Solenoid::GetSmartDashboardType() const { return "Solenoid"; }
|
2014-06-23 11:51:34 -07:00
|
|
|
|
2015-07-29 16:48:04 -04:00
|
|
|
void Solenoid::InitTable(std::shared_ptr<ITable> subTable) {
|
2016-05-20 17:30:37 -07:00
|
|
|
m_table = subTable;
|
|
|
|
|
UpdateTable();
|
2014-06-23 11:51:34 -07:00
|
|
|
}
|
|
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
std::shared_ptr<ITable> Solenoid::GetTable() const { return m_table; }
|