Skip to content

Commit 17f20e2

Browse files
protectivedadAnthony Sepa
andauthored
new_pins: fix for inconsistent pin value on wake after sleep (#1922)
On startup PINS that conditionally processed based on g_lastValidState would be ignore if they were currently 0 regardless of the state before the module woke up. This change intializes them with the proper restored channel values. Co-authored-by: Anthony Sepa <protectivedad@gmail.com>
1 parent ec56008 commit 17f20e2

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/new_pins.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,10 +1347,8 @@ static void Channel_OnChanged(int ch, int prevValue, int iFlags) {
13471347
Channel_SaveInFlashIfNeeded(ch);
13481348
}
13491349
void CFG_ApplyChannelStartValues() {
1350-
int i;
1350+
int i, iValue;
13511351
for (i = 0; i < CHANNEL_MAX; i++) {
1352-
int iValue;
1353-
13541352
iValue = g_cfg.startChannelValues[i];
13551353
if (iValue == -1) {
13561354
g_channelValuesFloats[i] = g_channelValues[i] = HAL_FlashVars_GetChannelValue(i);
@@ -1361,6 +1359,22 @@ void CFG_ApplyChannelStartValues() {
13611359
//addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "CFG_ApplyChannelStartValues: Channel %i is being set to constant state %i", i, g_channelValues[i]);
13621360
}
13631361
}
1362+
// preload pin values from channels for pin types that look at g_lastValidState
1363+
for (i = 0; i < PLATFORM_GPIO_MAX; i++) {
1364+
switch (g_cfg.pins.roles[i]) {
1365+
case IOR_DigitalInput:
1366+
case IOR_DigitalInput_n:
1367+
case IOR_ToggleChannelOnToggle:
1368+
case IOR_DigitalInput_NoPup:
1369+
case IOR_DigitalInput_NoPup_n:
1370+
case IOR_DoorSensorWithDeepSleep:
1371+
case IOR_DoorSensorWithDeepSleep_NoPup:
1372+
case IOR_DoorSensorWithDeepSleep_pd:
1373+
iValue = g_cfg.pins.channels[i];
1374+
g_lastValidState[i] = g_channelValues[iValue];
1375+
//addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "CFG_ApplyChannelStartValues: Pin %i is being set channel state %i", i, g_channelValues[iValue]);
1376+
}
1377+
}
13641378
}
13651379
int ChannelType_GetDecimalPlaces(int type) {
13661380
int pl;

0 commit comments

Comments
 (0)