Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[T-Embed-CC1101] Encoder RGB LED Support #563

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ Also, [read our FAQ](https://github.com/pr3y/Bruce/wiki/FAQ)
| Core2 | :x: | :x: | :x: | :x: | :x: | :ok: | :ok:¹ | :x: | :x: | :x: |
| CoreSe/SE | :x: | :x: | :ok: | :x: | :x: | :x: | :ok: | :x: | :x: | :x: |
| CYD-2432S028 | :ok: | :ok: | :ok: | :x: | :ok: | :x: | :ok:¹ | :x: | :x: | :x:² |
| Lilygo T-Embed CC1101 | :ok: | :x: | :ok: | :x: | :ok: | :ok: | :ok: | :x: | :x: | :x: |
| Lilygo T-Embed CC1101 | :ok: | :x: | :ok: | :x: | :ok: | :ok: | :ok: | :ok: | :x: | :x: |
| Lilygo T-Embed | :x: | :x: | :ok: | :x: | :ok: | :ok: | :ok: | :x: | :x: | :x: |
| Lilygo T-Deck (and pro) | :x: | :x: | :ok: | :x: | :x: | :x: | :ok: | :x: | :x: | :x: |

Expand Down
15 changes: 9 additions & 6 deletions ports/lilygo-t-embed-cc1101/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@ build_flags =
-DPIN_DATA=42

;RGB LED runned by xylopyrographer/LiteLED@^1.2.0 library
;-DHAS_RGB_LED=1 ;uncomment to enable
-DRGB_LED=21
-DHAS_RGB_LED=1
-DRGB_LED=14

;Have RTC Chip
;-DHAS_RTC=1

; SERIAL (GPS) dedicated pins
-DSERIAL_TX=43 ;may be wrong
-DSERIAL_TX=43
-DSERIAL_RX=44

;Speaker to run music, compatible with NS4168
-DHAS_NS4168_SPKR=1 ;uncomment to enable
-DHAS_NS4168_SPKR=1
-DBCLK=46
-DWCLK=40
-DDOUT=7
-DMCLK=39 # Microphone CLK

;Can run USB as HID
-DUSB_as_HID=1 ;uncomment to enable
-DUSB_as_HID=1
;-DBAD_TX=GROVE_SDA
;-DBAD_RX=GROVE_SCL

Expand Down Expand Up @@ -179,8 +179,11 @@ lib_deps =
${env.lib_deps}
lewisxhe/XPowersLib @0.2.6
mathertel/RotaryEncoder @1.5.3
fastled/FastLED @3.9.4


######################################################################################################
######################################################################################################
######################################################################################################
[env:lilygo-t-embed]
platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip
board = lilygo-t-display-s3
Expand Down
2 changes: 1 addition & 1 deletion ports/m5stack-cardputer/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ build_flags =

lib_deps =
${env.lib_deps}
xylopyrographer/LiteLED@^1.2.0
fastled/FastLED @3.9.4
4 changes: 2 additions & 2 deletions src/core/menu_items/OthersMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ void OthersMenu::optionsMenu() {
{"USB Keyboard", [=]() { usb_keyboard(); }},
#endif
#ifdef HAS_RGB_LED
{"LED Control", [=]() { ledrgb_setup(); }}, // IncursioHack
{"LED FLash", [=]() { ledrgb_flash(); }}, // IncursioHack
{"LED Control", [=]() { ledColorConfig(); }},
{"LED Brightness", [=]() { ledBrightnessConfig(); }},
#endif
#ifndef LITE_VERSION
{"Openhaystack", [=]() { openhaystack_setup(); }},
Expand Down
130 changes: 92 additions & 38 deletions src/modules/others/led.cpp
Original file line number Diff line number Diff line change
@@ -1,56 +1,110 @@
#ifdef HAS_RGB_LED
// By @IncursioHack - github.com/IncursioHack
#include <LiteLED.h>
#include <FastLED.h>
#include "core/display.h"
#include "core/globals.h"
#include "led_control.h"

// Escolha o tipo de LED na lista abaixo.
// Comente todos menos um LED_TYPE.
// #define LED_TYPE LED_STRIP_WS2812
#define LED_TYPE LED_STRIP_SK6812
// #define LED_STRIP_APA106
// #define LED_STRIP_SM16703
#ifdef T_EMBED_1101
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to use the LED_TYPE as condition instead of T-EMBED? ( I'm trying to remove as much Device related MACROS from the ./src/ files and make it as generic as possible)

Otherwise we would need to add more devices in here when we could be declaring this MACRO on platformio.ini..

I would suggest to use like:

#if LED_TYPE==WS2812B
   #define LED_ORDER GRB
   #define LED_TYPE_IS_RGBW 0
   #define LED_COUNT 8
#elif LED_TYPE==SK6812
   #define LED_ORDER RGB
   #define LED_TYPE_IS_RGBW 1
   #define LED_COUNT 1
#endif

and in cardputer/platformio.ini add -DLED_TYPE=SK6812 after -DHAS_RGB_LED=1
and in t-embed/platformio.ini add -DLED_TYPE=WS2812B

if other LED models compatible with FastLED come, we can just make the proper setup in the platformio

#define LED_TYPE WS2812B
#define LED_ORDER GRB
#define LED_TYPE_IS_RGBW 0
#define LED_COUNT 8
#else
#define LED_TYPE SK6812
#define LED_ORDER RGB
#define LED_TYPE_IS_RGBW 1
#define LED_COUNT 1
#endif

#define LED_TYPE_IS_RGBW 1 // Se o LED for do tipo RGBW, altere o 0 para 1
#define LED_BRIGHT 245 // Define o brilho do LED. "0" está desligado; 255 pode queimar seus olhos (não recomendado)
#define LED_BRIGHT_DEFAULT 245

LiteLED myLED( LED_TYPE, LED_TYPE_IS_RGBW ); // Cria o objeto LiteLED com o nome "myLED"
int brightness = 75;

void ledrgb_setup() {
myLED.begin( RGB_LED, 1 ); // Inicialize o objeto myLED. Aqui temos 1 LED conectado ao pino RGB_LED
myLED.brightness( LED_BRIGHT, 1 ); // Ligue o LED
CRGB leds[LED_COUNT];
CRGB color = CRGB::Red;

CRGB hsvToRgb(uint16_t h, uint8_t s, uint8_t v)
{
uint8_t f = (h % 60) * 255 / 60;
uint8_t p = (255 - s) * (uint16_t)v / 255;
uint8_t q = (255 - f * (uint16_t)s / 255) * (uint16_t)v / 255;
uint8_t t = (255 - (255 - f) * (uint16_t)s / 255) * (uint16_t)v / 255;
uint8_t r = 0, g = 0, b = 0;
switch ((h / 60) % 6) {
case 0: r = v; g = t; b = p; break;
case 1: r = q; g = v; b = p; break;
case 2: r = p; g = v; b = t; break;
case 3: r = p; g = q; b = v; break;
case 4: r = t; g = p; b = v; break;
case 5: r = v; g = p; b = q; break;
}

CRGB c;
c.red = r;
c.green = g;
c.blue = b;
return c;
}

void setColor(CRGB c)
{
color = c;
for(int i = 0; i < LED_COUNT; i++){
leds[i] = color;
}
FastLED.show();
}

void setBrightness(int b)
{
brightness = b;
FastLED.setBrightness(brightness);
FastLED.show();
}


void ledColorConfig()
{
FastLED.addLeds<LED_TYPE, RGB_LED, LED_ORDER>(leds, LED_COUNT); // Initialize the LED Object. Only 1 LED.
setBrightness(brightness); // Set LED Brightness

options = {
{"OFF", [=]() { myLED.brightness( 0, 1 ); }},
{"PURPLE", [=]() { myLED.setPixel( 0, L_PURPLE, 1 ); }},
{"WHITE", [=]() { myLED.setPixel( 0, L_WHITE, 1 ); }},
{"RED", [=]() { myLED.setPixel( 0, L_RED, 1 ); }},
{"GREEN", [=]() { myLED.setPixel( 0, L_GREEN, 1 ); }},
{"BLUE", [=]() { myLED.setPixel( 0, L_BLUE, 1 ); }},
{"OFF", [=]()
{ setBrightness(0); }},
{"PURPLE", [=]()
{ setColor(CRGB::Purple); }},
{"WHITE", [=]()
{ setColor(CRGB::White); }},
{"RED", [=]()
{ setColor(CRGB::Red); }},
{"GREEN", [=]()
{ setColor(CRGB::Green); }},
{"BLUE", [=]()
{ setColor(CRGB::Blue); }},
};
delay(200);
loopOptions(options);
delay(200);
}

void ledrgb_flash() {
myLED.begin( RGB_LED, 1 ); // Inicialize o objeto myLED. Aqui temos 1 LED conectado ao pino RGB_LED
myLED.brightness( LED_BRIGHT_DEFAULT, 1 ); // Ligue o LED
myLED.setPixel( 0, L_PURPLE, 1 );
delay(1000);
myLED.brightness( 0, 1 );
delay(1000);
myLED.brightness( LED_BRIGHT_DEFAULT, 1 );
delay(1000);
myLED.brightness( 0, 1 );
delay(1000);
myLED.brightness( LED_BRIGHT_DEFAULT, 1 );
delay(1000);
myLED.brightness( 0, 1 );
delay(1000);
myLED.brightness( LED_BRIGHT_DEFAULT, 1 );
delay(1000);
myLED.brightness( 0, 1 );
void ledBrightnessConfig()
{

options = {
{"10", [=]()
{ setBrightness(10); }},
{"25", [=]()
{ setBrightness(20); }},
{"50", [=]()
{ setBrightness(50); }},
{"75", [=]()
{ setBrightness(75); }},
{"100", [=]()
{ setBrightness(100); }},
};

delay(200);
loopOptions(options);
delay(200);
}
#endif
35 changes: 9 additions & 26 deletions src/modules/others/led_control.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
#ifndef __LED_CONTROL_H__
#define __LED_CONTROL_H__
#ifdef HAS_RGB_LED
// By IncursioHack @github.com/IncursioHack
#include <Arduino.h>
#include <LiteLED.h>
#include <FastLED.h>

// Escolha o tipo de LED na lista abaixo. Comente todos, exceto o que você está usando.
#define LED_TYPE LED_STRIP_SK6812
// #define LED_STRIP_WS2812
// #define LED_STRIP_APA106
// #define LED_STRIP_SM16703

#define LED_TYPE_IS_RGBW 1 // Se o LED for do tipo RGBW, altere o 0 para 1

// Definição de intensidade de brilho
#define LED_BRIGHT_DEFAULT 245 // Define o brilho padrão do LED. "0" é desligado; 255 pode ser muito brilhante.

// Cores predefinidas para o LED
static const crgb_t L_RED = 0xff0000;
static const crgb_t L_GREEN = 0x00ff00;
static const crgb_t L_BLUE = 0x0000ff;
static const crgb_t L_WHITE = 0xe0e0e0;
static const crgb_t L_PURPLE = 0xff00ff;

// Declaração do objeto LiteLED
extern LiteLED myLED;

// Declarações de funções para controle do LED RGB
void ledrgb_setup();
void ledrgb_flash();
CRGB hsvToRgb(uint16_t h, uint8_t s, uint8_t v);
void setColor(CRGB c);
void setBrightness(int b);
void ledColorConfig();
void ledBrightnessConfig();

#endif
#endif
Loading