@@ -151,8 +151,9 @@ static const RCSwitch::Protocol PROGMEM proto[] = {
151
151
{ 340 , 0 , { 0 , 0 }, 1 , { 14 , 4 }, { 1 , 2 }, { 2 , 1 }, false , 0 }, // 33 (Dooya Control DC2708L)
152
152
{ 120 , 0 , { 0 , 0 }, 1 , { 1 , 28 }, { 1 , 3 }, { 3 , 1 }, false , 0 }, // 34 DIGOO SD10 - so as to use this protocol RCSWITCH_SEPARATION_LIMIT must be set to 2600
153
153
{ 20 , 0 , { 0 , 0 }, 1 , { 239 , 78 }, {20 , 35 }, {35 , 20 }, false , 10000 },// 35 Dooya 5-Channel blinds remote DC1603
154
- { 250 , 0 , { 0 , 0 }, 1 , { 18 , 6 }, { 1 , 3 }, { 3 , 1 }, false , 0 }, // 36 Dooya remote DC2700AC for Dooya DT82TV curtains motor
155
- { 200 , 0 , { 0 , 0 }, 0 , { 0 , 0 }, { 1 , 3 }, { 3 , 1 } , false , 20 } // 37 DEWENWILS Power Strip
154
+ { 250 , 0 , { 0 , 0 }, 1 , { 18 , 6 }, { 1 , 3 }, { 3 , 1 }, false , 0 }, // 36 Dooya remote DC2700AC for Dooya DT82TV curtains motor
155
+ { 200 , 0 , { 0 , 0 }, 0 , { 0 , 0 }, { 1 , 3 }, { 3 , 1 }, false , 20 }, // 37 DEWENWILS Power Strip
156
+ { 500 , 0 , { 0 , 0 }, 1 , { 7 , 1 }, { 2 , 1 }, { 4 , 1 }, true , 0 }, // 38 temperature and humidity sensor, various brands, nexus protocol, 36 bits + start impulse
156
157
};
157
158
158
159
enum {
@@ -166,7 +167,7 @@ volatile unsigned int RCSwitch::nReceivedBitlength = 0;
166
167
volatile unsigned int RCSwitch::nReceivedDelay = 0 ;
167
168
volatile unsigned int RCSwitch::nReceivedProtocol = 0 ;
168
169
int RCSwitch::nReceiveTolerance = 60 ;
169
- const unsigned int RCSwitch::nSeparationLimit = RCSWITCH_SEPARATION_LIMIT;
170
+ unsigned int RCSwitch::nSeparationLimit = RCSWITCH_SEPARATION_LIMIT;
170
171
unsigned int RCSwitch::timings[RCSWITCH_MAX_CHANGES];
171
172
unsigned int RCSwitch::buftimings[4 ];
172
173
#endif
@@ -238,8 +239,50 @@ void RCSwitch::setReceiveTolerance(int nPercent) {
238
239
RCSwitch::nReceiveTolerance = nPercent;
239
240
}
240
241
241
- void RCSwitch::setReceiveProtocolMask (unsigned long long mask) {
242
+ bool RCSwitch::setReceiveProtocolMask (unsigned long long mask) {
242
243
RCSwitch::nReceiveProtocolMask = mask;
244
+ return updateSeparationLimit ();
245
+ }
246
+
247
+ bool RCSwitch::updateSeparationLimit ()
248
+ {
249
+ unsigned int longestPulseTime = std::numeric_limits<unsigned int >::max ();
250
+ unsigned int shortestPulseTime = 0 ;
251
+
252
+ unsigned long long thisMask = 1 ;
253
+ for (unsigned int i = 0 ; i < numProto; i++) {
254
+ if (RCSwitch::nReceiveProtocolMask & thisMask) {
255
+ const unsigned int headerShortPulseCount = std::min (proto[i].Header .high , proto[i].Header .low );
256
+ const unsigned int headerLongPulseCount = std::max (proto[i].Header .high , proto[i].Header .low );
257
+
258
+ // This must be the longest pulse-length of this protocol. nSeparationLimit must of this length or shorter.
259
+ // This pulse will be used to detect the beginning of a transmission.
260
+ const unsigned int headerLongPulseTime = proto[i].pulseLength * headerLongPulseCount;
261
+
262
+ // nSeparationLimit must be longer than any of the following pulses to avoid detecting a new transmission in the middle of a frame.
263
+ unsigned int longestDataPulseCount = headerShortPulseCount;
264
+ longestDataPulseCount = std::max<unsigned int >(longestDataPulseCount, proto[i].zero .high );
265
+ longestDataPulseCount = std::max<unsigned int >(longestDataPulseCount, proto[i].zero .low );
266
+ longestDataPulseCount = std::max<unsigned int >(longestDataPulseCount, proto[i].one .high );
267
+ longestDataPulseCount = std::max<unsigned int >(longestDataPulseCount, proto[i].one .low );
268
+
269
+ const unsigned int longestDataPulseTime = proto[i].pulseLength * longestDataPulseCount;
270
+
271
+ longestPulseTime = std::min (longestPulseTime, headerLongPulseTime);
272
+ shortestPulseTime = std::max (shortestPulseTime, longestDataPulseTime);
273
+ }
274
+ thisMask <<= 1 ;
275
+ }
276
+
277
+ if (longestPulseTime <= shortestPulseTime) {
278
+ // incompatible protocols enabled, fall back to default value
279
+ nSeparationLimit = RCSWITCH_SEPARATION_LIMIT;
280
+ return false ;
281
+ }
282
+
283
+ const unsigned int timeDiff = longestPulseTime - shortestPulseTime;
284
+ nSeparationLimit = longestPulseTime - (timeDiff / 2 );
285
+ return true ;
243
286
}
244
287
#endif
245
288
0 commit comments