Skip to content
Snippets Groups Projects
Commit c9fddc27 authored by Max Horn's avatar Max Horn
Browse files

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
No related tags found
No related merge requests found
...@@ -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') {
......
...@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment