mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-03-30 14:55:46 +00:00
Merge pull request #547 from fdlamotte/sensors_gpio
sensors: gpio command
This commit is contained in:
@@ -547,7 +547,26 @@ void SensorMesh::handleCommand(uint32_t sender_timestamp, char* command, char* r
|
||||
Serial.printf("\n");
|
||||
}
|
||||
reply[0] = 0;
|
||||
} else {
|
||||
} else if (memcmp(command, "io ", 2) == 0) { // io {value}: write, io: read
|
||||
if (command[2] == ' ') { // it's a write
|
||||
uint32_t val;
|
||||
uint32_t g = board.getGpio();
|
||||
if (command[3] == 'r') { // reset bits
|
||||
sscanf(&command[4], "%x", &val);
|
||||
val = g & ~val;
|
||||
} else if (command[3] == 's') { // set bits
|
||||
sscanf(&command[4], "%x", &val);
|
||||
val |= g;
|
||||
} else if (command[3] == 't') { // toggle bits
|
||||
sscanf(&command[4], "%x", &val);
|
||||
val ^= g;
|
||||
} else { // set value
|
||||
sscanf(&command[3], "%x", &val);
|
||||
}
|
||||
board.setGpio(val);
|
||||
}
|
||||
sprintf(reply, "%x", board.getGpio());
|
||||
} else{
|
||||
_cli.handleCommand(sender_timestamp, command, reply); // common CLI commands
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ public:
|
||||
virtual void onAfterTransmit() { }
|
||||
virtual void reboot() = 0;
|
||||
virtual void powerOff() { /* no op */ }
|
||||
virtual uint32_t getGpio() { return 0; }
|
||||
virtual void setGpio(uint32_t values) {}
|
||||
virtual uint8_t getStartupReason() const = 0;
|
||||
virtual bool startOTAUpdate(const char* id, char reply[]) { return false; } // not supported
|
||||
};
|
||||
|
||||
@@ -13,6 +13,12 @@
|
||||
|
||||
class RAK3x72Board : public STM32Board {
|
||||
public:
|
||||
void begin() override {
|
||||
STM32Board::begin();
|
||||
pinMode(PA0, OUTPUT);
|
||||
pinMode(PA1, OUTPUT);
|
||||
}
|
||||
|
||||
const char* getManufacturerName() const override {
|
||||
return "RAK 3x72";
|
||||
}
|
||||
@@ -25,6 +31,17 @@ public:
|
||||
}
|
||||
return ((double)raw) * ADC_MULTIPLIER / 8 / 4096;
|
||||
}
|
||||
|
||||
void setGpio(uint32_t values) override {
|
||||
// set led values
|
||||
digitalWrite(PA0, values & 1);
|
||||
digitalWrite(PA1, (values & 2) >> 1);
|
||||
}
|
||||
|
||||
uint32_t getGpio() override {
|
||||
// get led value
|
||||
return (digitalRead(PA1) << 1) | digitalRead(PA0);
|
||||
}
|
||||
};
|
||||
|
||||
extern RAK3x72Board board;
|
||||
|
||||
Reference in New Issue
Block a user