Skip to content

Commit a8b289b

Browse files
committed
Add time dependency for package drop
1 parent fe314c0 commit a8b289b

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

src/autoClose.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ typedef enum {
1818
AC_WAIT = 3,
1919
AC_CLOSE = 4,
2020
AC_ABORT_WAIT = 5,
21+
PD_CORRECT_ERROR = 10,
2122
PD_START = 11,
2223
PD_GOTO_VENTING = 12,
2324
PD_WAIT = 13
@@ -37,9 +38,16 @@ void ac_trigger() {
3738

3839

3940
void pd_trigger() {
40-
if (acState == AC_INIT) {
41+
if (acState == AC_INIT && (uap_getBroadcast() & UAP_STATUS_CLOSED)) {
4142
LOG(m, "Start Paketdienst", "");
42-
acState = PD_START;
43+
if (uap_getBroadcast() & UAP_STATUS_ERROR) {
44+
// if an error is present, then it's not possible to go directly to venting. Send first a "close", wait and then start as usual
45+
uap_triggerAction(UAP_ACTION_CLOSE, SRC_AUTOCLOSE);
46+
acState = PD_CORRECT_ERROR;
47+
acTimer = millis();
48+
} else {
49+
acState = PD_START;
50+
}
4351
}
4452
}
4553

@@ -64,7 +72,6 @@ void ac_loop() {
6472
lastCall = millis();
6573

6674
uint32_t seconds = log_getSecSinceMidnight();
67-
6875
if ((seconds >= (uint32_t)cfgAcTime * 3600) && (seconds <= (uint32_t)cfgAcTime * 3600 + AC_TRIGGER_INTERVAL / 1000)) {
6976
// check for a 5s time-window to safely detect, but not trigger multiple times
7077
ac_trigger();
@@ -115,6 +122,12 @@ void ac_loop() {
115122
}
116123

117124

125+
case PD_CORRECT_ERROR: {
126+
if (millis() - acTimer > cfgPdWaitError) {
127+
acState = PD_START;
128+
}
129+
break;
130+
}
118131
case PD_START: {
119132
// start the first movement, e.g. a short closing to warn
120133
uap_triggerAction(UAP_ACTION_VENTING, SRC_AUTOCLOSE);

src/globalConfig.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
const uint8_t m = 1;
1010

1111
char cfgHgdoVersion[] = "v0.1.0"; // hgdo version
12-
char cfgBuildDate[] = "2021-10-30"; // hgdo build date
12+
char cfgBuildDate[] = "2021-10-31"; // hgdo build date
1313

1414
char cfgApSsid[32]; // SSID of the initial Access Point
1515
char cfgApPass[63]; // Password of the initial Access Point
@@ -21,8 +21,11 @@ uint16_t cfgBtnDebounce; // Debounce time for button [ms]
2121
uint8_t cfgAcTime; // Hour to start the auto-close [h]
2222
uint8_t cfgAcDur1; // Duration of the auto-close PREWARN phase [s]
2323
uint8_t cfgAcDur2; // Duration of the auto-close WAIT phase [s]
24+
uint8_t cfgPdTimeOn; // Hour to enable package drop function
25+
uint8_t cfgPdTimeOff; // Hour to disable package drop function
2426
uint8_t cfgPdWaitTime; // Duration of the package drop WAIT phase [s]
2527
uint8_t cfgPdTimeout; // Timeout of the package drop function, when venting position is missed [s]
28+
uint16_t cfgPdWaitError; // Wait time for error correction before start [ms]
2629
uint8_t cfgHwVersion; // Selection of the used HW
2730
uint8_t cfgLogMonths; // Months to be logged
2831
uint8_t cfgTrace; // 0: disable Trace Feature, 1: enable
@@ -106,8 +109,11 @@ void loadConfig() {
106109
cfgAcTime = doc["cfgAcTime"] | 24;
107110
cfgAcDur1 = doc["cfgAcDur1"] | 2;
108111
cfgAcDur2 = doc["cfgAcDur2"] | 30;
112+
cfgPdTimeOn = doc["cfgPdTimeOn"] | 24;
113+
cfgPdTimeOff = doc["cfgPdTimeOff"] | 0;
109114
cfgPdWaitTime = doc["cfgPdWaitTime"] | 15;
110115
cfgPdTimeout = doc["cfgPdTimeout"] | 10;
116+
cfgPdWaitError = doc["cfgPdWaitError"] | 200;
111117
cfgHwVersion = doc["cfgHwVersion"] | 20;
112118
cfgLogMonths = doc["cfgLogMonths"] | 0;
113119
cfgTrace = doc["cfgTrace"] | 0;

src/globalConfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ extern uint16_t cfgBtnDebounce; // Debounce time for button [ms]
2525
extern uint8_t cfgAcTime; // Hour to start the auto-close [h]
2626
extern uint8_t cfgAcDur1; // Duration of the auto-close PREWARN phase [s]
2727
extern uint8_t cfgAcDur2; // Duration of the auto-close WAIT phase [s]
28+
extern uint8_t cfgPdTimeOn; // Hour to enable package drop function
29+
extern uint8_t cfgPdTimeOff; // Hour to disable package drop function
2830
extern uint8_t cfgPdWaitTime; // Duration of the package drop WAIT phase [s]
2931
extern uint8_t cfgPdTimeout; // Timeout of the package drop function, when venting position is missed [s]
32+
extern uint16_t cfgPdWaitError; // Wait time for error correction before start [ms]
3033
extern uint8_t cfgHwVersion; // Selection of the used HW
3134
extern uint8_t cfgLogMonths; // Months to be logged
3235
extern uint8_t cfgTrace; // 0: disable Trace Feature, 1: enable

src/keyPanel.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ static void checkCode(char * input) {
110110
uap_triggerAction(UAP_ACTION_OPEN, SRC_KEYPAD); break;
111111
}
112112
case 1: {
113-
//start the package drop function
114-
pd_trigger(); break;
113+
//start the package drop function, if time is within the allowed range
114+
uint32_t seconds = log_getSecSinceMidnight();
115+
if ((seconds >= (uint32_t)cfgPdTimeOn * 3600) && (seconds < (uint32_t)cfgPdTimeOff * 3600)) {
116+
pd_trigger();
117+
}
118+
break;
115119
}
116120
default: ; // nothing
117121
}

0 commit comments

Comments
 (0)