You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
boolblockBruteForce(longpressTimeMs) { // call only on press (not release)!
269
273
boolallow= true;
270
274
staticintcount=0;
271
-
if (pressTimeMs>30000) // if released for 30s, re-allow unlocking
272
-
{
275
+
if (pressTimeMs>30000){ // if released for 30s, re-allow unlocking
273
276
allow= true;
274
277
count=0;
275
-
fprintf(stderr, "Unlocking re-allowed for 3 attempts!\n");
278
+
HAPLogInfo(&kHAPLog_Default, "%s: Unlocking re-allowed for 3 attempts", __func__);
276
279
}
277
280
count++;
278
-
if (count>3) {
279
-
281
+
if (count>3){
280
282
allow= false; // after the third (i.e. at the fourth) ring, disallow unlocking the door for some time
281
283
count--; // prevent overflow, i.e. go back to 2
282
-
fprintf(stderr, "Unlocking disallowed for 30s!\n"); // called after start of pressing, so pressTimeMs is actually a release time
283
-
284
+
HAPLogInfo(&kHAPLog_Default, "%s: Unlocking disallowed for 30s", __func__); // called after start of pressing, so pressTimeMs is actually a release time
voiddecodePattern(boolpress) { // bei press (true) und release (false) aufrufen
373
+
voiddecodePattern(boolpress) { // call for press (true) and release (false) of bell button
379
374
staticstructtimevaltimeStart, timeEnd;
380
375
381
376
@@ -384,32 +379,25 @@ void decodePattern(bool press) { // bei press (true) und release (false) aufrufe
384
379
+ (timeEnd.tv_usec-timeStart.tv_usec) / 1000);
385
380
timeStart=timeEnd;
386
381
387
-
fprintf(stderr, "%stime was = %ld ms = ", !press ? "press" : "release",
382
+
HAPLogInfo(&kHAPLog_Default, "%s: %s time was = %ld ms = ", __func__, (!press ? "press" : "release"),
388
383
pressTimeMs); // !press, because we lag behind
389
-
// NOTE: first value of pressTimeMs will be large negative
384
+
385
+
// NOTE: first value of pressTimeMs (after startup or long idle time) can be anything (even overflow to negative), but it is ignored in the state machine
390
386
391
387
/* NEED TO DEBOUNCE! And need to distinguish falling and rising IRQs properly.
392
388
* Reading the input at the beginning of the ISR may be too slow, i.e. the level is no longer the one that triggered the IRQ.
393
-
* Workaround: use two inputs in parallel, one ofr rising, another one for falling edge detection. */
394
-
395
-
389
+
* Possible workaround: use two inputs in parallel, one for rising, another one for falling edge detection. */
396
390
397
-
boolisAny= (pressTimeMs <= anyMax) && (pressTimeMs >= anyMin); // nach oben begrenzt, damit kein Zustand ewig stehenbleiben kann! Nach spätestens 10s matched auch Any nicht mehr, d.h. ein press-Event führt zum state RING.
398
391
399
-
boolisShort= (pressTimeMs <= shortMax) && (pressTimeMs >= shortMin); // less than half a second
400
-
boolisLong= (pressTimeMs <= longMax) && (pressTimeMs >= longMin); // about one seconds
401
-
boolisVeryLong= (pressTimeMs <= veryLongMax) && (pressTimeMs >= veryLongMin); // about two seconds
boolisAny= (pressTimeMs <= anyMax) && (pressTimeMs >= anyMin); // upper limit anyMax ensures that no state is kept forever: when anyMax is exceeded when expecting ANY duration, the next press/release event leads to the RING state
393
+
boolisShort= (pressTimeMs <= shortMax) && (pressTimeMs >= shortMin); // e.g. less than half a second
394
+
boolisLong= (pressTimeMs <= longMax) && (pressTimeMs >= longMin); // e.g. about one seconds
395
+
boolisVeryLong= (pressTimeMs <= veryLongMax) && (pressTimeMs >= veryLongMin); // e.g. about two seconds
@@ -471,23 +459,19 @@ void decodePattern(bool press) { // bei press (true) und release (false) aufrufe
471
459
}
472
460
}
473
461
} else {
474
-
fprintf(stderr, "state overflow error"); // this should not ever happen - sizeof(code) must be odd (odd number of press times plus even number of release times)
462
+
HAPLogInfo(&kHAPLog_Default, "%s: state overflow error", __func__); // this should not ever happen - sizeof(code) must be odd (odd number of press times plus even number of release times)
0 commit comments