mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-24 03:31:14 +00:00
add remote gpio control as an example plugin
https://github.com/meshtastic/Meshtastic-device/issues/182
This commit is contained in:
@@ -17,7 +17,7 @@ extern "C" {
|
||||
typedef enum _PortNum {
|
||||
PortNum_UNKNOWN_APP = 0,
|
||||
PortNum_TEXT_MESSAGE_APP = 1,
|
||||
PortNum_GPIO_APP = 2,
|
||||
PortNum_REMOTE_HARDWARE_APP = 2,
|
||||
PortNum_POSITION_APP = 3,
|
||||
PortNum_NODEINFO_APP = 4,
|
||||
PortNum_PRIVATE_APP = 256,
|
||||
|
||||
13
src/mesh/remote_hardware.pb.c
Normal file
13
src/mesh/remote_hardware.pb.c
Normal file
@@ -0,0 +1,13 @@
|
||||
/* Automatically generated nanopb constant definitions */
|
||||
/* Generated by nanopb-0.4.1 */
|
||||
|
||||
#include "remote_hardware.pb.h"
|
||||
#if PB_PROTO_HEADER_VERSION != 40
|
||||
#error Regenerate this file with the current version of nanopb generator.
|
||||
#endif
|
||||
|
||||
PB_BIND(HardwareMessage, HardwareMessage, AUTO)
|
||||
|
||||
|
||||
|
||||
|
||||
69
src/mesh/remote_hardware.pb.h
Normal file
69
src/mesh/remote_hardware.pb.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* Automatically generated nanopb header */
|
||||
/* Generated by nanopb-0.4.1 */
|
||||
|
||||
#ifndef PB_REMOTE_HARDWARE_PB_H_INCLUDED
|
||||
#define PB_REMOTE_HARDWARE_PB_H_INCLUDED
|
||||
#include <pb.h>
|
||||
|
||||
#if PB_PROTO_HEADER_VERSION != 40
|
||||
#error Regenerate this file with the current version of nanopb generator.
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Enum definitions */
|
||||
typedef enum _HardwareMessage_MessageType {
|
||||
HardwareMessage_MessageType_UNSET = 0,
|
||||
HardwareMessage_MessageType_WRITE_GPIOS = 1,
|
||||
HardwareMessage_MessageType_WATCH_GPIOS = 2,
|
||||
HardwareMessage_MessageType_GPIOS_CHANGED = 3,
|
||||
HardwareMessage_MessageType_READ_GPIOS = 4,
|
||||
HardwareMessage_MessageType_READ_GPIOS_REPLY = 5
|
||||
} HardwareMessage_MessageType;
|
||||
|
||||
/* Struct definitions */
|
||||
typedef struct _HardwareMessage {
|
||||
HardwareMessage_MessageType typ;
|
||||
uint64_t gpio_mask;
|
||||
uint64_t gpio_value;
|
||||
} HardwareMessage;
|
||||
|
||||
|
||||
/* Helper constants for enums */
|
||||
#define _HardwareMessage_MessageType_MIN HardwareMessage_MessageType_UNSET
|
||||
#define _HardwareMessage_MessageType_MAX HardwareMessage_MessageType_READ_GPIOS_REPLY
|
||||
#define _HardwareMessage_MessageType_ARRAYSIZE ((HardwareMessage_MessageType)(HardwareMessage_MessageType_READ_GPIOS_REPLY+1))
|
||||
|
||||
|
||||
/* Initializer values for message structs */
|
||||
#define HardwareMessage_init_default {_HardwareMessage_MessageType_MIN, 0, 0}
|
||||
#define HardwareMessage_init_zero {_HardwareMessage_MessageType_MIN, 0, 0}
|
||||
|
||||
/* Field tags (for use in manual encoding/decoding) */
|
||||
#define HardwareMessage_typ_tag 1
|
||||
#define HardwareMessage_gpio_mask_tag 2
|
||||
#define HardwareMessage_gpio_value_tag 3
|
||||
|
||||
/* Struct field encoding specification for nanopb */
|
||||
#define HardwareMessage_FIELDLIST(X, a) \
|
||||
X(a, STATIC, SINGULAR, UENUM, typ, 1) \
|
||||
X(a, STATIC, SINGULAR, UINT64, gpio_mask, 2) \
|
||||
X(a, STATIC, SINGULAR, UINT64, gpio_value, 3)
|
||||
#define HardwareMessage_CALLBACK NULL
|
||||
#define HardwareMessage_DEFAULT NULL
|
||||
|
||||
extern const pb_msgdesc_t HardwareMessage_msg;
|
||||
|
||||
/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
|
||||
#define HardwareMessage_fields &HardwareMessage_msg
|
||||
|
||||
/* Maximum encoded size of messages (where known) */
|
||||
#define HardwareMessage_size 24
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
17
src/plugins/RemoteHardwarePlugin.cpp
Normal file
17
src/plugins/RemoteHardwarePlugin.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "RemoteHardwarePlugin.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "RTC.h"
|
||||
#include "Router.h"
|
||||
#include "configuration.h"
|
||||
#include "main.h"
|
||||
|
||||
RemoteHardwarePlugin remoteHardwarePlugin;
|
||||
|
||||
bool RemoteHardwarePlugin::handleReceivedProtobuf(const MeshPacket &mp, const HardwareMessage &p)
|
||||
{
|
||||
|
||||
return false; // Let others look at this message also if they want
|
||||
}
|
||||
|
||||
|
||||
24
src/plugins/RemoteHardwarePlugin.h
Normal file
24
src/plugins/RemoteHardwarePlugin.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "ProtobufPlugin.h"
|
||||
#include "remote_hardware.pb.h"
|
||||
|
||||
/**
|
||||
* A plugin that provides easy low-level remote access to device hardware.
|
||||
*/
|
||||
class RemoteHardwarePlugin : public ProtobufPlugin<HardwareMessage>
|
||||
{
|
||||
public:
|
||||
/** Constructor
|
||||
* name is for debugging output
|
||||
*/
|
||||
RemoteHardwarePlugin() : ProtobufPlugin("remotehardware", PortNum_REMOTE_HARDWARE_APP, HardwareMessage_fields) {}
|
||||
|
||||
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
|
||||
*/
|
||||
virtual bool handleReceivedProtobuf(const MeshPacket &mp, const HardwareMessage &p);
|
||||
};
|
||||
|
||||
extern RemoteHardwarePlugin remoteHardwarePlugin;
|
||||
Reference in New Issue
Block a user