mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-03 03:09:59 +00:00
#654 - Partial work for the LED/Speaker.
Framework is done. Just need to blink a few things and update protobufs.
This commit is contained in:
parent
ad322476d2
commit
eff0c1fe89
108
src/plugins/ExternalNotificationPlugin.cpp
Normal file
108
src/plugins/ExternalNotificationPlugin.cpp
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
#include "ExternalNotificationPlugin.h"
|
||||||
|
#include "MeshService.h"
|
||||||
|
#include "NodeDB.h"
|
||||||
|
#include "RTC.h"
|
||||||
|
#include "Router.h"
|
||||||
|
#include "configuration.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
bool ext_notification_plugin_enabled = 126;
|
||||||
|
uint32 ext_notification_plugin_output_ms = 127;
|
||||||
|
uint32 ext_notification_plugin_output = 128;
|
||||||
|
bool ext_notification_plugin_active = 129;
|
||||||
|
bool ext_notification_plugin_alert_message = 130;
|
||||||
|
bool ext_notification_plugin_alert_bell = 131;
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
ExternalNotificationPlugin *externalNotificationPlugin;
|
||||||
|
ExternalNotificationPluginRadio *externalNotificationPluginRadio;
|
||||||
|
|
||||||
|
ExternalNotificationPlugin::ExternalNotificationPlugin() : concurrency::OSThread("ExternalNotificationPlugin") {}
|
||||||
|
|
||||||
|
int32_t ExternalNotificationPlugin::runOnce()
|
||||||
|
{
|
||||||
|
#ifndef NO_ESP32
|
||||||
|
|
||||||
|
/*
|
||||||
|
Uncomment the preferences below if you want to use the plugin
|
||||||
|
without having to configure it from the PythonAPI or WebUI.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// radioConfig.preferences.externalnotificationplugin_enabled = 1;
|
||||||
|
// radioConfig.preferences.externalnotificationplugin_mode = 1;
|
||||||
|
|
||||||
|
if (0) {
|
||||||
|
|
||||||
|
if (firstTime) {
|
||||||
|
|
||||||
|
DEBUG_MSG("Initializing External Notification Plugin\n");
|
||||||
|
|
||||||
|
externalNotificationPluginRadio = new ExternalNotificationPluginRadio();
|
||||||
|
|
||||||
|
firstTime = 0;
|
||||||
|
|
||||||
|
} 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.
|
||||||
|
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
return (25);
|
||||||
|
} else {
|
||||||
|
DEBUG_MSG("External Notification Plugin Disabled\n");
|
||||||
|
|
||||||
|
return (INT32_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------
|
||||||
|
|
||||||
|
MeshPacket *ExternalNotificationPluginRadio::allocReply()
|
||||||
|
{
|
||||||
|
|
||||||
|
auto reply = allocDataPacket(); // Allocate a packet for sending
|
||||||
|
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ExternalNotificationPluginRadio::handleReceived(const MeshPacket &mp)
|
||||||
|
{
|
||||||
|
#ifndef NO_ESP32
|
||||||
|
|
||||||
|
if (0) {
|
||||||
|
|
||||||
|
auto &p = mp.decoded.data;
|
||||||
|
|
||||||
|
if (mp.from != nodeDB.getNodeNum()) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO: If ext_notification_plugin_alert_bell is true and we see a bell character, trigger an external notification.
|
||||||
|
*/
|
||||||
|
// TODO: Check p.payload.bytes to see if it contains a bell character. If it does, trigger an external notifcation.
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO: If ext_notification_plugin_alert_message is true, trigger an external notification.
|
||||||
|
*/
|
||||||
|
// TODO: On received packet, blink the LED.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
DEBUG_MSG("External Notification Plugin Disabled\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true; // Let others look at this message also if they want
|
||||||
|
}
|
43
src/plugins/ExternalNotificationPlugin.h
Normal file
43
src/plugins/ExternalNotificationPlugin.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "SinglePortPlugin.h"
|
||||||
|
#include "concurrency/OSThread.h"
|
||||||
|
#include "configuration.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
|
||||||
|
class ExternalNotificationPlugin : private concurrency::OSThread
|
||||||
|
{
|
||||||
|
bool firstTime = 1;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ExternalNotificationPlugin();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual int32_t runOnce();
|
||||||
|
};
|
||||||
|
|
||||||
|
extern ExternalNotificationPlugin *externalNotificationPlugin;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Radio interface for ExternalNotificationPlugin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class ExternalNotificationPluginRadio : public SinglePortPlugin
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
ExternalNotificationPluginRadio() : SinglePortPlugin("ExternalNotificationPluginRadio", PortNum_TEXT_MESSAGE_APP) {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual MeshPacket *allocReply();
|
||||||
|
|
||||||
|
/** Called to handle a particular incoming message
|
||||||
|
|
||||||
|
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
|
||||||
|
*/
|
||||||
|
virtual bool handleReceived(const MeshPacket &mp);
|
||||||
|
};
|
||||||
|
|
||||||
|
extern ExternalNotificationPluginRadio *externalNotificationPluginRadio;
|
@ -1,3 +1,4 @@
|
|||||||
|
#include "plugins/ExternalNotificationPlugin.h"
|
||||||
#include "plugins/NodeInfoPlugin.h"
|
#include "plugins/NodeInfoPlugin.h"
|
||||||
#include "plugins/PositionPlugin.h"
|
#include "plugins/PositionPlugin.h"
|
||||||
#include "plugins/RemoteHardwarePlugin.h"
|
#include "plugins/RemoteHardwarePlugin.h"
|
||||||
@ -23,7 +24,7 @@ void setupPlugins()
|
|||||||
#ifndef NO_ESP32
|
#ifndef NO_ESP32
|
||||||
// Only run on an esp32 based device.
|
// Only run on an esp32 based device.
|
||||||
|
|
||||||
new SerialPlugin(); // Maintained by MC Hamster (Jm Casler) jm@casler.org
|
new SerialPlugin(); // Maintained by MC Hamster (Jm Casler) jm@casler.org
|
||||||
|
new ExternalNotificationPlugin(); // Maintained by MC Hamster (Jm Casler) jm@casler.org
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user