Browse Source

gpio: notify about failed locks

pull/2584/head
Maxim Prokhorov 1 year ago
parent
commit
3a1e041f51
23 changed files with 15895 additions and 15793 deletions
  1. BIN
      code/espurna/data/index.all.html.gz
  2. BIN
      code/espurna/data/index.curtain.html.gz
  3. BIN
      code/espurna/data/index.garland.html.gz
  4. BIN
      code/espurna/data/index.light.html.gz
  5. BIN
      code/espurna/data/index.lightfox.html.gz
  6. BIN
      code/espurna/data/index.rfbridge.html.gz
  7. BIN
      code/espurna/data/index.rfm69.html.gz
  8. BIN
      code/espurna/data/index.sensor.html.gz
  9. BIN
      code/espurna/data/index.small.html.gz
  10. BIN
      code/espurna/data/index.thermostat.html.gz
  11. +28
    -14
      code/espurna/gpio.cpp
  12. +9
    -4
      code/espurna/gpio.h
  13. +2311
    -2304
      code/espurna/static/index.all.html.gz.h
  14. +1439
    -1433
      code/espurna/static/index.curtain.html.gz.h
  15. +1412
    -1406
      code/espurna/static/index.garland.html.gz.h
  16. +2008
    -2001
      code/espurna/static/index.light.html.gz.h
  17. +1392
    -1386
      code/espurna/static/index.lightfox.html.gz.h
  18. +1447
    -1441
      code/espurna/static/index.rfbridge.html.gz.h
  19. +1444
    -1438
      code/espurna/static/index.rfm69.html.gz.h
  20. +1546
    -1540
      code/espurna/static/index.sensor.html.gz.h
  21. +1397
    -1391
      code/espurna/static/index.small.html.gz.h
  22. +1434
    -1428
      code/espurna/static/index.thermostat.html.gz.h
  23. +28
    -7
      code/html/custom.js

BIN
code/espurna/data/index.all.html.gz View File


BIN
code/espurna/data/index.curtain.html.gz View File


BIN
code/espurna/data/index.garland.html.gz View File


BIN
code/espurna/data/index.light.html.gz View File


BIN
code/espurna/data/index.lightfox.html.gz View File


BIN
code/espurna/data/index.rfbridge.html.gz View File


BIN
code/espurna/data/index.rfm69.html.gz View File


BIN
code/espurna/data/index.sensor.html.gz View File


BIN
code/espurna/data/index.small.html.gz View File


BIN
code/espurna/data/index.thermostat.html.gz View File


+ 28
- 14
code/espurna/gpio.cpp View File

@ -621,6 +621,19 @@ private:
Mask _mask;
};
namespace origin {
namespace internal {
std::forward_list<Origin> origins;
} // namespace internal
void add(Origin origin) {
internal::origins.emplace_front(origin);
}
} // namespace origin
#if WEB_SUPPORT
namespace web {
@ -651,6 +664,19 @@ void onVisible(JsonObject& root) {
}
}
}
JsonObject& info = root.createNestedObject(F("gpioInfo"));
JsonArray& locks = info.createNestedArray(F("failed-locks"));
for (auto& origin : origin::internal::origins) {
if (!origin.result) {
JsonArray& entry = locks.createNestedArray();
entry.add(origin.pin);
entry.add(origin.location.file);
entry.add(origin.location.func);
entry.add(origin.location.line);
}
}
}
void setup() {
@ -661,19 +687,6 @@ void setup() {
} // namespace web
#endif
namespace origin {
namespace internal {
std::forward_list<Origin> origins;
} // namespace internal
void add(Origin origin) {
internal::origins.emplace_front(origin);
}
} // namespace origin
#if TERMINAL_SUPPORT
namespace terminal {
@ -681,7 +694,8 @@ PROGMEM_STRING(GpioLocks, "GPIO.LOCKS");
void gpio_list_origins(::terminal::CommandContext&& ctx) {
for (const auto& origin : origin::internal::origins) {
ctx.output.printf_P(PSTR("%c %s GPIO%hhu\t%d:%s:%s\n"),
ctx.output.printf_P(PSTR("%c %c %s GPIO%hhu\t%d:%s:%s\n"),
origin.result ? ' ' : '!',
origin.lock ? '*' : ' ',
origin.base, origin.pin,
origin.location.line,


+ 9
- 4
code/espurna/gpio.h View File

@ -26,6 +26,7 @@ struct Origin {
const char* base;
uint8_t pin;
bool lock;
bool result;
SourceLocation location;
};
@ -85,16 +86,20 @@ inline bool gpioLock(GpioBase& base, unsigned char pin, bool value,
espurna::SourceLocation source_location = espurna::make_source_location())
{
if (base.valid(pin)) {
const auto old = base.lock(pin);
base.lock(pin, value);
const auto result = value != old;
gpioLockOrigin(espurna::gpio::Origin{
.base = base.id(),
.pin = pin,
.lock = value,
.location = trim_source_location(source_location)
.result = result,
.location = trim_source_location(source_location),
});
bool old = base.lock(pin);
base.lock(pin, value);
return (value != old);
return result;
}
return false;


+ 2311
- 2304
code/espurna/static/index.all.html.gz.h
File diff suppressed because it is too large
View File


+ 1439
- 1433
code/espurna/static/index.curtain.html.gz.h
File diff suppressed because it is too large
View File


+ 1412
- 1406
code/espurna/static/index.garland.html.gz.h
File diff suppressed because it is too large
View File


+ 2008
- 2001
code/espurna/static/index.light.html.gz.h
File diff suppressed because it is too large
View File


+ 1392
- 1386
code/espurna/static/index.lightfox.html.gz.h
File diff suppressed because it is too large
View File


+ 1447
- 1441
code/espurna/static/index.rfbridge.html.gz.h
File diff suppressed because it is too large
View File


+ 1444
- 1438
code/espurna/static/index.rfm69.html.gz.h
File diff suppressed because it is too large
View File


+ 1546
- 1540
code/espurna/static/index.sensor.html.gz.h
File diff suppressed because it is too large
View File


+ 1397
- 1391
code/espurna/static/index.small.html.gz.h
File diff suppressed because it is too large
View File


+ 1434
- 1428
code/espurna/static/index.thermostat.html.gz.h
File diff suppressed because it is too large
View File


+ 28
- 7
code/html/custom.js View File

@ -137,10 +137,10 @@ function magnitudeTypedKey(magnitude, name) {
// Utils
// -----------------------------------------------------------------------------
function notifyError(message, source, lineno, colno, error) {
function showErrorNotification(message) {
let container = document.getElementById("error-notification");
if (container.childElementCount > 0) {
return;
return false;
}
container.style.display = "inherit";
@ -149,15 +149,24 @@ function notifyError(message, source, lineno, colno, error) {
let notification = document.createElement("div");
notification.classList.add("pure-u-1");
notification.classList.add("pure-u-lg-1");
notification.textContent = message;
container.appendChild(notification);
return false;
}
function notifyError(message, source, lineno, colno, error) {
let text = "";
if (error) {
notification.textContent += error.stack;
text = error.stack;
} else {
notification.textContent += message;
text = message;
}
notification.textContent += "\n\nFor more info see the Developer Tools console.";
container.appendChild(notification);
return false;
text += "\n\nFor more info see the Debug Log and / or Developer Tools console.";
return showErrorNotification(text);
}
window.onerror = notifyError;
@ -2556,6 +2565,18 @@ function processData(data) {
return;
}
if ("gpioInfo" === key) {
let failed = "Could not acquire locks on the following pins, check configuration\n\n";
for (const [pin, file, func, line] of value["failed-locks"]) {
failed += `GPIO${pin} @ ${file}:${func}:${line}\n`;
}
if (failed.length > 0) {
showErrorNotification(failed);
}
return;
}
// ---------------------------------------------------------------------
// Actions
// ---------------------------------------------------------------------


Loading…
Cancel
Save