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
c9fddc27
Commit
c9fddc27
authored
9 years ago
by
Max Horn
Browse files
Options
Downloads
Patches
Plain Diff
Add a bunch of const qualifiers
These help to catch bugs, and also can sometimes help the compiler optimize the code
parent
a0fb5247
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
RCSwitch.cpp
+14
-16
14 additions, 16 deletions
RCSwitch.cpp
RCSwitch.h
+8
-8
8 additions, 8 deletions
RCSwitch.h
with
22 additions
and
24 deletions
RCSwitch.cpp
+
14
−
16
View file @
c9fddc27
...
@@ -189,26 +189,26 @@ void RCSwitch::switchOff(int nAddressCode, int nChannelCode) {
...
@@ -189,26 +189,26 @@ void RCSwitch::switchOff(int nAddressCode, int nChannelCode) {
}
}
/**
/**
* Deprecated, use switchOn(char* sGroup, char* sDevice) instead!
* Deprecated, use switchOn(
const
char* sGroup,
const
char* sDevice) instead!
* Switch a remote switch on (Type A with 10 pole DIP switches)
* Switch a remote switch on (Type A with 10 pole DIP switches)
*
*
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param nChannelCode Number of the switch itself (1..5)
* @param nChannelCode Number of the switch itself (1..5)
*/
*/
void
RCSwitch
::
switchOn
(
char
*
sGroup
,
int
nChannel
)
{
void
RCSwitch
::
switchOn
(
const
char
*
sGroup
,
int
nChannel
)
{
char
*
code
[
6
]
=
{
"00000"
,
"10000"
,
"01000"
,
"00100"
,
"00010"
,
"00001"
};
const
char
*
code
[
6
]
=
{
"00000"
,
"10000"
,
"01000"
,
"00100"
,
"00010"
,
"00001"
};
this
->
switchOn
(
sGroup
,
code
[
nChannel
]);
this
->
switchOn
(
sGroup
,
code
[
nChannel
]);
}
}
/**
/**
* Deprecated, use switchOff(char* sGroup, char* sDevice) instead!
* Deprecated, use switchOff(
const
char* sGroup,
const
char* sDevice) instead!
* Switch a remote switch off (Type A with 10 pole DIP switches)
* Switch a remote switch off (Type A with 10 pole DIP switches)
*
*
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param nChannelCode Number of the switch itself (1..5)
* @param nChannelCode Number of the switch itself (1..5)
*/
*/
void
RCSwitch
::
switchOff
(
char
*
sGroup
,
int
nChannel
)
{
void
RCSwitch
::
switchOff
(
const
char
*
sGroup
,
int
nChannel
)
{
char
*
code
[
6
]
=
{
"00000"
,
"10000"
,
"01000"
,
"00100"
,
"00010"
,
"00001"
};
const
char
*
code
[
6
]
=
{
"00000"
,
"10000"
,
"01000"
,
"00100"
,
"00010"
,
"00001"
};
this
->
switchOff
(
sGroup
,
code
[
nChannel
]);
this
->
switchOff
(
sGroup
,
code
[
nChannel
]);
}
}
...
@@ -218,7 +218,7 @@ void RCSwitch::switchOff(char* sGroup, int nChannel) {
...
@@ -218,7 +218,7 @@ void RCSwitch::switchOff(char* sGroup, int nChannel) {
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param sDevice Code of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param sDevice Code of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111")
*/
*/
void
RCSwitch
::
switchOn
(
char
*
sGroup
,
char
*
sDevice
)
{
void
RCSwitch
::
switchOn
(
const
char
*
sGroup
,
const
char
*
sDevice
)
{
this
->
sendTriState
(
this
->
getCodeWordA
(
sGroup
,
sDevice
,
true
)
);
this
->
sendTriState
(
this
->
getCodeWordA
(
sGroup
,
sDevice
,
true
)
);
}
}
...
@@ -228,7 +228,7 @@ void RCSwitch::switchOn(char* sGroup, char* sDevice) {
...
@@ -228,7 +228,7 @@ void RCSwitch::switchOn(char* sGroup, char* sDevice) {
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param sDevice Code of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param sDevice Code of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111")
*/
*/
void
RCSwitch
::
switchOff
(
char
*
sGroup
,
char
*
sDevice
)
{
void
RCSwitch
::
switchOff
(
const
char
*
sGroup
,
const
char
*
sDevice
)
{
this
->
sendTriState
(
this
->
getCodeWordA
(
sGroup
,
sDevice
,
false
)
);
this
->
sendTriState
(
this
->
getCodeWordA
(
sGroup
,
sDevice
,
false
)
);
}
}
...
@@ -252,7 +252,7 @@ char* RCSwitch::getCodeWordB(int nAddressCode, int nChannelCode, boolean bStatus
...
@@ -252,7 +252,7 @@ char* RCSwitch::getCodeWordB(int nAddressCode, int nChannelCode, boolean bStatus
int
nReturnPos
=
0
;
int
nReturnPos
=
0
;
static
char
sReturn
[
13
];
static
char
sReturn
[
13
];
char
*
code
[
5
]
=
{
"FFFF"
,
"0FFF"
,
"F0FF"
,
"FF0F"
,
"FFF0"
};
const
char
*
code
[
5
]
=
{
"FFFF"
,
"0FFF"
,
"F0FF"
,
"FF0F"
,
"FFF0"
};
if
(
nAddressCode
<
1
||
nAddressCode
>
4
||
nChannelCode
<
1
||
nChannelCode
>
4
)
{
if
(
nAddressCode
<
1
||
nAddressCode
>
4
||
nChannelCode
<
1
||
nChannelCode
>
4
)
{
return
'\0'
;
return
'\0'
;
}
}
...
@@ -282,10 +282,8 @@ char* RCSwitch::getCodeWordB(int nAddressCode, int nChannelCode, boolean bStatus
...
@@ -282,10 +282,8 @@ char* RCSwitch::getCodeWordB(int nAddressCode, int nChannelCode, boolean bStatus
/**
/**
* Returns a char[13], representing the Code Word to be send.
* Returns a char[13], representing the Code Word to be send.
*
*
* getCodeWordA(char*, char*)
*
*/
*/
char
*
RCSwitch
::
getCodeWordA
(
char
*
sGroup
,
char
*
sDevice
,
boolean
bOn
)
{
char
*
RCSwitch
::
getCodeWordA
(
const
char
*
sGroup
,
const
char
*
sDevice
,
boolean
bOn
)
{
static
char
sDipSwitches
[
13
];
static
char
sDipSwitches
[
13
];
int
i
=
0
;
int
i
=
0
;
int
j
=
0
;
int
j
=
0
;
...
@@ -330,8 +328,8 @@ char* RCSwitch::getCodeWordC(char sFamily, int nGroup, int nDevice, boolean bSta
...
@@ -330,8 +328,8 @@ char* RCSwitch::getCodeWordC(char sFamily, int nGroup, int nDevice, boolean bSta
return
'\0'
;
return
'\0'
;
}
}
char
*
sDeviceGroupCode
=
dec2binWzerofill
(
(
nDevice
-
1
)
+
(
nGroup
-
1
)
*
4
,
4
);
const
char
*
sDeviceGroupCode
=
dec2binWzerofill
(
(
nDevice
-
1
)
+
(
nGroup
-
1
)
*
4
,
4
);
char
familycode
[
16
][
5
]
=
{
"0000"
,
"F000"
,
"0F00"
,
"FF00"
,
"00F0"
,
"F0F0"
,
"0FF0"
,
"FFF0"
,
"000F"
,
"F00F"
,
"0F0F"
,
"FF0F"
,
"00FF"
,
"F0FF"
,
"0FFF"
,
"FFFF"
};
const
char
familycode
[
16
][
5
]
=
{
"0000"
,
"F000"
,
"0F00"
,
"FF00"
,
"00F0"
,
"F0F0"
,
"0FF0"
,
"FFF0"
,
"000F"
,
"F00F"
,
"0F0F"
,
"FF0F"
,
"00FF"
,
"F0FF"
,
"0FFF"
,
"FFFF"
};
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
sReturn
[
nReturnPos
++
]
=
familycode
[
(
int
)
sFamily
-
97
][
i
];
sReturn
[
nReturnPos
++
]
=
familycode
[
(
int
)
sFamily
-
97
][
i
];
}
}
...
@@ -437,7 +435,7 @@ char* RCSwitch::getCodeWordD(char sGroup, int nDevice, boolean bStatus){
...
@@ -437,7 +435,7 @@ char* RCSwitch::getCodeWordD(char sGroup, int nDevice, boolean bStatus){
/**
/**
* @param sCodeWord /^[10FS]*$/ -> see getCodeWord
* @param sCodeWord /^[10FS]*$/ -> see getCodeWord
*/
*/
void
RCSwitch
::
sendTriState
(
char
*
sCodeWord
)
{
void
RCSwitch
::
sendTriState
(
const
char
*
sCodeWord
)
{
for
(
int
nRepeat
=
0
;
nRepeat
<
nRepeatTransmit
;
nRepeat
++
)
{
for
(
int
nRepeat
=
0
;
nRepeat
<
nRepeatTransmit
;
nRepeat
++
)
{
int
i
=
0
;
int
i
=
0
;
while
(
sCodeWord
[
i
]
!=
'\0'
)
{
while
(
sCodeWord
[
i
]
!=
'\0'
)
{
...
@@ -462,7 +460,7 @@ void RCSwitch::send(unsigned long Code, unsigned int length) {
...
@@ -462,7 +460,7 @@ void RCSwitch::send(unsigned long Code, unsigned int length) {
this
->
send
(
this
->
dec2binWzerofill
(
Code
,
length
)
);
this
->
send
(
this
->
dec2binWzerofill
(
Code
,
length
)
);
}
}
void
RCSwitch
::
send
(
char
*
sCodeWord
)
{
void
RCSwitch
::
send
(
const
char
*
sCodeWord
)
{
for
(
int
nRepeat
=
0
;
nRepeat
<
nRepeatTransmit
;
nRepeat
++
)
{
for
(
int
nRepeat
=
0
;
nRepeat
<
nRepeatTransmit
;
nRepeat
++
)
{
int
i
=
0
;
int
i
=
0
;
while
(
sCodeWord
[
i
]
!=
'\0'
)
{
while
(
sCodeWord
[
i
]
!=
'\0'
)
{
...
...
This diff is collapsed.
Click to expand it.
RCSwitch.h
+
8
−
8
View file @
c9fddc27
...
@@ -60,18 +60,18 @@ class RCSwitch {
...
@@ -60,18 +60,18 @@ class RCSwitch {
void
switchOn
(
int
nGroupNumber
,
int
nSwitchNumber
);
void
switchOn
(
int
nGroupNumber
,
int
nSwitchNumber
);
void
switchOff
(
int
nGroupNumber
,
int
nSwitchNumber
);
void
switchOff
(
int
nGroupNumber
,
int
nSwitchNumber
);
void
switchOn
(
char
*
sGroup
,
int
nSwitchNumber
);
void
switchOn
(
const
char
*
sGroup
,
int
nSwitchNumber
);
void
switchOff
(
char
*
sGroup
,
int
nSwitchNumber
);
void
switchOff
(
const
char
*
sGroup
,
int
nSwitchNumber
);
void
switchOn
(
char
sFamily
,
int
nGroup
,
int
nDevice
);
void
switchOn
(
char
sFamily
,
int
nGroup
,
int
nDevice
);
void
switchOff
(
char
sFamily
,
int
nGroup
,
int
nDevice
);
void
switchOff
(
char
sFamily
,
int
nGroup
,
int
nDevice
);
void
switchOn
(
char
*
sGroup
,
char
*
sDevice
);
void
switchOn
(
const
char
*
sGroup
,
const
char
*
sDevice
);
void
switchOff
(
char
*
sGroup
,
char
*
sDevice
);
void
switchOff
(
const
char
*
sGroup
,
const
char
*
sDevice
);
void
switchOn
(
char
sGroup
,
int
nDevice
);
void
switchOn
(
char
sGroup
,
int
nDevice
);
void
switchOff
(
char
sGroup
,
int
nDevice
);
void
switchOff
(
char
sGroup
,
int
nDevice
);
void
sendTriState
(
char
*
Code
);
void
sendTriState
(
const
char
*
Code
);
void
send
(
unsigned
long
Code
,
unsigned
int
length
);
void
send
(
unsigned
long
Code
,
unsigned
int
length
);
void
send
(
char
*
Code
);
void
send
(
const
char
*
Code
);
#if not defined( RCSwitchDisableReceiving )
#if not defined( RCSwitchDisableReceiving )
void
enableReceive
(
int
interrupt
);
void
enableReceive
(
int
interrupt
);
...
@@ -99,8 +99,8 @@ class RCSwitch {
...
@@ -99,8 +99,8 @@ class RCSwitch {
private:
private:
char
*
getCodeWordB
(
int
nGroupNumber
,
int
nSwitchNumber
,
boolean
bStatus
);
char
*
getCodeWordB
(
int
nGroupNumber
,
int
nSwitchNumber
,
boolean
bStatus
);
char
*
getCodeWordA
(
char
*
sGroup
,
int
nSwitchNumber
,
boolean
bStatus
);
char
*
getCodeWordA
(
const
char
*
sGroup
,
int
nSwitchNumber
,
boolean
bStatus
);
char
*
getCodeWordA
(
char
*
sGroup
,
char
*
sDevice
,
boolean
bStatus
);
char
*
getCodeWordA
(
const
char
*
sGroup
,
const
char
*
sDevice
,
boolean
bStatus
);
char
*
getCodeWordC
(
char
sFamily
,
int
nGroup
,
int
nDevice
,
boolean
bStatus
);
char
*
getCodeWordC
(
char
sFamily
,
int
nGroup
,
int
nDevice
,
boolean
bStatus
);
char
*
getCodeWordD
(
char
group
,
int
nDevice
,
boolean
bStatus
);
char
*
getCodeWordD
(
char
group
,
int
nDevice
,
boolean
bStatus
);
void
sendT0
();
void
sendT0
();
...
...
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