Skip to content

Commit

Permalink
gpio: notify about failed locks
Browse files Browse the repository at this point in the history
  • Loading branch information
mcspr committed Mar 16, 2023
1 parent 704ddc4 commit 3a1e041
Show file tree
Hide file tree
Showing 23 changed files with 15,895 additions and 15,793 deletions.
Binary file modified code/espurna/data/index.all.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.curtain.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.garland.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.light.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.lightfox.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfbridge.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfm69.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.sensor.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.small.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.thermostat.html.gz
Binary file not shown.
42 changes: 28 additions & 14 deletions code/espurna/gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,19 @@ class Hardware : public GpioBase {
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 {

Expand Down Expand Up @@ -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() {
Expand All @@ -661,27 +687,15 @@ 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 {

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,
Expand Down
13 changes: 9 additions & 4 deletions code/espurna/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct Origin {
const char* base;
uint8_t pin;
bool lock;
bool result;
SourceLocation location;
};

Expand Down Expand Up @@ -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;
Expand Down
4,615 changes: 2,311 additions & 2,304 deletions code/espurna/static/index.all.html.gz.h

Large diffs are not rendered by default.

2,872 changes: 1,439 additions & 1,433 deletions code/espurna/static/index.curtain.html.gz.h

Large diffs are not rendered by default.

2,818 changes: 1,412 additions & 1,406 deletions code/espurna/static/index.garland.html.gz.h

Large diffs are not rendered by default.

4,009 changes: 2,008 additions & 2,001 deletions code/espurna/static/index.light.html.gz.h

Large diffs are not rendered by default.

2,778 changes: 1,392 additions & 1,386 deletions code/espurna/static/index.lightfox.html.gz.h

Large diffs are not rendered by default.

2,888 changes: 1,447 additions & 1,441 deletions code/espurna/static/index.rfbridge.html.gz.h

Large diffs are not rendered by default.

2,882 changes: 1,444 additions & 1,438 deletions code/espurna/static/index.rfm69.html.gz.h

Large diffs are not rendered by default.

3,086 changes: 1,546 additions & 1,540 deletions code/espurna/static/index.sensor.html.gz.h

Large diffs are not rendered by default.

2,788 changes: 1,397 additions & 1,391 deletions code/espurna/static/index.small.html.gz.h

Large diffs are not rendered by default.

2,862 changes: 1,434 additions & 1,428 deletions code/espurna/static/index.thermostat.html.gz.h

Large diffs are not rendered by default.

35 changes: 28 additions & 7 deletions code/html/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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
// ---------------------------------------------------------------------
Expand Down

0 comments on commit 3a1e041

Please sign in to comment.