-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added shutter control device firmware example.
- Loading branch information
Showing
22 changed files
with
666 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* HomeGenie-Mini (c) 2018-2024 G-Labs | ||
* | ||
* | ||
* This file is part of HomeGenie-Mini (HGM). | ||
* | ||
* HomeGenie-Mini is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* HomeGenie-Mini is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with HomeGenie-Mini. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* | ||
* Authors: | ||
* - Generoso Martello <[email protected]> | ||
* | ||
* | ||
* Releases: | ||
* - 2024-01-06 Initial release | ||
* | ||
*/ | ||
|
||
#include "ShutterHandler.h" | ||
|
||
namespace Service { namespace API { | ||
|
||
ShutterHandler::ShutterHandler(ShutterControl* servoControl) { | ||
this->servoControl = servoControl; | ||
|
||
auto domain = IO::IOEventDomains::Automation_Components; | ||
// Shutter module | ||
shutterModule = new Module(); | ||
shutterModule->domain = domain; | ||
shutterModule->address = SERVO_MODULE_ADDRESS; | ||
shutterModule->type = "Shutter"; | ||
shutterModule->name = "Shutter 1"; | ||
// add properties | ||
shutterLevel = new ModuleParameter(IOEventPaths::Status_Level); | ||
shutterModule->properties.add(shutterLevel); | ||
|
||
moduleList.add(shutterModule); | ||
} | ||
|
||
void ShutterHandler::init() { | ||
|
||
} | ||
|
||
|
||
bool ShutterHandler::handleRequest(APIRequest *command, WebServer &server) { | ||
|
||
if (command->Domain == (IOEventDomains::Automation_Components) | ||
&& command->Address == SERVO_MODULE_ADDRESS) { | ||
|
||
if (command->Command == "Control.Level") { | ||
|
||
float level = command->OptionsString.toFloat(); | ||
|
||
servoControl->setLevel(level); | ||
|
||
command->Response = R"({ "ResponseText": "OK" })"; | ||
|
||
} else if (command->Command == "Control.Close" || command->Command == "Control.Off") { | ||
|
||
servoControl->close(); | ||
|
||
} else if (command->Command == "Control.Open" || command->Command == "Control.On") { | ||
|
||
servoControl->open(); | ||
|
||
} else { | ||
|
||
return false; | ||
|
||
} | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool ShutterHandler::canHandleDomain(String* domain) { | ||
return domain->equals(IO::IOEventDomains::Automation_Components); | ||
} | ||
|
||
bool ShutterHandler::handleEvent(IIOEventSender *sender, | ||
const char* domain, const char* address, | ||
const unsigned char *eventPath, void *eventData, IOEventDataType dataType) { | ||
auto module = getModule(domain, address); | ||
if (module) { | ||
auto event = String((char *) eventPath); | ||
// Event Stream Message Enqueue (for MQTT/SSE/WebSocket propagation) | ||
auto m = QueuedMessage(domain, address, event.c_str(), ""); | ||
// Data type handling | ||
switch (dataType) { | ||
case Number: | ||
m.value = String(*(int32_t *) eventData); | ||
break; | ||
case Float: | ||
m.value = String(*(float *) eventData); | ||
break; | ||
case Integer: | ||
m.value = String(*(int16_t *) eventData); | ||
break; | ||
default: | ||
m.value = String(*(int32_t *) eventData); | ||
} | ||
module->setProperty(event, m.value); | ||
HomeGenie::getInstance()->getEventRouter().signalEvent(m); | ||
} | ||
return false; | ||
} | ||
|
||
Module* ShutterHandler::getModule(const char* domain, const char* address) { | ||
for (int i = 0; i < moduleList.size(); i++) { | ||
Module* module = moduleList.get(i); | ||
if (module->domain.equals(domain) && module->address.equals(address)) | ||
return module; | ||
} | ||
return nullptr; | ||
} | ||
LinkedList<Module*>* ShutterHandler::getModuleList() { | ||
return &moduleList; | ||
} | ||
|
||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* HomeGenie-Mini (c) 2018-2024 G-Labs | ||
* | ||
* | ||
* This file is part of HomeGenie-Mini (HGM). | ||
* | ||
* HomeGenie-Mini is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* HomeGenie-Mini is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with HomeGenie-Mini. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* | ||
* Authors: | ||
* - Generoso Martello <[email protected]> | ||
* | ||
* | ||
* Releases: | ||
* - 2024-01-06 Initial release | ||
* | ||
*/ | ||
|
||
#ifndef HOMEGENIE_MINI_SHUTTERHANDLER_H | ||
#define HOMEGENIE_MINI_SHUTTERHANDLER_H | ||
|
||
#include <HomeGenie.h> | ||
|
||
#include "../io/ShutterControl.h" | ||
|
||
namespace Service { namespace API { | ||
|
||
using namespace IO::Components; | ||
|
||
class ShutterHandler : public APIHandler { | ||
private: | ||
LinkedList<Module*> moduleList; | ||
Module* shutterModule; | ||
ModuleParameter* shutterLevel; | ||
ShutterControl* servoControl; | ||
public: | ||
ShutterHandler(ShutterControl* servoControl); | ||
void init() override; | ||
bool canHandleDomain(String* domain) override; | ||
bool handleRequest(APIRequest *request, WebServer &server) override; | ||
bool handleEvent(IIOEventSender *sender, | ||
const char* domain, const char* address, | ||
const unsigned char *eventPath, void *eventData, IOEventDataType dataType) override; | ||
|
||
Module* getModule(const char* domain, const char* address) override; | ||
LinkedList<Module*>* getModuleList() override; | ||
}; | ||
|
||
}} | ||
#endif //HOMEGENIE_MINI_SHUTTERHANDLER_H |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* HomeGenie-Mini (c) 2018-2024 G-Labs | ||
* | ||
* | ||
* This file is part of HomeGenie-Mini (HGM). | ||
* | ||
* HomeGenie-Mini is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* HomeGenie-Mini is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with HomeGenie-Mini. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* | ||
* Authors: | ||
* - Generoso Martello <[email protected]> | ||
* | ||
* | ||
* Releases: | ||
* - 2024-01-06 Initial release | ||
* | ||
*/ | ||
|
||
#ifndef HOMEGENIE_MINI_ISHUTTERDRIVER_H | ||
#define HOMEGENIE_MINI_ISHUTTERDRIVER_H | ||
|
||
namespace IO { namespace Components { | ||
class IShutterDriver { | ||
public: | ||
virtual void init() = 0; | ||
virtual void stop() = 0; | ||
virtual void open() = 0; | ||
virtual void close() = 0; | ||
}; | ||
}} | ||
|
||
#endif //HOMEGENIE_MINI_ISHUTTERDRIVER_H |
Oops, something went wrong.