Home
Roadside
Carputer
geoHist
software
FRC
Blog
Now you can download a copy of these docs so you can use them offline!
Download now
Main Page
Related Pages
Classes
Files
File List
Solenoid.cpp
1
/*----------------------------------------------------------------------------*/
2
/* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
5
/*----------------------------------------------------------------------------*/
6
7
#include "Solenoid.h"
8
#include "NetworkCommunication/UsageReporting.h"
9
#include "WPIErrors.h"
10
#include "LiveWindow/LiveWindow.h"
11
15
void
Solenoid::InitSolenoid()
16
{
17
char
buf[64];
18
if
(!
CheckSolenoidModule
(
m_moduleNumber
))
19
{
20
snprintf(buf, 64,
"Solenoid Module %d"
,
m_moduleNumber
);
21
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf);
22
return
;
23
}
24
if
(!
CheckSolenoidChannel
(m_channel))
25
{
26
snprintf(buf, 64,
"Solenoid Channel %d"
, m_channel);
27
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
28
return
;
29
}
30
Resource::CreateResourceObject
(&m_allocated, tSolenoid::kNumDO7_0Elements * kSolenoidChannels);
31
32
snprintf(buf, 64,
"Solenoid %d (Module: %d)"
, m_channel,
m_moduleNumber
);
33
if
(m_allocated->
Allocate
((
m_moduleNumber
- 1) * kSolenoidChannels + m_channel - 1, buf) == ~0ul)
34
{
35
CloneError(m_allocated);
36
return
;
37
}
38
39
LiveWindow::GetInstance
()->
AddActuator
(
"Solenoid"
,
m_moduleNumber
, m_channel,
this
);
40
nUsageReporting::report(nUsageReporting::kResourceType_Solenoid, m_channel,
m_moduleNumber
- 1);
41
}
42
48
Solenoid::Solenoid
(UINT32 channel)
49
:
SolenoidBase
(GetDefaultSolenoidModule())
50
, m_channel (channel)
51
{
52
InitSolenoid();
53
}
54
61
Solenoid::Solenoid
(UINT8 moduleNumber, UINT32 channel)
62
:
SolenoidBase
(moduleNumber)
63
, m_channel (channel)
64
{
65
InitSolenoid();
66
}
67
71
Solenoid::~Solenoid
()
72
{
73
if
(
CheckSolenoidModule
(
m_moduleNumber
))
74
{
75
m_allocated->
Free
((
m_moduleNumber
- 1) * kSolenoidChannels + m_channel - 1);
76
}
77
}
78
84
void
Solenoid::Set
(
bool
on)
85
{
86
if
(
StatusIsFatal
())
return
;
87
UINT8 value = on ? 0xFF : 0x00;
88
UINT8 mask = 1 << (m_channel - 1);
89
90
SolenoidBase::Set
(value, mask);
91
}
92
98
bool
Solenoid::Get
()
99
{
100
if
(
StatusIsFatal
())
return
false
;
101
UINT8 value =
GetAll
() & ( 1 << (m_channel - 1));
102
return
(value != 0);
103
}
104
105
106
void
Solenoid::ValueChanged
(
ITable
* source,
const
std::string& key,
EntryValue
value,
bool
isNew) {
107
Set
(value.b);
108
}
109
110
void
Solenoid::UpdateTable
() {
111
if
(m_table != NULL) {
112
m_table->
PutBoolean
(
"Value"
,
Get
());
113
}
114
}
115
116
void
Solenoid::StartLiveWindowMode
() {
117
Set
(
false
);
118
m_table->
AddTableListener
(
"Value"
,
this
,
true
);
119
}
120
121
void
Solenoid::StopLiveWindowMode
() {
122
Set
(
false
);
123
m_table->
RemoveTableListener
(
this
);
124
}
125
126
std::string
Solenoid::GetSmartDashboardType
() {
127
return
"Solenoid"
;
128
}
129
130
void
Solenoid::InitTable
(
ITable
*subTable) {
131
m_table = subTable;
132
UpdateTable
();
133
}
134
135
ITable
*
Solenoid::GetTable
() {
136
return
m_table;
137
}
138
Generated on Tue Feb 5 2013 00:55:09 for WPILibC++ by
1.8.1.2
© 2006-2009 Dustin Spicuzza. All rights reserved.
Powered by Onnac
I do not condone or encourage graffiti. Please paint responsibly.