Changed the logic for calculating IKEA-dim message.

This commit is contained in:
Micke Prag 2008-02-16 13:12:56 +00:00
parent fc72421616
commit e7512dbe2e

View file

@ -90,10 +90,10 @@ string DeviceIkea::getStringCode(unsigned char level){
for (int i = 13; i >= 0; --i) { for (int i = 13; i >= 0; --i) {
if ((intCode>>i) & 1) { if ((intCode>>i) & 1) {
strChannels.append("TT"); strChannels.append("TT");
if (13 % 2 == 0) if (i % 2 == 0)
checksum2++;
else
checksum1++; checksum1++;
else
checksum2++;
} else { } else {
strChannels.append("ª"); strChannels.append("ª");
} }
@ -103,22 +103,58 @@ string DeviceIkea::getStringCode(unsigned char level){
strReturn.append(checksum1 %2 == 0 ? "TT" : "ª"); //1st checksum strReturn.append(checksum1 %2 == 0 ? "TT" : "ª"); //1st checksum
strReturn.append(checksum2 %2 == 0 ? "TT" : "ª"); //2nd checksum strReturn.append(checksum2 %2 == 0 ? "TT" : "ª"); //2nd checksum
int intLevel = 0;
if (level <= 12) { if (level <= 12) {
strReturn.append("ªTTªTT"); //Level 0 - Off intLevel = 10; // Level 10 is actually off
} else if (level <= 37) {
intLevel = 1;
} else if (level <= 62) {
intLevel = 2;
} else if (level <= 87) {
intLevel = 3;
} else if (level <= 112) {
intLevel = 4;
} else if (level <= 137) { } else if (level <= 137) {
strReturn.append("TTªTTª"); //Level 5 intLevel = 5;
} else if (level <= 162) { } else if (level <= 162) {
strReturn.append("ªTTTTª"); //Level 6 intLevel = 6;
} else if (level <= 187) {
intLevel = 7;
} else if (level <= 212) {
intLevel = 8;
} else if (level <= 237) {
intLevel = 9;
} else { } else {
strReturn.append("ªªªª"); //Level 10 - On intLevel = 0; // Level 0 is actually full on
} }
if (intFadeStyle == 1) int intFade = 0;
strReturn.append("TTTTªª"); //Smooth if (intFadeStyle == 1) {
else intFade = 11 << 4; //Smooth
strReturn.append("TTªªTT"); //Instant } else {
strReturn.append("+"); intFade = 1 << 4; //Instant
}
intCode = intLevel | intFade; //Concat level and fade
checksum1 = 0;
checksum2 = 0;
for (int i = 0; i < 6; ++i) {
if ((intCode>>i) & 1) {
strReturn.append("TT");
if (i % 2 == 0)
checksum1++;
else
checksum2++;
} else {
strReturn.append("ª");
}
}
strReturn.append(checksum1 %2 == 0 ? "TT" : "ª"); //1st checksum
strReturn.append(checksum2 %2 == 0 ? "TT" : "ª"); //2nd checksum
strReturn.append("+");
} }
catch(...){ catch(...){
throw; throw;