Skip to content

Commit

Permalink
meshtastic#654 - Non blocking call to toggle the output.
Browse files Browse the repository at this point in the history
  • Loading branch information
mc-hamster committed Jan 28, 2021
1 parent 5e303f8 commit c524732
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/plugins/ExternalNotificationPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
This plugin supports:
https://github.com/meshtastic/Meshtastic-device/issues/654
bool ext_notification_plugin_enabled = 126;
bool ext_notification_plugin_active = 129;
Expand Down Expand Up @@ -72,13 +72,13 @@ int32_t ExternalNotificationPlugin::runOnce()
}

} else {
/*
1) If GPIO is turned on ...
2) Check the timer. If the timer has elapsed more time than
our set limit, turn the GPIO off.
if (externalCurrentState) {

*/
// TODO: Test this part. Don't know if this should be greater than or less than.
if (externalTurnedOn + EXT_NOTIFICATION_PLUGIN_OUTPUT_MS < millis()) {
setExternalOff();
}
}
}

return (25);
Expand All @@ -94,6 +94,7 @@ int32_t ExternalNotificationPlugin::runOnce()
void ExternalNotificationPlugin::setExternalOn()
{
externalCurrentState = 1;
externalTurnedOn = millis();

// if ext_notification_plugin_active
if (EXT_NOTIFICATION_PLUGIN_ACTIVE) {
Expand Down Expand Up @@ -140,20 +141,12 @@ bool ExternalNotificationPluginRadio::handleReceived(const MeshPacket &mp)
for (int i = 0; i < p.payload.size; i++) {
if (p.payload.bytes[i] == ASCII_BELL) {
externalNotificationPlugin->setExternalOn();

// TODO: Make this non-blocking.
delay(EXT_NOTIFICATION_PLUGIN_OUTPUT_MS);
externalNotificationPlugin->setExternalOff();
}
}
}

if (EXT_NOTIFICATION_PLUGIN_ALERT_MESSAGE) {
externalNotificationPlugin->setExternalOn();

// TODO: Make this non-blocking.
delay(EXT_NOTIFICATION_PLUGIN_OUTPUT_MS);
externalNotificationPlugin->setExternalOff();
}
}

Expand Down
1 change: 1 addition & 0 deletions src/plugins/ExternalNotificationPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ExternalNotificationPlugin : private concurrency::OSThread
{
bool firstTime = 1;
bool externalCurrentState = 0;
uint32_t externalTurnedOn = 0;

public:
ExternalNotificationPlugin();
Expand Down

0 comments on commit c524732

Please sign in to comment.