Skip to content

Commit 87dd120

Browse files
committed
Implement GPIO Opposite, this is a change to the existing API
1 parent 0162b51 commit 87dd120

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/gpio.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ int ExtGPIO(int gpio, char* mode, int value) {
7777
return retval;
7878
}
7979

80+
GPIOManager GPIOManager::INSTANCE;
81+
8082
class FPPGPIOCommand : public Command {
8183
public:
8284
FPPGPIOCommand() :
8385
Command("GPIO") {
8486
args.push_back(CommandArg("pin", "string", "Pin").setContentListUrl("api/gpio?list=true"));
85-
args.push_back(CommandArg("on", "bool", "On"));
87+
args.push_back(CommandArg("on", "string", "Action").setContentList({"On", "Off", "Opposite"}));
8688
}
8789
virtual std::unique_ptr<Command::Result> run(const std::vector<std::string>& args) override {
8890
if (args.size() != 2) {
@@ -93,14 +95,27 @@ class FPPGPIOCommand : public Command {
9395
const PinCapabilities& p = PinCapabilities::getPinByName(n);
9496
if (p.ptr()) {
9597
p.configPin();
96-
p.setValue(v == "true" || v == "1");
98+
if (v == "On" || v == "on" || v == "true" || v == "True" || v == "1") {
99+
p.setValue(true);
100+
GPIOManager::INSTANCE.fppCommandLastValue[n] = true;
101+
}
102+
else if (v == "Off" || v == "off" || v == "false" || v == "False" || v == "0") {
103+
p.setValue(false);
104+
GPIOManager::INSTANCE.fppCommandLastValue[n] = false;
105+
}
106+
else if (v == "Opposite" || v == "opposite") {
107+
GPIOManager::INSTANCE.fppCommandLastValue[n] = !GPIOManager::INSTANCE.fppCommandLastValue[n];
108+
p.setValue(GPIOManager::INSTANCE.fppCommandLastValue[n]);
109+
}
110+
else {
111+
return std::make_unique<Command::ErrorResult>("Invalid Action" + v);
112+
}
97113
return std::make_unique<Command::Result>("OK");
98114
}
99115
return std::make_unique<Command::ErrorResult>("No Pin Named " + n);
100116
}
101117
};
102118

103-
GPIOManager GPIOManager::INSTANCE;
104119

105120
GPIOManager::GPIOManager() :
106121
checkDebounces(false) {

src/gpio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class GPIOManager : public httpserver::http_resource {
3333
public:
3434
static GPIOManager INSTANCE;
3535

36+
std::map<std::string, bool> fppCommandLastValue;
37+
3638
virtual HTTP_RESPONSE_CONST std::shared_ptr<httpserver::http_response> render_GET(const httpserver::http_request& req) override;
3739

3840
void Initialize(std::map<int, std::function<bool(int)>>& callbacks);

0 commit comments

Comments
 (0)