Skip to content

Commit

Permalink
v1.2.22
Browse files Browse the repository at this point in the history
- added configuration parameters get/set via serial connection
- enabled API commands input via serial connection
- unified `color-light` firmware by adding configurable parameters
- added `#VERSION` command to retrieve firmware version info
  • Loading branch information
genemars committed Jun 19, 2024
1 parent f54e40e commit 02160be
Show file tree
Hide file tree
Showing 16 changed files with 258 additions and 142 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
cmake-build-debug
CMakeFiles
.idea
artifacts

# Clion

Expand Down
53 changes: 53 additions & 0 deletions examples/color-light/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# color-light

A smart light device with addressable RGB LEDs.

- [Documentation and firmware install page](https://homegenie.it/mini/1.2/examples/smart-led-lights/)


## Firmware configuration

| Key | Description | Default |
|------------|----------------------------|-----------------------------------------|
| `leds-pin` | LEDs 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.) |
| `stld-spd` | Status LED speed | 0 (0=800MHz, 256=400MHz) |

*Example **setting** configuration from a terminal connected to the serial port of the device:*

```
#SET:leds-pin=5
#SET:leds-cnt=25
#SET:leds-typ=6
#SET:leds-spd=0
#SET:stld-pin=10
#SET:stld-typ=82
#SET:stld-spd=0
#RESET
```

*Example **getting** configuration value:*

```
#GET:stl-pin
```
response:
```
#GET:stl-pin=10
```

## Manual build and install

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

```bash
pio run -e color-light[<target>] -t upload
```

where the optional `<target>` suffix can be one of the following: `-c3`, `-d1-mini`.
112 changes: 72 additions & 40 deletions examples/color-light/color-light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,92 +36,124 @@ using namespace Service::API::devices;

HomeGenie* homeGenie;

Adafruit_NeoPixel statusLED(1, CONFIG_StatusLedNeoPixelPin, NEO_GRB + NEO_KHZ800);
// Optional RGB Status LED
Adafruit_NeoPixel* statusLED = nullptr;

#ifdef LED_ARRAY_COUNT
int num = LED_ARRAY_COUNT; // 90 = 3mt // 30 LEDs per meter (3 mt. strip)
int pin = LED_ARRAY_PIN;
Adafruit_NeoPixel pixels(num, pin, NEO_RGB + NEO_KHZ800);
#endif
// LED strip/array
int count = 0; int pin = -1;
Adafruit_NeoPixel* pixels = nullptr;

bool changed = false;
unsigned long lastRefreshTs = 0;

// LED Blink callback when statusLED is configured
void statusLedCallback(bool isLedOn) {
if (isLedOn) {
statusLED.setPixelColor(0, Adafruit_NeoPixel::Color(1, 1, 0));
statusLED->setPixelColor(0, Adafruit_NeoPixel::Color(1, 1, 0));
} else {
statusLED.setPixelColor(0, Adafruit_NeoPixel::Color(0, 0, 0));
statusLED->setPixelColor(0, Adafruit_NeoPixel::Color(0, 0, 0));
}
statusLED.show();
statusLED->show();
}

void setup() {
homeGenie = HomeGenie::getInstance();

// Get status LED config
int statusLedPin = Config::getSetting("stld-pin", "0").toInt();
if (statusLedPin > 0) {
int statusLedType = Config::getSetting("stld-typ", "0").toInt();
int statusLedSpeed = Config::getSetting("stld-spd", "0").toInt();
statusLED = new Adafruit_NeoPixel(1, statusLedPin, statusLedType + statusLedSpeed);
}

if (!Config::isDeviceConfigured()) {

// Custom status led (builtin NeoPixel RGB on pin 10)
Config::statusLedCallback(&statusLedCallback);
if (statusLED != nullptr) {
Config::statusLedCallback(&statusLedCallback);
}

} else {

// Get LED strip config
count = Config::getSetting("leds-cnt", "0").toInt(); // 90 = 3mt // 30 LEDs per meter (3 mt. strip)
pin = (int16_t)Config::getSetting("leds-pin", "-1").toInt();
if (count > 0 && pin != -1) {
auto pixelsType = (int16_t)Config::getSetting("leds-typ", "-1").toInt();
auto pixelsSpeed = (int16_t)Config::getSetting("leds-spd", "0").toInt();
pixels = new Adafruit_NeoPixel(count, pin, pixelsType + pixelsSpeed);
}

// Setup Status LED as master channel
auto colorLight = new ColorLight(IO::IOEventDomains::HomeAutomation_HomeGenie, "C1", "Demo Light");
colorLight->onSetColor([](float r, float g, float b) {
statusLED.setPixelColor(0, r, g, b);
#ifdef LED_ARRAY_COUNT
for (int i = 0; i < num; i++) {
pixels.setPixelColor(i, r, g, b);
if (statusLED != nullptr) {
statusLED->setPixelColor(0, r, g, b);
}
#endif

for (int i = 0; i < count; i++) {
pixels->setPixelColor(i, r, g, b);
}

changed = true;
if (millis() - lastRefreshTs > 50) { // force 20fps max
statusLED.show();
#ifdef LED_ARRAY_COUNT
pixels.show();
#endif
if (statusLED != nullptr) {
statusLED->show();
}
if (pixels != nullptr) {
pixels->show();
}
lastRefreshTs = millis();
changed = false;
}
});
homeGenie->addAPIHandler(colorLight);

#ifdef LED_ARRAY_COUNT
for (int i = 0; i < num; i++) {
auto address = String("L") + String(i + 1);
auto cl = new ColorLight(IO::IOEventDomains::HomeAutomation_HomeGenie, address.c_str(), "Demo Light");
cl->onSetColor([i](float r, float g, float b) {
pixels.setPixelColor(i, r, g, b);
changed = true;
if (millis() - lastRefreshTs > 50) { // force 20fps max
pixels.show();
lastRefreshTs = millis();
changed = false;
}
});
homeGenie->addAPIHandler(cl);
// Setup LED strip/array
if (pixels != nullptr) {
for (int i = 0; i < count; i++) {
auto address = String("L") + String(i + 1);
auto cl = new ColorLight(IO::IOEventDomains::HomeAutomation_HomeGenie, address.c_str(), "Demo Light");
cl->onSetColor([i](float r, float g, float b) {
pixels->setPixelColor(i, r, g, b);
changed = true;
if (millis() - lastRefreshTs > 50) { // force 20fps max
pixels->show();
lastRefreshTs = millis();
changed = false;
}
});
homeGenie->addAPIHandler(cl);
}
}
#endif

// TODO: implement color/status recall on start
// TODO: implement color/status recall on start
// TODO: implement color/status recall on start

}

statusLED.begin();
if (statusLED != nullptr) {
statusLED->begin();
}
if (pixels != nullptr) {
pixels->begin();
}
homeGenie->begin();
}

void loop()
{
homeGenie->loop();

if (changed) { // trailing fx
changed = false;
statusLED.show();
#ifdef LED_ARRAY_COUNT
pixels.show();
#endif
if (statusLED != nullptr) {
statusLED->show();
}
if (pixels != nullptr) {
pixels->show();
}
lastRefreshTs = millis();
}
}
3 changes: 0 additions & 3 deletions examples/color-light/configuration.h
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
#ifndef CONFIG_StatusLedNeoPixelPin
#define CONFIG_StatusLedNeoPixelPin 10
#endif
2 changes: 2 additions & 0 deletions examples/ir-transceiver/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#define CONFIG_IRTransmitterPin 7

#ifndef CONFIG_StatusLedNeoPixelPin
#ifdef ESP32_C3
#define CONFIG_StatusLedNeoPixelPin 10
#endif
#endif

#define CONFIG_IR_MODULE_ADDRESS "IR"

Expand Down
9 changes: 8 additions & 1 deletion examples/ir-transceiver/io/IRReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ namespace IO { namespace IR {
Logger::info("| - %s (PIN=%d INT=%d)", IR_IRRECEIVER_NS_PREFIX,
configuration->getPin(),
configuration->getInterrupt());

#ifdef ESP8266
irReceiver = new IRrecv(configuration->getPin(), 1024, 50, false);
#else
irReceiver = new IRrecv(configuration->getPin(), 1024, 50, false, 1);
#endif
//irReceiver->setTolerance(10);
enabled(true);

Expand Down Expand Up @@ -84,7 +87,11 @@ namespace IO { namespace IR {
sSize = Utility::byteToHex((uint16_t )(size / 8));
sData = Utility::getByteString(results.state, size / 8);
} else { // simple message protocol (<= 64 bits)
#ifdef ESP8266
sData = String((unsigned long)results.value, HEX);
#else
sData = String(results.value, HEX);
#endif
}

if (sData != "ffffffffffffffff") {
Expand Down
57 changes: 27 additions & 30 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ data_dir = ./data/web

[env]
build_src_filter = -<*> +<src/*>
build_flags = -D CRON_USE_LOCAL_TIME -DCRON_DISABLE_YEARS -Os
build_flags = -D CRON_USE_LOCAL_TIME -D CRON_DISABLE_YEARS -Os -D BUILD_ENV_NAME=\"$PIOENV\"
build_unflags = -fno-exceptions
framework = arduino
board = esp32dev
board_build.filesystem = littlefs
board_build.flash_size = 4MB
board_build.partitions = ./src/partitions.csv
monitor_filters = send_on_enter
monitor_eol = LF
monitor_echo = true
lib_deps =
[email protected]
thijse/[email protected]
Expand All @@ -32,6 +35,8 @@ lib_deps =
lovyan03/[email protected]
dvarrel/[email protected]
jpb10/[email protected]
lib_deps_8266 =
vshymanskyy/[email protected]


[env:default]
Expand All @@ -43,6 +48,8 @@ build_flags = ${env.build_flags}
platform = [email protected]
board = d1_mini
build_flags = ${env.build_flags} -D DISABLE_UI -D DISABLE_AUTOMATION
lib_deps = ${env.lib_deps_8266}
${env.lib_deps}
lib_ignore =
ESP32Time
ESP32_BleSerial
Expand Down Expand Up @@ -84,7 +91,8 @@ platform = [email protected]
board = d1_mini
build_flags = ${env.build_flags} -I examples -I src -D DISABLE_UI -D DISABLE_AUTOMATION
build_src_filter = +<src> -<src/main.cpp> +<examples/smart-sensor>
lib_deps = ${env.lib_deps}
lib_deps = ${env.lib_deps_8266}
${env.lib_deps}
[email protected]
lib_ignore =
ESP32Time
Expand Down Expand Up @@ -133,6 +141,8 @@ platform = [email protected]
board = d1_mini
build_flags = ${env.build_flags} -D DISABLE_UI
build_src_filter = +<src> -<src/main.cpp> +<examples/x10-transceiver>
lib_deps = ${env.lib_deps_8266}
${env.lib_deps}
lib_ignore =
ESP32Time
ESP32_BleSerial
Expand All @@ -150,7 +160,8 @@ platform = [email protected]
board = d1_mini
build_flags = ${env.build_flags} -D DISABLE_UI
build_src_filter = +<src> -<src/main.cpp> +<examples/rf-transceiver>
lib_deps = ${env.lib_deps}
lib_deps = ${env.lib_deps_8266}
${env.lib_deps}
[email protected]
lib_ignore =
ESP32Time
Expand Down Expand Up @@ -178,6 +189,19 @@ lib_deps = ${env.lib_deps}
lib_ignore =
LovyanGFX

[env:ir-transceiver-d1-mini]
platform = [email protected]
board = d1_mini
build_flags = ${env.build_flags} -D DISABLE_UI
build_src_filter = +<src> -<src/main.cpp> +<examples/ir-transceiver>
lib_deps = ${env.lib_deps_8266}
${env.lib_deps}
crankyoldgit/[email protected]
lib_ignore =
ESP32Time
ESP32_BleSerial
LovyanGFX

[env:ir-transceiver-c3]
platform = [email protected]
board = esp32-c3-devkitc-02
Expand Down Expand Up @@ -207,33 +231,6 @@ build_src_filter = +<src> -<src/main.cpp> +<lib/jerryscript/amalgam/*> +<example
lib_deps = ${env.lib_deps}
https://github.com/adafruit/Adafruit_NeoPixel#1.12.0

[env:color-light-c3-25]
platform = [email protected]
board = esp32-c3-devkitc-02
#board = esp32-c3-devkitm-1
build_flags = ${env.build_flags} -I examples -I src -D ESP32_C3 -D DISABLE_UI -D CONFIG_StatusLedPin=-1 -D LED_ARRAY_COUNT=25 -D LED_ARRAY_PIN=8 -D ARDUINO_USB_MODE=1 -D ARDUINO_USB_CDC_ON_BOOT=1
build_src_filter = +<src> -<src/main.cpp> +<examples/color-light>
lib_deps = ${env.lib_deps}
https://github.com/adafruit/Adafruit_NeoPixel#1.12.0

[env:color-light-c3-64]
platform = [email protected]
board = esp32-c3-devkitc-02
#board = esp32-c3-devkitm-1
build_flags = ${env.build_flags} -I examples -I src -D ESP32_C3 -D DISABLE_UI -D CONFIG_StatusLedPin=-1 -D LED_ARRAY_COUNT=64 -D LED_ARRAY_PIN=5 -D ARDUINO_USB_MODE=1 -D ARDUINO_USB_CDC_ON_BOOT=1
build_src_filter = +<src> -<src/main.cpp> +<examples/color-light>
lib_deps = ${env.lib_deps}
https://github.com/adafruit/Adafruit_NeoPixel#1.12.0

[env:color-light-c3-90]
platform = [email protected]
board = esp32-c3-devkitc-02
#board = esp32-c3-devkitm-1
build_flags = ${env.build_flags} -I examples -I src -D ESP32_C3 -D DISABLE_UI -D CONFIG_StatusLedPin=-1 -D LED_ARRAY_COUNT=90 -D LED_ARRAY_PIN=5 -D ARDUINO_USB_MODE=1 -D ARDUINO_USB_CDC_ON_BOOT=1
build_src_filter = +<src> -<src/main.cpp> +<examples/color-light>
lib_deps = ${env.lib_deps}
https://github.com/adafruit/Adafruit_NeoPixel#1.12.0


[env:shutter]
platform = [email protected]
Expand Down
Loading

0 comments on commit 02160be

Please sign in to comment.