Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rc-switch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
c3pb
rc-switch
Commits
5e9666dc
Commit
5e9666dc
authored
9 years ago
by
Max Horn
Browse files
Options
Downloads
Patches
Plain Diff
Add new setProtocol(Protocol) method
The resulting code is actually simpler, and more powerful at the same time
parent
94642ad7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
RCSwitch.cpp
+17
-16
17 additions, 16 deletions
RCSwitch.cpp
RCSwitch.h
+3
-2
3 additions, 2 deletions
RCSwitch.h
with
20 additions
and
18 deletions
RCSwitch.cpp
+
17
−
16
View file @
5e9666dc
...
...
@@ -67,24 +67,25 @@ RCSwitch::RCSwitch() {
/**
* Sets the protocol to send.
*/
void
RCSwitch
::
setProtocol
(
Protocol
protocol
)
{
this
->
protocol
=
protocol
;
}
/**
* Sets the protocol to send, from a list of predefined protocols
*/
void
RCSwitch
::
setProtocol
(
int
nProtocol
)
{
if
(
nProtocol
<=
0
||
nProtocol
>
numProto
)
{
this
->
nProtocol
=
1
;
// TODO: trigger an error, e.g. "bad protocol" ???
}
else
{
this
->
nProtocol
=
nProtocol
;
if
(
nProtocol
<=
0
||
nProtocol
>=
numProto
)
{
nProtocol
=
1
;
// TODO: trigger an error, e.g. "bad protocol" ???
}
this
->
setPulseLength
(
proto
[
nProtocol
]
.
pulseLength
)
;
this
->
protocol
=
proto
[
nProtocol
];
}
/**
* Sets the protocol to send with pulse length in microseconds.
*/
void
RCSwitch
::
setProtocol
(
int
nProtocol
,
int
nPulseLength
)
{
if
(
nProtocol
<=
0
||
nProtocol
>
numProto
)
{
this
->
nProtocol
=
1
;
// TODO: trigger an error, e.g. "bad protocol" ???
}
else
{
this
->
nProtocol
=
nProtocol
;
}
setProtocol
(
nProtocol
);
this
->
setPulseLength
(
nPulseLength
);
}
...
...
@@ -93,7 +94,7 @@ void RCSwitch::setProtocol(int nProtocol, int nPulseLength) {
* Sets pulse length in microseconds
*/
void
RCSwitch
::
setPulseLength
(
int
nPulseLength
)
{
this
->
nP
ulseLength
=
nPulseLength
;
this
->
protocol
.
p
ulseLength
=
nPulseLength
;
}
/**
...
...
@@ -493,9 +494,9 @@ void RCSwitch::transmit(int nHighPulses, int nLowPulses) {
}
#endif
digitalWrite
(
this
->
nTransmitterPin
,
HIGH
);
delayMicroseconds
(
this
->
nP
ulseLength
*
nHighPulses
);
delayMicroseconds
(
this
->
protocol
.
p
ulseLength
*
nHighPulses
);
digitalWrite
(
this
->
nTransmitterPin
,
LOW
);
delayMicroseconds
(
this
->
nP
ulseLength
*
nLowPulses
);
delayMicroseconds
(
this
->
protocol
.
p
ulseLength
*
nLowPulses
);
#if not defined( RCSwitchDisableReceiving )
if
(
disabled_Receive
)
{
...
...
@@ -517,7 +518,7 @@ void RCSwitch::transmit(HighLow pulses) {
* Waveform Protocol 2: | |__
*/
void
RCSwitch
::
send0
()
{
this
->
transmit
(
proto
[
nProto
col
]
.
zero
);
this
->
transmit
(
protocol
.
zero
);
}
/**
...
...
@@ -528,7 +529,7 @@ void RCSwitch::send0() {
* Waveform Protocol 2: | |_
*/
void
RCSwitch
::
send1
()
{
this
->
transmit
(
proto
[
nProto
col
]
.
one
);
this
->
transmit
(
protocol
.
one
);
}
...
...
@@ -570,7 +571,7 @@ void RCSwitch::sendTF() {
* Waveform Protocol 2: | |__________
*/
void
RCSwitch
::
sendSync
()
{
this
->
transmit
(
proto
[
nProto
col
]
.
syncFactor
);
this
->
transmit
(
protocol
.
syncFactor
);
}
#if not defined( RCSwitchDisableReceiving )
...
...
This diff is collapsed.
Click to expand it.
RCSwitch.h
+
3
−
2
View file @
5e9666dc
...
...
@@ -101,6 +101,7 @@ class RCSwitch {
HighLow
one
;
};
void
setProtocol
(
Protocol
protocol
);
void
setProtocol
(
int
nProtocol
);
void
setProtocol
(
int
nProtocol
,
int
nPulseLength
);
...
...
@@ -128,9 +129,9 @@ class RCSwitch {
int
nReceiverInterrupt
;
#endif
int
nTransmitterPin
;
int
nPulseLength
;
int
nRepeatTransmit
;
int
nProtocol
;
Protocol
protocol
;
#if not defined( RCSwitchDisableReceiving )
static
int
nReceiveTolerance
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment