mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-25 22:20:27 +00:00
Fix "watch GPIOs" feature of Remote Hardware module (#3047)
* Fix watch GPIO feature of Remote Hardware * Add Remote Hardware messages to JSON output * Add curly brackets --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
parent
4577646f8b
commit
943367edd0
@ -56,7 +56,7 @@ bool RemoteHardwareModule::handleReceivedProtobuf(const meshtastic_MeshPacket &r
|
|||||||
LOG_INFO("Received RemoteHardware type=%d\n", p.type);
|
LOG_INFO("Received RemoteHardware type=%d\n", p.type);
|
||||||
|
|
||||||
switch (p.type) {
|
switch (p.type) {
|
||||||
case meshtastic_HardwareMessage_Type_WRITE_GPIOS:
|
case meshtastic_HardwareMessage_Type_WRITE_GPIOS: {
|
||||||
// Print notification to LCD screen
|
// Print notification to LCD screen
|
||||||
screen->print("Write GPIOs\n");
|
screen->print("Write GPIOs\n");
|
||||||
|
|
||||||
@ -69,6 +69,7 @@ bool RemoteHardwareModule::handleReceivedProtobuf(const meshtastic_MeshPacket &r
|
|||||||
pinModes(p.gpio_mask, OUTPUT);
|
pinModes(p.gpio_mask, OUTPUT);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case meshtastic_HardwareMessage_Type_READ_GPIOS: {
|
case meshtastic_HardwareMessage_Type_READ_GPIOS: {
|
||||||
// Print notification to LCD screen
|
// Print notification to LCD screen
|
||||||
@ -94,6 +95,7 @@ bool RemoteHardwareModule::handleReceivedProtobuf(const meshtastic_MeshPacket &r
|
|||||||
previousWatch =
|
previousWatch =
|
||||||
~watchGpios; // generate a 'previous' value which is guaranteed to not match (to force an initial publish)
|
~watchGpios; // generate a 'previous' value which is guaranteed to not match (to force an initial publish)
|
||||||
enabled = true; // Let our thread run at least once
|
enabled = true; // Let our thread run at least once
|
||||||
|
setInterval(2000); // Set a new interval so we'll run soon
|
||||||
LOG_INFO("Now watching GPIOs 0x%llx\n", watchGpios);
|
LOG_INFO("Now watching GPIOs 0x%llx\n", watchGpios);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -118,6 +120,7 @@ int32_t RemoteHardwareModule::runOnce()
|
|||||||
|
|
||||||
if (now - lastWatchMsec >= WATCH_INTERVAL_MSEC) {
|
if (now - lastWatchMsec >= WATCH_INTERVAL_MSEC) {
|
||||||
uint64_t curVal = digitalReads(watchGpios);
|
uint64_t curVal = digitalReads(watchGpios);
|
||||||
|
lastWatchMsec = now;
|
||||||
|
|
||||||
if (curVal != previousWatch) {
|
if (curVal != previousWatch) {
|
||||||
previousWatch = curVal;
|
previousWatch = curVal;
|
||||||
@ -136,5 +139,5 @@ int32_t RemoteHardwareModule::runOnce()
|
|||||||
return disable();
|
return disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 200; // Poll our GPIOs every 200ms (FIXME, make adjustable via protobuf arg)
|
return 2000; // Poll our GPIOs every 2000ms
|
||||||
}
|
}
|
@ -10,6 +10,7 @@
|
|||||||
#if defined(ARCH_ESP32)
|
#if defined(ARCH_ESP32)
|
||||||
#include "../mesh/generated/meshtastic/paxcount.pb.h"
|
#include "../mesh/generated/meshtastic/paxcount.pb.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "mesh/generated/meshtastic/remote_hardware.pb.h"
|
||||||
#include "sleep.h"
|
#include "sleep.h"
|
||||||
#if HAS_WIFI
|
#if HAS_WIFI
|
||||||
#include "mesh/wifi/WiFiAPClient.h"
|
#include "mesh/wifi/WiFiAPClient.h"
|
||||||
@ -747,6 +748,28 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
case meshtastic_PortNum_REMOTE_HARDWARE_APP: {
|
||||||
|
meshtastic_HardwareMessage scratch;
|
||||||
|
meshtastic_HardwareMessage *decoded = NULL;
|
||||||
|
memset(&scratch, 0, sizeof(scratch));
|
||||||
|
if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_HardwareMessage_msg,
|
||||||
|
&scratch)) {
|
||||||
|
decoded = &scratch;
|
||||||
|
if (decoded->type == meshtastic_HardwareMessage_Type_GPIOS_CHANGED) {
|
||||||
|
msgType = "gpios_changed";
|
||||||
|
msgPayload["gpio_value"] = new JSONValue((uint)decoded->gpio_value);
|
||||||
|
jsonObj["payload"] = new JSONValue(msgPayload);
|
||||||
|
} else if (decoded->type == meshtastic_HardwareMessage_Type_READ_GPIOS_REPLY) {
|
||||||
|
msgType = "gpios_read_reply";
|
||||||
|
msgPayload["gpio_value"] = new JSONValue((uint)decoded->gpio_value);
|
||||||
|
msgPayload["gpio_mask"] = new JSONValue((uint)decoded->gpio_mask);
|
||||||
|
jsonObj["payload"] = new JSONValue(msgPayload);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG_ERROR("Error decoding protobuf for RemoteHardware message!\n");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
// add more packet types here if needed
|
// add more packet types here if needed
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user