Skip to content

Commit

Permalink
v1.2.48
Browse files Browse the repository at this point in the history
- Fixed memory leak when adding/updating a schedule.
- Completed `rf-transceiver` firmware implementation.
- Updated `ir-rf-transceiver` firmware to support both X10 and RC RF.
  • Loading branch information
genemars committed Jan 20, 2025
1 parent dd81e27 commit f12389c
Show file tree
Hide file tree
Showing 61 changed files with 2,279 additions and 381 deletions.
1 change: 1 addition & 0 deletions .github/workflows/platformio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ jobs:
with:
files: |
./artifacts/*.zip
body: ${{ github.event.workflow_run.head_commit.message }}
generate_release_notes: true
163 changes: 163 additions & 0 deletions examples/color-light/StatusLed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* HomeGenie-Mini (c) 2018-2025 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_STATUSLED_H
#define HOMEGENIE_MINI_STATUSLED_H


#include <service/api/devices/ColorLight.h>

#include <Adafruit_NeoPixel.h>

#define COLOR_LIGHT_ADDRESS "C1"


using namespace Service::API::devices;

class StatusLed: Task {
private:
// Optional RGB Status LED
Adafruit_NeoPixel* statusLED = nullptr;
bool _statusLedWifiConnected = false;

// Blinks only first 20 seconds right after boot
unsigned long helloWorldDuration = 20000;
bool helloWorldActive = true;

// Status LED activity signal callback
bool signalRfReceive = false;
unsigned long signalRfReceiveTs = 0;
LightColor currentColor;
ColorLight* colorLight;

void blinkLed(bool isLedOn) {
if (statusLED == nullptr) return;
if (isLedOn) {
statusLED->setPixelColor(0, Adafruit_NeoPixel::Color(100, 100, 0));
} else {
statusLED->setPixelColor(0, Adafruit_NeoPixel::Color(0, 0, 0));
}
statusLED->show();
}

public:
StatusLed() {
setLoopInterval(10);
}

void setup() {
#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();
// Status LED Blink callback
Config::statusLedCallback([this](bool isLedOn) {
blinkLed(isLedOn);
});
}
#endif
// Setup master LED control module
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");

colorLight->onSetColor([this](LightColor c) {
if (statusLED != nullptr) {
statusLED->setPixelColor(0, c.getRed(), c.getGreen(), c.getBlue());
statusLED->show();
currentColor.setColor(c.getHue(), c.getSaturation(), c.getValue(), 0);
}
});

auto hg = Service::HomeGenie::getInstance();
hg->addAPIHandler(colorLight);
}

void loop() override {
if (statusLED != nullptr) {
if (helloWorldActive && millis() > helloWorldDuration && Config::isDeviceConfigured()) {
// stops blinking if "helloWorldDuration" is elapsed
helloWorldActive = false;
Config::statusLedCallback(nullptr);
} else if (WiFi.isConnected() != _statusLedWifiConnected) {
_statusLedWifiConnected = WiFi.isConnected();
if (_statusLedWifiConnected) {
// turn off status LED blinking if connected
if (!helloWorldActive) {
Config::statusLedCallback(nullptr);
}
} else {
// blinks status LED rapidly if not connected
Config::statusLedCallback([this](bool isLedOn) {
blinkLed(isLedOn);
});
}
}
}

if (signalRfReceive && millis() - signalRfReceiveTs > 50) {
signalRfReceive = false;
if (statusLED != nullptr) {
statusLED->setPixelColor(0, currentColor.getRed(), currentColor.getGreen(), currentColor.getBlue());
statusLED->show();
}
}
}

void signalActivity(uint8_t r, uint8_t g, uint8_t b) {
if (statusLED != nullptr) {
statusLED->setPixelColor(0, r, g, b);
statusLED->show();
}
signalRfReceive = true;
signalRfReceiveTs = millis();
}

bool isEnabled() {
return statusLED != nullptr;
}
Adafruit_NeoPixel* getLed() {
return statusLED;
}
ColorLight* getColorLight() {
return colorLight;
}
LightColor& getCurrentColor() {
return currentColor;
}
void setCurrentColor(LightColor c) {
currentColor = c;
}

};

#endif //HOMEGENIE_MINI_STATUSLED_H
13 changes: 5 additions & 8 deletions examples/color-light/color-light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void setup() {
mpMaxPower = new ModuleParameter("LED.power", "25");
miniModule->properties.add(mpMaxPower);

colorLight = statusLedSetup();
statusLed.setup();
colorLight = statusLed.getColorLight();

isConfigured = Config::isDeviceConfigured();
if (!isConfigured) {
Expand Down Expand Up @@ -86,7 +87,7 @@ void setup() {

// Setup main LEDs control module
colorLight->onSetColor([](LightColor color) {
currentColor = color;
statusLed.setCurrentColor(color);
fx_reset(pixels, color);
});
homeGenie->addAPIHandler(colorLight);
Expand Down Expand Up @@ -116,7 +117,7 @@ void setup() {
#endif

// Initialize FX buffer
fx_init(ledsCount, currentColor);
fx_init(ledsCount, statusLed.getCurrentColor());

// TODO: implement color/status recall on start
// Set default color
Expand Down Expand Up @@ -167,6 +168,7 @@ void loop()

} else {

auto currentColor = statusLed.getCurrentColor();
// apply selected light style
switch (currentStyleIndex) {
case LightStyles::RAINBOW:
Expand Down Expand Up @@ -230,9 +232,4 @@ void loop()
}

}

#ifdef BOARD_HAS_RGB_LED
// Custom status led (builtin NeoPixel RGB LED)
statusLedLoop();
#endif
}
24 changes: 13 additions & 11 deletions examples/color-light/color-light.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@

#include "configuration.h"
#include "color-fx.h"
#include "status-led.h"

#include "StatusLed.h"
StatusLed statusLed;

using namespace Service;
using namespace Service::API::devices;

HomeGenie* homeGenie;
bool isConfigured = false;

// Master/Status LED
ColorLight* colorLight;

// LED strip
uint16_t ledsCount = 0; int16_t ledsPin = -1;
int16_t pixelsType, pixelsSpeed;
Expand Down Expand Up @@ -84,9 +89,6 @@ uint8_t getLightStyleIndex(String& styleName) {
return 0;
}

ColorLight* colorLight;
LightColor currentColor;

ModuleParameter* mpLedCount;
ModuleParameter* mpMaxPower;
ModuleParameter* mpFxStyle;
Expand All @@ -106,8 +108,8 @@ bool strobeOff = true;
uint8_t currentStyleIndex = 0;

void refresh() {
if (statusLED != nullptr) {
statusLED->show();
if (statusLed.isEnabled()) {
statusLed.getLed()->show();
}
if (pixels != nullptr) {
pixels->show();
Expand All @@ -124,11 +126,11 @@ void renderPixels() {
static_cast<int>(round(animatedColors[i]->getBlue() * pwr)));
}
}
if (statusLED != nullptr) {
statusLED->setPixelColor(0,
static_cast<int>(round(animatedColors[0]->getRed())),
static_cast<int>(round(animatedColors[0]->getGreen())),
static_cast<int>(round(animatedColors[0]->getBlue())));
if (statusLed.isEnabled()) {
statusLed.getLed()->setPixelColor(0,
static_cast<int>(round(animatedColors[0]->getRed())),
static_cast<int>(round(animatedColors[0]->getGreen())),
static_cast<int>(round(animatedColors[0]->getBlue())));
}
}

Expand Down
100 changes: 0 additions & 100 deletions examples/color-light/status-led.h

This file was deleted.

1 change: 0 additions & 1 deletion examples/ir-rf-transceiver/configuration.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Default config

#include "../ir-transceiver/configuration.h"
// TODO: verify if X10 and RCSwitch can share same module address
#include "../rf-transceiver/configuration.h"
#include "../x10-transceiver/configuration.h"
Loading

0 comments on commit f12389c

Please sign in to comment.