Bug fix for the archtech protocol.
Former-commit-id: a432362fdfa1d8b95d32fe72930006302d113ea1
This commit is contained in:
parent
efadc097ce
commit
70b1608dd8
1 changed files with 35 additions and 30 deletions
|
|
@ -23,8 +23,8 @@ Total: 32 or 36 bits depending if absolute dimming is used
|
||||||
|
|
||||||
Each real bit in the data field is sent over air as a pair of two inverted bits.
|
Each real bit in the data field is sent over air as a pair of two inverted bits.
|
||||||
real bit bits over air
|
real bit bits over air
|
||||||
1 = "01"
|
1 = "10"
|
||||||
0 = "10"
|
0 = "01"
|
||||||
|
|
||||||
Over air a "1"(one) is sent as:
|
Over air a "1"(one) is sent as:
|
||||||
send high for 250 microseconds
|
send high for 250 microseconds
|
||||||
|
|
@ -44,61 +44,66 @@ send low for 10,000 microseconds
|
||||||
#define ARCHTECH_SHORT_MAX 7
|
#define ARCHTECH_SHORT_MAX 7
|
||||||
#define ARCHTECH_LONG_MIN 17
|
#define ARCHTECH_LONG_MIN 17
|
||||||
#define ARCHTECH_LONG_MAX 27
|
#define ARCHTECH_LONG_MAX 27
|
||||||
|
#define ARCHTECH_PREAMP_MIN 40
|
||||||
|
#define ARCHTECH_PREAMP_MAX 48
|
||||||
|
|
||||||
#define IS_SHORT(b) ( ARCHTECH_SHORT_MIN <= b && b <= ARCHTECH_SHORT_MAX )
|
#define IS_SHORT(b) ( ARCHTECH_SHORT_MIN <= b && b <= ARCHTECH_SHORT_MAX )
|
||||||
#define IS_LONG(b) ( ARCHTECH_LONG_MIN <= b && b <= ARCHTECH_LONG_MAX )
|
#define IS_LONG(b) ( ARCHTECH_LONG_MIN <= b && b <= ARCHTECH_LONG_MAX )
|
||||||
|
#define IS_PREAMP_LONG(b) ( ARCHTECH_PREAMP_MIN <= b && b <= ARCHTECH_PREAMP_MAX )
|
||||||
|
|
||||||
#define IS_ZERO(b1,b2,b3,b4) ( IS_SHORT(b1) && IS_LONG(b2) && IS_SHORT(b3) && IS_SHORT(b4) )
|
#define IS_ONE(b1,b2,b3,b4) ( IS_SHORT(b1) && IS_LONG(b2) && IS_SHORT(b3) && IS_SHORT(b4) )
|
||||||
#define IS_ONE(b1,b2,b3,b4) ( IS_SHORT(b1) && IS_SHORT(b2) && IS_SHORT(b3) && IS_LONG(b4) )
|
#define IS_ZERO(b1,b2,b3,b4) ( IS_SHORT(b1) && IS_SHORT(b2) && IS_SHORT(b3) && IS_LONG(b4) )
|
||||||
|
#define IS_PREAMP(b1,b2) ( IS_SHORT(b1) && IS_PREAMP_LONG(b2) )
|
||||||
|
|
||||||
bool parseArctechSelfLearning(uint8_t* bufStartP, uint8_t* bufEndP) { //start points to a "high" buffer byte, end points to a "low" buffer byte
|
bool parseArctechSelfLearning(uint8_t* bufStartP, uint8_t* bufEndP) { //start points to a "high" buffer byte, end points to a "low" buffer byte
|
||||||
uint64_t data = 0;
|
uint64_t data = 0;
|
||||||
bool dimValuePresent;
|
bool dimValuePresent;
|
||||||
|
uint8_t b1,b2,b3,b4;
|
||||||
|
|
||||||
uint16_t bitsInBuffer = calculateBufferPointerDistance(bufStartP, bufEndP) / 4; //each bit is representd by 4 high/low
|
//parse preamp
|
||||||
//Serial.print("bits in buffer: "); Serial.print(bitsInBuffer); Serial.print(" - ");
|
|
||||||
if (bitsInBuffer == 33) {
|
b1 = *bufStartP;
|
||||||
//Serial.println("default");
|
stepBufferPointer(&bufStartP);
|
||||||
dimValuePresent = false;
|
b2 = *bufStartP;
|
||||||
}else if(bitsInBuffer == 37){
|
stepBufferPointer(&bufStartP);
|
||||||
//Serial.println("with dim");
|
if(!IS_PREAMP(b1, b2)){
|
||||||
dimValuePresent = true;
|
|
||||||
} else {
|
|
||||||
//Serial.println("ignore");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//stkip two buffers entries.
|
//parse data
|
||||||
stepBufferPointer(&bufStartP);
|
|
||||||
stepBufferPointer(&bufStartP);
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < bitsInBuffer-1; ++i) {
|
uint16_t dataBitsInBuffer = (calculateBufferPointerDistance(bufStartP, bufEndP)-2) / 4; //each bit is representd by 4 high/low
|
||||||
|
if (dataBitsInBuffer == 32) {
|
||||||
|
dimValuePresent = false;
|
||||||
|
}else if(dataBitsInBuffer == 36){
|
||||||
|
dimValuePresent = true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t b1 = *bufStartP; //no of high
|
for (uint8_t i = 0; i < dataBitsInBuffer; ++i) {
|
||||||
|
b1 = *bufStartP; //no of high
|
||||||
stepBufferPointer(&bufStartP);
|
stepBufferPointer(&bufStartP);
|
||||||
uint8_t b2 = *bufStartP; //no of low
|
b2 = *bufStartP; //no of low
|
||||||
stepBufferPointer(&bufStartP);
|
stepBufferPointer(&bufStartP);
|
||||||
uint8_t b3 = *bufStartP; //no of high
|
b3 = *bufStartP; //no of high
|
||||||
stepBufferPointer(&bufStartP);
|
stepBufferPointer(&bufStartP);
|
||||||
uint8_t b4 = *bufStartP; //no of low
|
b4 = *bufStartP; //no of low
|
||||||
stepBufferPointer(&bufStartP);
|
stepBufferPointer(&bufStartP);
|
||||||
|
|
||||||
//Serial.print(b1); Serial.print(", ");Serial.print(b2); Serial.print(", ");Serial.print(b3); Serial.print(", ");Serial.print(b4);
|
|
||||||
|
|
||||||
if (IS_ONE(b1,b2,b3,b4)) { //"one" is sent over air
|
if (IS_ONE(b1,b2,b3,b4)) { //"one" is sent over air
|
||||||
//Serial.println(" --> 1");
|
|
||||||
data <<= 1; //shift in a zero
|
data <<= 1; //shift in a zero
|
||||||
data |= 0x1; //add one
|
data |= 0x1; //add one
|
||||||
} else if (IS_ZERO(b1,b2,b3,b4)) { //"zero" is sent over air
|
} else if (IS_ZERO(b1,b2,b3,b4)) { //"zero" is sent over air
|
||||||
//Serial.println(" --> 0");
|
|
||||||
data <<= 1; //shift in a zero
|
data <<= 1; //shift in a zero
|
||||||
} else {
|
} else {
|
||||||
//Serial.println(" --> CORRUPT");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//data parsed - send event over serial
|
||||||
|
|
||||||
Serial.print(F("+Wclass:command;protocol:arctech;model:selflearning;data:0x"));
|
Serial.print(F("+Wclass:command;protocol:arctech;model:selflearning;data:0x"));
|
||||||
uint8_t hexToSend = (dimValuePresent ? 9 : 8);
|
uint8_t hexToSend = (dimValuePresent ? 9 : 8);
|
||||||
for (int8_t i = hexToSend - 1; i >= 0; --i) {
|
for (int8_t i = hexToSend - 1; i >= 0; --i) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue