Skip to content

Commit

Permalink
feat: Add remote IO example with Commanders
Browse files Browse the repository at this point in the history
  • Loading branch information
franky47 committed Jul 4, 2019
1 parent e7db934 commit d14deae
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ env:
- PLATFORMIO_CI_SRC=examples/NestedData
- PLATFORMIO_CI_SRC=examples/Commander
- PLATFORMIO_CI_SRC=examples/CommanderCalculator
- PLATFORMIO_CI_SRC=examples/CommanderRemoteIO

addons:
apt:
Expand Down
49 changes: 49 additions & 0 deletions examples/CommanderRemoteIO/CommanderRemoteIO.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <serde-commander.h>

// TX Commands

struct PinState
{
byte pinNumber;
bool state;
};

SERDE_COMMANDER_CREATE_TX(CommanderTX, PinState);

// RX Commands

struct SetPinState
{
byte pinNumber;
bool state;
};

struct GetPinState
{
byte pinNumber;
};

void onSetPinStateReceived(const SetPinState& args)
{
digitalWrite(args.pinNumber, args.state ? HIGH : LOW);
}

void onGetPinStateReceived(const GetPinState& args)
{
PinState reply;
reply.pinNumber = args.pinNumber;
reply.state = digitalRead(args.pinNumber);
CommanderTX::send(reply, SERIAL_PORT_HARDWARE);
}

SERDE_COMMANDER_CREATE_RX(CommanderRX, SetPinState, GetPinState);

void setup()
{
SERIAL_PORT_HARDWARE.begin(115200);
}

void loop()
{
CommanderRX::read(SERIAL_PORT_HARDWARE);
}

0 comments on commit d14deae

Please sign in to comment.