2020-12-06 10:33:42 +00:00
|
|
|
#pragma once
|
2022-03-09 08:01:43 +00:00
|
|
|
#include "ProtobufModule.h"
|
2020-12-11 10:29:32 +00:00
|
|
|
#include "concurrency/OSThread.h"
|
2023-01-18 20:51:48 +00:00
|
|
|
#include "mesh/generated/meshtastic/remote_hardware.pb.h"
|
2020-12-06 10:33:42 +00:00
|
|
|
|
|
|
|
/**
|
2022-02-27 08:29:05 +00:00
|
|
|
* A module that provides easy low-level remote access to device hardware.
|
2020-12-06 10:33:42 +00:00
|
|
|
*/
|
2023-01-21 17:22:19 +00:00
|
|
|
class RemoteHardwareModule : public ProtobufModule<meshtastic_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
|
2023-01-18 20:51:48 +00:00
|
|
|
uint64_t watchGpios = 0;
|
2020-12-11 10:29:32 +00:00
|
|
|
|
|
|
|
/// 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;
|
2023-01-18 20:51:48 +00:00
|
|
|
|
2020-12-06 10:33:42 +00:00
|
|
|
public:
|
|
|
|
/** Constructor
|
|
|
|
* name is for debugging output
|
|
|
|
*/
|
2022-02-27 10:21:02 +00:00
|
|
|
RemoteHardwareModule();
|
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
|
|
|
|
*/
|
2023-01-21 17:22:19 +00:00
|
|
|
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_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.
|
2023-01-18 20:51:48 +00:00
|
|
|
*
|
2020-12-11 10:29:32 +00:00
|
|
|
* 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-02-27 10:21:02 +00:00
|
|
|
extern RemoteHardwareModule remoteHardwareModule;
|