Skip to content

Commit

Permalink
added web elements of momentary state for homekit simple gpio
Browse files Browse the repository at this point in the history
  • Loading branch information
rednblkx committed Aug 23, 2024
1 parent f34b3e2 commit 23f5328
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
13 changes: 13 additions & 0 deletions data/actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ <h3 style="margin: 0 0 1rem;align-self: flex-start;">Simple GPIO</h3>
<label for="gpio-a-pin">GPIO Pin</label>
<input type="number" name="gpio-a-pin" id="gpio-a-pin" placeholder="2" required value="%GPIOAPIN%" style="width: 4rem;" min="0" max="255">
</div>
<div style="display: flex;margin-top: .7rem;gap: 8px;">
<label for="gpio-a-momentary">Momentary State</label>
<select name="gpio-a-momentary" id="gpio-a-momentary">
<option value="0">Disabled</option>
<option value="1">Enabled</option>
</select>
</div>
<div style="display: flex;margin-top: .7rem;gap: 8px;">
<label for="gpio-a-mo-timeout">Momentary Timeout</label>
<input type="number" name="gpio-a-mo-timeout" id="gpio-a-mo-timeout" placeholder="2" required value="%GPIOAMOTIME%" style="width: 4rem;">
</div>
<div style="display: flex;margin-top: .7rem;gap: 8px;">
<label for="gpio-a-lock">GPIO State - Locked</label>
<select name="gpio-a-lock" id="gpio-a-lock">
Expand All @@ -148,10 +159,12 @@ <h3 style="margin: 0 0 1rem;align-self: flex-start;">Simple GPIO</h3>
let nfcfhl = document.querySelector("#nfc-f-hl");
let actionunlock = document.querySelector("#gpio-a-unlock");
let actionlock = document.querySelector("#gpio-a-lock");
let actionMomentary = document.querySelector("#gpio-a-momentary");
nfcshl.selectedIndex = "%NFC1HL%";
nfcfhl.selectedIndex = "%NFC2HL%";
actionlock.selectedIndex = "%GPIOALOCK%";
actionunlock.selectedIndex = "%GPIOALOCK%";
actionMomentary.selectedIndex = "%GPIOAMOEN%";
let form = document.getElementById("actions-config");
async function handleForm(event) {
event.preventDefault();
Expand Down
4 changes: 3 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ enum customLockActions
#define NFC_FAIL_TIME 1000 // How long should NFC_FAIL_PIN be held High or Low
#define GPIO_ACTION_PIN 255
#define GPIO_ACTION_LOCK_STATE LOW
#define GPIO_ACTION_UNLOCK_STATE HIGH
#define GPIO_ACTION_UNLOCK_STATE HIGH
#define GPIO_ACTION_MOMENTARY_STATE false
#define GPIO_ACTION_MOMENTARY_TIMEOUT 5000
16 changes: 15 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ namespace espConfig
uint8_t gpioActionPin = GPIO_ACTION_PIN;
bool gpioActionLockState = GPIO_ACTION_LOCK_STATE;
bool gpioActionUnlockState = GPIO_ACTION_UNLOCK_STATE;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(misc_config_t, deviceName, otaPasswd, hk_key_color, setupCode, lockAlwaysUnlock, lockAlwaysLock, controlPin, hsStatusPin, nfcSuccessPin, nfcSuccessTime, nfcNeopixelPin, neopixelSuccessColor, neopixelFailureColor, neopixelSuccessTime, neopixelFailTime, nfcSuccessHL, nfcFailPin, nfcFailTime, nfcFailHL, gpioActionPin, gpioActionLockState, gpioActionUnlockState)
bool gpioActionMomentaryEnabled = GPIO_ACTION_MOMENTARY_STATE;
uint16_t gpioActionMomentaryTimeout = GPIO_ACTION_MOMENTARY_TIMEOUT;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(misc_config_t, deviceName, otaPasswd, hk_key_color, setupCode, lockAlwaysUnlock, lockAlwaysLock, controlPin, hsStatusPin, nfcSuccessPin, nfcSuccessTime, nfcNeopixelPin, neopixelSuccessColor, neopixelFailureColor, neopixelSuccessTime, neopixelFailTime, nfcSuccessHL, nfcFailPin, nfcFailTime, nfcFailHL, gpioActionPin, gpioActionLockState, gpioActionUnlockState, gpioActionMomentaryEnabled, gpioActionMomentaryTimeout)
} miscConfig;
};

Expand Down Expand Up @@ -795,6 +797,12 @@ String actionsProcess(const String& var) {
else if (var == "GPIOAUNLOCK") {
return String(espConfig::miscConfig.gpioActionUnlockState);
}
else if (var == "GPIOAMOEN") {
return String(espConfig::miscConfig.gpioActionMomentaryEnabled);
}
else if (var == "GPIOAMOTIME") {
return String(espConfig::miscConfig.gpioActionMomentaryTimeout);
}
else if (var == "NEOSTIME") {
return String(espConfig::miscConfig.neopixelSuccessTime);
}
Expand Down Expand Up @@ -1047,6 +1055,12 @@ void setupWeb() {
else if (!strcmp(p->name().c_str(), "gpio-a-unlock")) {
espConfig::miscConfig.gpioActionUnlockState = p->value().toInt();
}
else if (!strcmp(p->name().c_str(), "gpio-a-momentary")) {
espConfig::miscConfig.gpioActionMomentaryEnabled = p->value().toInt();
}
else if (!strcmp(p->name().c_str(), "gpio-a-mo-timeout")) {
espConfig::miscConfig.gpioActionMomentaryTimeout = p->value().toInt();
}
}
try {
json json_misc_config = espConfig::miscConfig;
Expand Down

0 comments on commit 23f5328

Please sign in to comment.