2020-12-06 10:33:42 +00:00
|
|
|
#pragma once
|
|
|
|
#include "ProtobufPlugin.h"
|
2020-12-30 04:34:22 +00:00
|
|
|
#include "mesh/generated/remote_hardware.pb.h"
|
2020-12-11 10:29:32 +00:00
|
|
|
#include "concurrency/OSThread.h"
|
2020-12-06 10:33:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A plugin that provides easy low-level remote access to device hardware.
|
|
|
|
*/
|
2020-12-11 10:29:32 +00:00
|
|
|
class RemoteHardwarePlugin : public ProtobufPlugin<HardwareMessage>, private concurrency::OSThread
|
2020-12-06 10:33:42 +00:00
|
|
|
{
|
2020-12-11 10:29:32 +00:00
|
|
|
/// The current set of GPIOs we've been asked to watch for changes
|
|
|
|
uint64_t watchGpios = 0;
|
|
|
|
|
|
|
|
/// The previously read value of watched pins
|
|
|
|
uint64_t previousWatch = 0;
|
|
|
|
|
|
|
|
/// The timestamp of our last watch event (we throttle watches to 1 change every 30 seconds)
|
|
|
|
uint32_t lastWatchMsec = 0;
|
2020-12-06 10:33:42 +00:00
|
|
|
public:
|
|
|
|
/** Constructor
|
|
|
|
* name is for debugging output
|
|
|
|
*/
|
2020-12-11 10:29:32 +00:00
|
|
|
RemoteHardwarePlugin();
|
2020-12-06 10:33:42 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/** 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
|
|
|
|
*/
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual bool handleReceivedProtobuf(const MeshPacket &mp, HardwareMessage *p) override;
|
2020-12-11 10:29:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Periodically read the gpios we have been asked to WATCH, if they have changed,
|
|
|
|
* broadcast a message with the change information.
|
|
|
|
*
|
|
|
|
* The method that will be called each time our thread gets a chance to run
|
|
|
|
*
|
|
|
|
* Returns desired period for next invocation (or RUN_SAME for no change)
|
|
|
|
*/
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual int32_t runOnce() override;
|
2020-12-06 10:33:42 +00:00
|
|
|
};
|
|
|
|
|
2022-01-24 17:24:40 +00:00
|
|
|
extern RemoteHardwarePlugin remoteHardwarePlugin;
|