Skip to content

Commit

Permalink
v1.2.45
Browse files Browse the repository at this point in the history
- added parameters for configuring receiver and transmitter GPIOs# to IR and X10 transceiver firmwares
  • Loading branch information
genemars committed Jan 7, 2025
1 parent 6585bd6 commit c5fcb9d
Show file tree
Hide file tree
Showing 26 changed files with 363 additions and 137 deletions.
13 changes: 11 additions & 2 deletions examples/color-light/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ In addition to default system options the following configuration options are av
|------------|-----------------------------|-----------------------------------------|
| `leds-pin` | LED strip GPIO pin number | -1 (-1=not used) |
| `leds-cnt` | Number of LEDs | 1 (1 - 200) |
| `stld-typ` | LEDs type | RGB/RGBW order mask (see code for ref.) |
| `leds-spd` | Data transfer speed | 0 (0=800kHz, 256=400kHz) |
| `stld-pin` | Status LED (RGB) pin | -1 (-1=not used) |
| `stld-typ` | Status LED type | RGB/RGBW order mask (see code for ref.) |
Expand All @@ -32,4 +31,14 @@ and using the following command for flashing the firmware:
pio run -e color-light[<target>] -t upload
```

where the optional `<target>` suffix can be one of the following: `-c3`, `-d1-mini`.
where the optional `<target>` suffix can be one of the following:
- ESP8266
`-d1-mini`
- ESP32 (generic)
*none*
- ESP32-C3
`-c3`
- ESP32-S3
`-s3`
- ESP32 D1 Mini
`-d1-mini-esp32`
4 changes: 2 additions & 2 deletions examples/color-light/color-light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "color-light.h"

void setup() {
// Default name shown in SMNP/UPnP advertising
// Default name shown in SNMP/UPnP advertising
Config::system.friendlyName = "LED Controller";

// Get a reference to HomeGenie Mini running instance
Expand Down Expand Up @@ -94,7 +94,7 @@ void setup() {
mpMaxPower->value = String(maxPower);

// Setup main LEDs control module
colorLight = new ColorLight(IO::IOEventDomains::HomeAutomation_HomeGenie, "C1", "Color Light");
colorLight = new ColorLight(IO::IOEventDomains::HomeAutomation_HomeGenie, COLOR_LIGHT_ADDRESS, "Color Light");
colorLight->module->setProperty("Widget.Implements.Scheduling", "1");
colorLight->module->setProperty("Widget.Implements.Scheduling.ModuleEvents", "1");
colorLight->module->setProperty("Widget.Preference.AudioLight", "true");
Expand Down
2 changes: 2 additions & 0 deletions examples/color-light/status-led.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include <Adafruit_NeoPixel.h>

#define COLOR_LIGHT_ADDRESS "C1"

// Optional RGB Status LED
Adafruit_NeoPixel* statusLED = nullptr;
bool _statusLedWifiConnected = true;
Expand Down
41 changes: 41 additions & 0 deletions examples/ir-transceiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ir-transceiver

A smart IR gateway device.

- [Documentation and firmware install page](https://homegenie.it/mini/1.2/examples/ir-rf-gateway/)


## Firmware configuration

In addition to default system options the following configuration options are available:

| Key | Description | Default |
|------------|----------------------|-----------------------------------------|
| `stld-pin` | Status LED (RGB) pin | -1 (-1=not used) |
| `stld-typ` | Status LED type | RGB/RGBW order mask (see code for ref.) |
| `stld-spd` | Status LED speed | 0 (0=800kHz, 256=400kHz) |
| `irrc-pin` | IR Receiver GPIO # | 7 |
| `irtr-pin` | IR Transmitter GPIO# | 5 |


### Manual build and install

You can also manually build and install the firmware from source code
as explained in the [Getting started](../../getting-started#custom-firmware) page
and using the following commands for flashing the firmware:

```bash
pio run -e ir-transceiver[<target>] -t upload
```

where the optional `<target>` suffix can be one of the following:
- ESP8266
`-d1-mini`
- ESP32 (generic)
*none*
- ESP32-C3
`-c3`
- ESP32-S3
`-s3`
- ESP32 D1 Mini
`-d1-mini-esp32`
35 changes: 22 additions & 13 deletions examples/ir-transceiver/api/IRTransceiverHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,37 @@

namespace Service { namespace API {

IRTransceiverHandler::IRTransceiverHandler(IRTransmitter* transmitter, IRReceiver* receiver) {
this->transmitter = transmitter;
transmitter->setListener(this);
this->receiver = receiver;
void IRTransceiverHandler::setReceiver(IRReceiver* r) {
receiver = r;
}

void IRTransceiverHandler::setTransmitter(IRTransmitter* t) {
this->transmitter = t;
t->setListener(this);
}

auto domain = IO::IOEventDomains::HomeAutomation_RemoteControl;
// HomeGenie Mini module
void IRTransceiverHandler::init() {
// Add IR sensor module
auto irModule = new Module();
irModule->domain = domain;
irModule->domain = IO::IOEventDomains::HomeAutomation_RemoteControl;
irModule->address = CONFIG_IR_MODULE_ADDRESS;
irModule->type = "Sensor";
irModule->name = CONFIG_IR_MODULE_ADDRESS; //TODO: CONFIG_IR_MODULE_NAME;

// explicitly enable "scheduling" features for this module
irModule->setProperty("Widget.Implements.Scheduling", "1");
irModule->setProperty("Widget.Implements.Scheduling.ModuleEvents", "1");

// add properties
irModule->setProperty(IOEventPaths::Receiver_RawData, "");
rawDataParameter = new ModuleParameter(IOEventPaths::Receiver_RawData);
irModule->properties.add(rawDataParameter);
rawDataParameter->value = "";

moduleList.add(irModule);

receiver->setModule(irModule);
}

void IRTransceiverHandler::init() {
transmitter->begin();
//receiver->begin(); <-- this is already done automatically by "IIOEventSender" parent class
receiver->setModule(irModule);
}

bool IRTransceiverHandler::handleRequest(APIRequest *command, ResponseCallback* responseCallback) {
Expand Down Expand Up @@ -96,9 +102,12 @@ namespace Service { namespace API {

// Event Stream Message Enqueue (for MQTT/SSE/WebSocket propagation)
auto m = QueuedMessage(domain, address, event.c_str(), stringData, eventData, dataType);
// module->setProperty(event, m.value, eventData, dataType);
HomeGenie::getInstance()->getEventRouter().signalEvent(m);

// Update module parameter as well
rawDataParameter->setData(eventData, dataType);
rawDataParameter->setValue(m.value.c_str());

return true;
}

Expand Down
8 changes: 5 additions & 3 deletions examples/ir-transceiver/api/IRTransceiverHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ namespace Service { namespace API {
class IRTransceiverHandler : public APIHandler, IRTransmitterListener {
private:
LinkedList<Module*> moduleList;
IRTransmitter* transmitter;
IRReceiver* receiver;
ModuleParameter* rawDataParameter{};
IRTransmitter* transmitter = nullptr;
IRReceiver* receiver = nullptr;
public:
IRTransceiverHandler(IRTransmitter*,IRReceiver*);
void setReceiver(IRReceiver*);
void setTransmitter(IRTransmitter*);
void init() override;
bool canHandleDomain(String* domain) override;
bool handleRequest(APIRequest*, ResponseCallback*) override;
Expand Down
10 changes: 2 additions & 8 deletions examples/ir-transceiver/configuration.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#define CONFIG_IRReceiverPin 5
#define CONFIG_IRTransmitterPin 7

#ifndef CONFIG_StatusLedNeoPixelPin
#ifdef ESP32_C3
#define CONFIG_StatusLedNeoPixelPin 10
#endif
#endif
#define CONFIG_IRReceiverPin 7
#define CONFIG_IRTransmitterPin 5

#define CONFIG_IR_MODULE_ADDRESS "IR"
8 changes: 2 additions & 6 deletions examples/ir-transceiver/io/IRReceiverConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@

namespace IO { namespace IR {

IRReceiverConfig::IRReceiverConfig()
IRReceiverConfig::IRReceiverConfig(uint8_t pin)
{
pin = interrupt = CONFIG_IRReceiverPin; // 5
}
IRReceiverConfig::IRReceiverConfig(uint8_t pin) : IRReceiverConfig()
{
this->pin = pin;
this->pin = this->interrupt = pin;
}
IRReceiverConfig::IRReceiverConfig(
uint8_t interrupt, uint8_t pin
Expand Down
5 changes: 2 additions & 3 deletions examples/ir-transceiver/io/IRReceiverConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ namespace IO { namespace IR {
class IRReceiverConfig
{
public:
IRReceiverConfig();
IRReceiverConfig(uint8_t pin);
explicit IRReceiverConfig(uint8_t pin);
IRReceiverConfig(uint8_t interrupt, uint8_t pin);
uint8_t getPin();
uint8_t getInterrupt();
private:
uint8_t interrupt;
uint8_t interrupt{};
uint8_t pin;
};
}} // ns
Expand Down
5 changes: 1 addition & 4 deletions examples/ir-transceiver/io/IRTransmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@

namespace IO { namespace IR {

IRTransmitter::IRTransmitter() {
IRTransmitter::IRTransmitter(IRTransmitterConfig *configuration) {
setLoopInterval(100);
}

IRTransmitter::IRTransmitter(IRTransmitterConfig *configuration) : IRTransmitter() {
this->configuration = configuration;
}

Expand Down
3 changes: 1 addition & 2 deletions examples/ir-transceiver/io/IRTransmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ namespace IO { namespace IR {

class IRTransmitter: Task {
public:
IRTransmitter();
IRTransmitter(IRTransmitterConfig *);
explicit IRTransmitter(IRTransmitterConfig *);

void begin();
void loop() override;
Expand Down
6 changes: 1 addition & 5 deletions examples/ir-transceiver/io/IRTransmitterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@
#include "IRTransmitterConfig.h"

namespace IO { namespace IR {
IRTransmitterConfig::IRTransmitterConfig()
{
pin = CONFIG_IRTransmitterPin;
}
IRTransmitterConfig::IRTransmitterConfig(uint8_t pin) : IRTransmitterConfig()
IRTransmitterConfig::IRTransmitterConfig(uint8_t pin)
{
this->pin = pin;
}
Expand Down
105 changes: 57 additions & 48 deletions examples/ir-transceiver/ir-transceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,74 +32,83 @@
#include "io/IRTransmitter.h"
#include "api/IRTransceiverHandler.h"

#ifdef ESP32_C3
#ifdef BOARD_HAS_RGB_LED
#include <service/api/devices/ColorLight.h>
#include "../color-light/status-led.h"
using namespace Service::API::devices;
unsigned long helloWorldDuration = 10000;
bool helloWorldActive = true;
#endif

using namespace Service;

HomeGenie* homeGenie;


#ifdef ESP32_C3
using namespace Service::API::devices;
#include <Adafruit_NeoPixel.h>
// Custom status led (builtin NeoPixel RGB on pin 10)
Adafruit_NeoPixel pixels(1, CONFIG_StatusLedNeoPixelPin, NEO_GRB + NEO_KHZ800);
void statusLedCallback(bool isLedOn) {
if (isLedOn) {
pixels.setPixelColor(0, Adafruit_NeoPixel::Color(50, 50, 0));
} else {
pixels.setPixelColor(0, Adafruit_NeoPixel::Color(0, 0, 0));
}
pixels.show();
}
unsigned long helloWorldDuration = 10000;
bool helloWorldActive = true;
#endif

void setup() {
// Default name shown in SMNP/UPnP advertising
// Default name shown in SNMP/UPnP advertising
Config::system.friendlyName = "Firefly IR";

#ifdef ESP32_C3
// Custom status led (builtin NeoPixel RGB on pin 10)
// if (!Config::isDeviceConfigured()) {
Config::statusLedCallback(&statusLedCallback);
// }
pixels.begin();
#endif

homeGenie = HomeGenie::getInstance();

auto receiverConfiguration = new IR::IRReceiverConfig(CONFIG_IRReceiverPin);
auto receiver = new IR::IRReceiver(receiverConfiguration);
homeGenie->addIOHandler(receiver);

auto transmitterConfig = new IR::IRTransmitterConfig(CONFIG_IRTransmitterPin);
auto transmitter = new IR::IRTransmitter(transmitterConfig);
homeGenie->addAPIHandler(new IRTransceiverHandler(transmitter, receiver));

#ifdef ESP32_C3
auto colorLight = new ColorLight(IO::IOEventDomains::HomeAutomation_HomeGenie, "C1", "Demo Light");
colorLight->onSetColor([](LightColor c) {
pixels.setPixelColor(0, c.getRed(), c.getGreen(), c.getBlue());
pixels.show();
});
homeGenie->addAPIHandler(colorLight);
auto miniModule = homeGenie->getDefaultModule();
miniModule->setProperty("Widget.Implements.Scheduling", "1");

#ifdef BOARD_HAS_RGB_LED
// Get status LED config
auto pin = Config::getSetting("stld-pin");
int statusLedPin = pin.isEmpty() ? -1 : pin.toInt();
if (statusLedPin >= 0) {
int statusLedType = Config::getSetting("stld-typ", "82").toInt();
int statusLedSpeed = Config::getSetting("stld-spd", "0").toInt();
statusLED = new Adafruit_NeoPixel(1, statusLedPin, statusLedType + statusLedSpeed);
statusLED->setPixelColor(0, 0, 0, 0);
statusLED->begin();
}
// Custom status led (builtin NeoPixel RGB LED)
if (statusLED != nullptr) {
// Setup main LEDs control module
auto colorLight = new ColorLight(IO::IOEventDomains::HomeAutomation_HomeGenie, COLOR_LIGHT_ADDRESS, "Status LED");
colorLight->module->setProperty("Widget.Implements.Scheduling", "1");
colorLight->module->setProperty("Widget.Implements.Scheduling.ModuleEvents", "1");
colorLight->module->setProperty("Widget.Preference.AudioLight", "true");
colorLight->onSetColor([](LightColor c) {
statusLED->setPixelColor(0, c.getRed(), c.getGreen(), c.getBlue());
statusLED->show();
});
homeGenie->addAPIHandler(colorLight);
}
#endif

auto apiHandler = new IRTransceiverHandler();
homeGenie->addAPIHandler(apiHandler);
// IR receiver pin
uint8_t irReceiverPin = Config::getSetting("irrc-pin", String(CONFIG_IRReceiverPin).c_str()).toInt();
if (irReceiverPin > 0) {
auto receiverConfiguration = new IR::IRReceiverConfig(irReceiverPin);
auto receiver = new IR::IRReceiver(receiverConfiguration);
apiHandler->setReceiver(receiver);
homeGenie->addIOHandler(receiver);
}
// IR transmitter pin
uint8_t irTransmitterPin = Config::getSetting("irtr-pin", String(CONFIG_IRTransmitterPin).c_str()).toInt();
if (irTransmitterPin > 0) {
auto transmitterConfig = new IR::IRTransmitterConfig(irTransmitterPin);
auto transmitter = new IR::IRTransmitter(transmitterConfig);
apiHandler->setTransmitter(transmitter);
}

homeGenie->begin();
}


void loop()
{
homeGenie->loop();
#ifdef ESP32_C3
if (helloWorldActive && millis() > helloWorldDuration && Config::isDeviceConfigured()) {
helloWorldActive = false;
Config::statusLedCallback(nullptr);
#ifdef BOARD_HAS_RGB_LED
if (statusLED != nullptr) {
if (helloWorldActive && millis() > helloWorldDuration && Config::isDeviceConfigured()) {
helloWorldActive = false;
Config::statusLedCallback(nullptr);
}
}
#endif
}
Loading

0 comments on commit c5fcb9d

Please sign in to comment.