mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-27 18:31:37 +00:00
Merge pull request #1162 from mkinney/remote_hw
gpio read and write work as expected
This commit is contained in:
commit
66cd824437
@ -17,7 +17,7 @@
|
|||||||
/// Set pin modes for every set bit in a mask
|
/// Set pin modes for every set bit in a mask
|
||||||
static void pinModes(uint64_t mask, uint8_t mode)
|
static void pinModes(uint64_t mask, uint8_t mode)
|
||||||
{
|
{
|
||||||
for (uint8_t i = 0; i < NUM_GPIOS; i++) {
|
for (uint64_t i = 0; i < NUM_GPIOS; i++) {
|
||||||
if (mask & (1 << i)) {
|
if (mask & (1 << i)) {
|
||||||
pinMode(i, mode);
|
pinMode(i, mode);
|
||||||
}
|
}
|
||||||
@ -29,13 +29,17 @@ static uint64_t digitalReads(uint64_t mask)
|
|||||||
{
|
{
|
||||||
uint64_t res = 0;
|
uint64_t res = 0;
|
||||||
|
|
||||||
pinModes(mask, INPUT_PULLUP);
|
// The Arduino docs show to run pinMode(). But, when testing, found it is best not to.
|
||||||
|
// If the line below is uncommented, read will flip the pin to the default of the second
|
||||||
|
// argument in pinModes(), which will make the read turn the PIN "on".
|
||||||
|
//pinModes(mask, INPUT_PULLUP);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < NUM_GPIOS; i++) {
|
for (uint64_t i = 0; i < NUM_GPIOS; i++) {
|
||||||
uint64_t m = 1 << i;
|
uint64_t m = 1 << i;
|
||||||
if (mask & m) {
|
if (mask & m) {
|
||||||
if (digitalRead(i))
|
if (digitalRead(i)) {
|
||||||
res |= m;
|
res |= m;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +83,7 @@ bool RemoteHardwarePlugin::handleReceivedProtobuf(const MeshPacket &req, Hardwar
|
|||||||
HardwareMessage r = HardwareMessage_init_default;
|
HardwareMessage r = HardwareMessage_init_default;
|
||||||
r.typ = HardwareMessage_Type_READ_GPIOS_REPLY;
|
r.typ = HardwareMessage_Type_READ_GPIOS_REPLY;
|
||||||
r.gpio_value = res;
|
r.gpio_value = res;
|
||||||
|
r.gpio_mask = p.gpio_mask;
|
||||||
MeshPacket *p2 = allocDataProtobuf(r);
|
MeshPacket *p2 = allocDataProtobuf(r);
|
||||||
setReplyTo(p2, req);
|
setReplyTo(p2, req);
|
||||||
myReply = p2;
|
myReply = p2;
|
||||||
|
Loading…
Reference in New Issue
Block a user