Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion examples/simple_repeater/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,35 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
sendNodeDiscoverReq();
strcpy(reply, "OK - Discover sent");
}
} else{
} else if (memcmp(command, "io", 2) == 0) {
uint32_t val = 0;
uint32_t current = board.getGpio();
char mode = command[2]; // This is ' ', 'r', 's', 't', or 'p'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be best to keep the syntax consistent with sensor firmware, ie. "io {r|s|t}mask-value"
Looks like you moved the space ' '.

// Find the start of the hex value (the first space)
const char* valuePtr = strchr(command, ' ');

if (valuePtr != nullptr) {
sscanf(valuePtr, "%x", &val);

if (mode == 'r') { // ior 1 (Reset/Off)
board.setGpio(current & ~val);
} else if (mode == 's') { // ios 1 (Set/On)
board.setGpio(current | val);
} else if (mode == 't') { // iot 1 (Toggle)
board.setGpio(current ^ val);
} else if (mode == 'p') { // iop 1 (Pulse for Pi)
// Pulse logic: Start the action
board.setGpio(current & ~val); // Pull Low (0)
// 50ms is the "sweet spot" for Pi triggers
delay(50);
board.setGpio(current | val); // Return High (1)
} else { // io 1 (Direct Write)
board.setGpio(val);
}
}
sprintf(reply, "IO: %x", board.getGpio());
} else{
_cli.handleCommand(sender_timestamp, command, reply); // common CLI commands
}
}
Expand Down
3 changes: 2 additions & 1 deletion variants/heltec_mesh_solar/MeshSolarBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

void MeshSolarBoard::begin() {
NRF52Board::begin();

pinMode(30, OUTPUT);
pinMode(5, OUTPUT);
meshSolarStart();

#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
Expand Down
11 changes: 11 additions & 0 deletions variants/heltec_mesh_solar/MeshSolarBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,15 @@ class MeshSolarBoard : public NRF52BoardDCDC {
const char* getManufacturerName() const override {
return "Heltec Mesh Solar";
}

void setGpio(uint32_t values) override {
// set led values
digitalWrite(30, values & 1);
digitalWrite(5, (values & 2) >> 1);
}

uint32_t getGpio() override {
// get led value
return (digitalRead(30) << 1) | digitalRead(5);
}
};