Skip to content

Commit

Permalink
v1.2.15
Browse files Browse the repository at this point in the history
- Fixed startup crash on ESP8266 chipset
- Changed default X10 RF transmitter pin from 4 to 6
- Updated to `espressif32` 6.7.0
  • Loading branch information
genemars committed Jun 1, 2024
1 parent b6568cb commit 2a1f70e
Show file tree
Hide file tree
Showing 43 changed files with 400 additions and 222 deletions.
2 changes: 1 addition & 1 deletion examples/ir-transceiver/api/IRTransceiverHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace Service { namespace API {

bool IRTransceiverHandler::handleEvent(IIOEventSender *sender,
const char* domain, const char* address,
const unsigned char *eventPath, void *eventData, IOEventDataType dataType) {
const char *eventPath, void *eventData, IOEventDataType dataType) {

String event = String((char*)eventPath);
/*
Expand Down
2 changes: 1 addition & 1 deletion examples/ir-transceiver/api/IRTransceiverHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Service { namespace API {
bool handleRequest(APIRequest*, ResponseCallback*) override;
bool handleEvent(IIOEventSender*,
const char* domain, const char* address,
const unsigned char *eventPath, void* eventData, IOEventDataType) override;
const char *eventPath, void* eventData, IOEventDataType) override;

Module* getModule(const char* domain, const char* address) override;
LinkedList<Module*>* getModuleList() override;
Expand Down
2 changes: 1 addition & 1 deletion examples/ir-transceiver/io/IRReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace IO { namespace IR {
//Serial.println(resultToSourceCode(&results));
String stringData = sProtocol + sSize + sData;
stringData.toUpperCase();
sendEvent((const uint8_t*)(IOEventPaths::Receiver_RawData), &stringData, IOEventDataType::Text);
sendEvent(IOEventPaths::Receiver_RawData, &stringData, IOEventDataType::Text);
}

irReceiver->resume();
Expand Down
8 changes: 5 additions & 3 deletions examples/rf-transceiver/api/RCSwitchHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ namespace Service { namespace API {
RCSwitchHandler::RCSwitchHandler(RFTransmitter* transmitter) {
this->transmitter = transmitter;

auto domain = IO::IOEventDomains::HomeAutomation_RemoteControl;
// HomeGenie Mini module
auto rfModule = new Module();
rfModule->domain = domain;
rfModule->domain = IO::IOEventDomains::HomeAutomation_RemoteControl;
rfModule->address = CONFIG_RCSwitchRF_MODULE_ADDRESS;
rfModule->type = "Sensor";
rfModule->name = "RF"; //TODO: CONFIG_RCSwitchRF_MODULE_NAME;
// explicitly enable "scheduling" features for this module
rfModule->properties.add(new ModuleParameter("Widget.Implements.Scheduling", "1"));
// add properties
auto propRawData = new ModuleParameter(IOEventPaths::Receiver_RawData);
rfModule->properties.add(propRawData);
Expand All @@ -50,6 +51,7 @@ namespace Service { namespace API {
}

void RCSwitchHandler::init() {
transmitter->begin();
}

bool RCSwitchHandler::handleRequest(APIRequest *command, ResponseCallback* responseCallback) {
Expand All @@ -73,7 +75,7 @@ namespace Service { namespace API {

bool RCSwitchHandler::handleEvent(IIOEventSender *sender,
const char* domain, const char* address,
const unsigned char *eventPath, void *eventData, IOEventDataType dataType) {
const char *eventPath, void *eventData, IOEventDataType dataType) {

String event = String((char*)eventPath);
/*
Expand Down
2 changes: 1 addition & 1 deletion examples/rf-transceiver/api/RCSwitchHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace Service { namespace API {
bool handleRequest(APIRequest *request, ResponseCallback* responseCallback) override;
bool handleEvent(IIOEventSender *sender,
const char* domain, const char* address,
const unsigned char *eventPath, void *eventData, IOEventDataType dataType) override;
const char *eventPath, void *eventData, IOEventDataType dataType) override;

Module* getModule(const char* domain, const char* address) override;
LinkedList<Module*>* getModuleList() override;
Expand Down
2 changes: 1 addition & 1 deletion examples/rf-transceiver/configuration.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define CONFIG_RCSwitchReceiverPin 5
#define CONFIG_RCSwitchTransmitterPin 4
#define CONFIG_RCSwitchTransmitterPin 6
#define CONFIG_RCSwitchRF_MODULE_ADDRESS "RF"

#ifdef MINI_ESP32
Expand Down
84 changes: 84 additions & 0 deletions examples/rf-transceiver/io/RFReceiver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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]>
*
*/

#include "RFReceiver.h"

namespace IO { namespace RCS {

RFReceiver *receiverInstance = NULL;

RFReceiver::RFReceiver() {
receiverInstance = this;
}

RFReceiver::RFReceiver(RFReceiverConfig *configuration) : RFReceiver() {
this->configuration = configuration;
}


//////////////////////////////
/// Public
//////////////////////////////

void RFReceiver::begin() {
Logger::info("| - %s (PIN=%d INT=%d)", RF_RFRECEIVER_NS_PREFIX,
configuration->getPin(),
configuration->getInterrupt());

//RF.setPulseLength(7000);
//RF.setReceiveTolerance(100);

RF.disableTransmit();
RF.enableReceive(configuration->getPin());

Logger::info("| ✔ %s", RF_RFRECEIVER_NS_PREFIX);
}

void RFReceiver::loop() {

if (RF.available()) { // We have captured something.

Serial.print("Received ");
Serial.print(RF.getReceivedValue());
Serial.print(" / ");
Serial.print(RF.getReceivedBitlength());
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println(RF.getReceivedProtocol());


// TODO:
// TODO:
// sendEvent((const uint8_t*)(IOEventPaths::Receiver_RawData), eventData, IOEventDataType::Undefined);
// TODO: auto eventData = RF.getReceivedValue();


RF.resetAvailable();

}

}

}} // ns
55 changes: 55 additions & 0 deletions examples/rf-transceiver/io/RFReceiver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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]>
*
*/

#ifndef HOMEGENIE_MINI_RFRECEIVER_H_
#define HOMEGENIE_MINI_RFRECEIVER_H_

#include <RCSwitch.h>

#include <HomeGenie.h>
#include <Utility.h>

#include "RFReceiverConfig.h"

#define RF_RFRECEIVER_NS_PREFIX "IO::RF::RfReceiver"

namespace IO { namespace RCS {

class RFReceiver : Task, public IIOEventSender {
public:
RFReceiver();
RFReceiver(RFReceiverConfig *);

void begin() override;
void loop() override;

private:
RFReceiverConfig* configuration;
RCSwitch RF = RCSwitch();
};

}} // ns

#endif // HOMEGENIE_MINI_RFRECEIVER_H_
4 changes: 4 additions & 0 deletions examples/rf-transceiver/io/RFReceiverConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ namespace IO { namespace RCS {
{
this->interrupt = interrupt;
}

uint8_t RFReceiverConfig::getPin() { return pin; };
uint8_t RFReceiverConfig::getInterrupt() { return interrupt; }

}} // ns
46 changes: 2 additions & 44 deletions examples/rf-transceiver/io/RFTransmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@

namespace IO { namespace RCS {

RCSwitch RF = RCSwitch();

/*
// Projector Screen commands
const long lowerMhz = 10045956;
const long raiseMhz = 10045953;
const long stopMhz = 10045954;
*/

const byte protocol = 1; // <--- See RCSwitch documentation

RFTransmitter::RFTransmitter() {
Expand All @@ -57,45 +48,12 @@ namespace IO { namespace RCS {

void RFTransmitter::begin() {
Logger::info("| - IO::RemoteControl::RFTransmitter (PIN=%d)", configuration->getPin());
RF.disableReceive();
RF.enableTransmit(configuration->getPin()); // Set RF transmit pin
RF.setProtocol(protocol); // Set RF protocal
RF.setProtocol(protocol); // Set RF protocol
Logger::info("| ✔ IO::RemoteControl::RFTransmitter");
}

/*
// TODO: code for RFReceiver.cpp
RCSwitch RF = RCSwitch();
// ....
void RFReceiver::begin() {
if (!Config::RCSwitchRFTransmitterEnabled) return;
Logger::info("| - IO::RCSwitch::RFReceiver (PIN=%d, INTERRUPT=%d)", configuration->getPin(), configuration->getInterrupt());
RF.enableReceive(D1); // Receiver on pin D1
Logger::info("| ✔ IO::RCSwitch::RFReceiver");
}
void RFReceiver::receive() {
// TODO: ...
if (RF.available()) {
Serial.print("Received ");
Serial.print(RF.getReceivedValue());
Serial.print(" / ");
Serial.print(RF.getReceivedBitlength());
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println(RF.getReceivedProtocol());
RF.resetAvailable();
}
}
// ....
*/

void RFTransmitter::sendCommand(long command, unsigned short bitLength, unsigned short repeat, unsigned short repeat_delay) {
for (int i = 0; i < repeat; i++) {
RF.send(command, bitLength);
Expand Down
2 changes: 1 addition & 1 deletion examples/rf-transceiver/io/RFTransmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace IO { namespace RCS {

private:
RFTransmitterConfig *configuration;
// TODO: declare other private members
RCSwitch RF = RCSwitch();
};

}}
Expand Down
11 changes: 9 additions & 2 deletions examples/rf-transceiver/rf-transceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "configuration.h"
#include "io/RFTransmitter.h"
#include "io/RFReceiver.h"
#include "api/RCSwitchHandler.h"

using namespace Service;
Expand All @@ -45,10 +46,16 @@ void setup() {
// RCSwitch RF Transmitter
auto rcsTransmitterConfig = new RCS::RFTransmitterConfig(CONFIG_RCSwitchTransmitterPin);
auto rcsTransmitter = new RCS::RFTransmitter(rcsTransmitterConfig);
homeGenie->addAPIHandler(new RCSwitchHandler(rcsTransmitter));

// TODO: homeGenie->addIOHandler(new RCS::RFReceiver());
auto apiHandler = new RCSwitchHandler(rcsTransmitter);
homeGenie->addAPIHandler(apiHandler);

// RCSwitch RF Receiver
auto rfModule = apiHandler->getModule(IO::IOEventDomains::HomeAutomation_RemoteControl, CONFIG_RCSwitchRF_MODULE_ADDRESS);
auto receiverConfiguration = new RCS::RFReceiverConfig(CONFIG_RCSwitchReceiverPin);
auto receiver = new RCS::RFReceiver(receiverConfiguration);
receiver->setModule(rfModule);
homeGenie->addIOHandler(receiver);

homeGenie->begin();

Expand Down
2 changes: 1 addition & 1 deletion examples/shutter/api/ShutterHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace Service { namespace API {

bool ShutterHandler::handleEvent(IIOEventSender *sender,
const char* domain, const char* address,
const unsigned char *eventPath, void *eventData, IOEventDataType dataType) {
const char *eventPath, void *eventData, IOEventDataType dataType) {
auto module = getModule(domain, address);
if (module) {
auto event = String((char *) eventPath);
Expand Down
2 changes: 1 addition & 1 deletion examples/shutter/api/ShutterHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace Service { namespace API {
bool handleRequest(APIRequest *request, ResponseCallback* responseCallback) override;
bool handleEvent(IIOEventSender *sender,
const char* domain, const char* address,
const unsigned char *eventPath, void *eventData, IOEventDataType dataType) override;
const char *eventPath, void *eventData, IOEventDataType dataType) override;

Module* getModule(const char* domain, const char* address) override;
LinkedList<Module*>* getModuleList() override;
Expand Down
8 changes: 4 additions & 4 deletions examples/shutter/io/drivers/ServoDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ namespace IO { namespace Components {

String err = "No pulse received from motor.";
Logger::info("@%s [%s %s]", SHUTTER_CONTROL_NS_PREFIX, (IOEventPaths::Status_Error), err.c_str());
eventSender->sendEvent((const uint8_t*)(IOEventPaths::Status_Error), &err, IOEventDataType::Text);
eventSender->sendEvent(IOEventPaths::Status_Error, &err, IOEventDataType::Text);

stopRequested = true;

Expand All @@ -169,15 +169,15 @@ namespace IO { namespace Components {
lastCommand = SHUTTER_COMMAND_NONE;
targetLevel = -1;
Logger::info("@%s [%s %.2f]", SHUTTER_CONTROL_NS_PREFIX, (IOEventPaths::Status_Level), currentLevel);
eventSender->sendEvent((const uint8_t*)(IOEventPaths::Status_Level), &currentLevel, IOEventDataType::Float);
eventSender->sendEvent(IOEventPaths::Status_Level, &currentLevel, IOEventDataType::Float);

} else if (lastCommand == SHUTTER_COMMAND_OPEN) {

if (millis() - lastEventMs > EVENT_EMIT_FREQUENCY) {
float level = (float)revolutions / (float)revolutionsMax;
lastEventMs = millis();
Logger::info("@%s [%s %.2f]", SHUTTER_CONTROL_NS_PREFIX, (IOEventPaths::Status_Level), level);
eventSender->sendEvent((const uint8_t *) (IOEventPaths::Status_Level), &level, IOEventDataType::Float);
eventSender->sendEvent(IOEventPaths::Status_Level, &level, IOEventDataType::Float);
}

} else if (lastCommand == SHUTTER_COMMAND_CLOSE) {
Expand All @@ -186,7 +186,7 @@ namespace IO { namespace Components {
float level = (float)revolutions / (float)revolutionsMax;
lastEventMs = millis();
Logger::info("@%s [%s %.2f]", SHUTTER_CONTROL_NS_PREFIX, (IOEventPaths::Status_Level), level);
eventSender->sendEvent((const uint8_t *) (IOEventPaths::Status_Level), &level, IOEventDataType::Float);
eventSender->sendEvent(IOEventPaths::Status_Level, &level, IOEventDataType::Float);
}

}
Expand Down
4 changes: 2 additions & 2 deletions examples/shutter/io/drivers/StepperDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ namespace IO { namespace Components {
}
void sendLevel() {
float currentLevel = ((float)currentPosition / (float)maxPosition);
Logger::info("@%s [%s %.4f]", SHUTTER_CONTROL_NS_PREFIX, (IOEventPaths::Status_Level), currentLevel);
eventSender->sendEvent(domain.c_str(), address.c_str(), (const uint8_t*)(IOEventPaths::Status_Level), &currentLevel, IOEventDataType::Float);
Logger::info("@%s [%s %.4f]", SHUTTER_CONTROL_NS_PREFIX, IOEventPaths::Status_Level, currentLevel);
eventSender->sendEvent(domain.c_str(), address.c_str(), IOEventPaths::Status_Level, &currentLevel, IOEventDataType::Float);
}
};
}}
Expand Down
Loading

0 comments on commit 2a1f70e

Please sign in to comment.