Skip to content

Commit

Permalink
Without FlashLED functions
Browse files Browse the repository at this point in the history
  • Loading branch information
norbert-walter committed Sep 18, 2024
1 parent 1b7c0f6 commit da4089c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 106 deletions.
88 changes: 7 additions & 81 deletions lib/obp60task/OBP60Extensions.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#ifdef BOARD_OBP60S3

#include <Arduino.h>
#define FASTLED_ALL_PINS_HARDWARE_SPI
#define FASTLED_ESP32_SPI_BUS FSPI
#define FASTLED_ESP32_FLASH_LOCK 1
#include <FastLED.h> // Driver for WS2812 RGB LED
#include <PCF8574.h> // Driver for PCF8574 output modul from Horter
#include <Wire.h> // I2C
#include <RTClib.h> // Driver for DS1388 RTC
Expand Down Expand Up @@ -61,8 +57,8 @@ GxEPD2_BW<GxEPD2_420_SE0420NQ04, GxEPD2_420_SE0420NQ04::HEIGHT> & getdisplay(){r
PCF8574 pcf8574_Out(PCF8574_I2C_ADDR1); // First digital output modul PCF8574 from Horter

// Define the array of leds
CRGB fled[NUM_FLASH_LED]; // Flash LED
CRGB backlight[NUM_BACKLIGHT_LED]; // Backlight
//CRGB fled[NUM_FLASH_LED]; // Flash LED
//CRGB backlight[NUM_BACKLIGHT_LED]; // Backlight

// Global vars
bool blinkingLED = false; // Enable / disable blinking flash LED
Expand All @@ -77,8 +73,8 @@ void hardwareInit()
setPortPin(OBP_POWER_50, true);

// Init RGB LEDs
FastLED.addLeds<WS2812B, OBP_FLASH_LED, GRB>(fled, NUM_FLASH_LED);
FastLED.addLeds<WS2812B, OBP_BACKLIGHT_LED, GRB>(backlight, NUM_BACKLIGHT_LED);
//FastLED.addLeds<WS2812B, OBP_FLASH_LED, GRB>(fled, NUM_FLASH_LED);
//FastLED.addLeds<WS2812B, OBP_BACKLIGHT_LED, GRB>(backlight, NUM_BACKLIGHT_LED);

// Init PCF8574 digital outputs
Wire.setClock(I2C_SPEED); // Set I2C clock on 10 kHz
Expand All @@ -98,86 +94,16 @@ void togglePortPin(uint pin){
}

// Valid colors see hue
CHSV colorMapping(String colorString){
CHSV color = CHSV(HUE_RED, 255, 255);
if(colorString == "Red"){color = CHSV(HUE_RED, 255, 255);}
if(colorString == "Orange"){color = CHSV(HUE_ORANGE, 255, 255);}
if(colorString == "Yellow"){color = CHSV(HUE_YELLOW, 255, 255);}
if(colorString == "Green"){color = CHSV(HUE_GREEN, 255, 255);}
if(colorString == "Blue"){color = CHSV(HUE_BLUE, 255, 255);}
if(colorString == "Aqua"){color = CHSV(HUE_AQUA, 255, 255);}
if(colorString == "Violet"){color = CHSV(HUE_PURPLE, 255, 255);}
if(colorString == "White"){color = CHSV(HUE_AQUA, 0, 255);}
return color;
}

// All defined colors see pixeltypes.h in FastLED lib
void setBacklightLED(uint brightness, CHSV color){
static uint oldbrightness;
static CHSV oldcolor;
// If changed the values then set new values
if(brightness != oldbrightness || color != oldcolor){
FastLED.setBrightness(255); // Brightness for flash LED
color.value = brightness;
backlight[0] = color; // Backlight LEDs on with color
backlight[1] = color;
backlight[2] = color;
backlight[3] = color;
backlight[4] = color;
backlight[5] = color;
FastLED.show();
oldbrightness = brightness;
oldcolor = color;
}
}

void toggleBacklightLED(uint brightness, CHSV color){
statusBacklightLED = !statusBacklightLED;
FastLED.setBrightness(255); // Brightness for flash LED
if(statusBacklightLED == true){
color.value = brightness;
backlight[0] = color; // Backlight LEDs on with color
backlight[1] = color;
backlight[2] = color;
backlight[3] = color;
backlight[4] = color;
backlight[5] = color;
}
else{
backlight[0] = CHSV(HUE_BLUE, 255, 0); // Backlight LEDs off (blue without britghness)
backlight[1] = CHSV(HUE_BLUE, 255, 0);
backlight[2] = CHSV(HUE_BLUE, 255, 0);
backlight[3] = CHSV(HUE_BLUE, 255, 0);
backlight[4] = CHSV(HUE_BLUE, 255, 0);
backlight[5] = CHSV(HUE_BLUE, 255, 0);
}
FastLED.show();
}
// All defined colors see pixeltypes.h in FastLED lib

void setFlashLED(bool status){
static bool oldstatus;
if(status == true){
FastLED.setBrightness(255); // Brightness for flash LED
fled[0] = CRGB::Red; // Flash LED on in red
}
else{
fled[0] = CRGB::Black; // Flash LED off
}
FastLED.show();

}

void blinkingFlashLED(){
if(blinkingLED == true){
statusLED = !statusLED; // Toggle LED for each run
if(statusLED == true){
FastLED.setBrightness(255); // Brightness for flash LED
fled[0] = CRGB::Red; // Flash LED on in red
}
else{
fled[0] = CRGB::Black; // Flash LED off
}
FastLED.show();
}

}

void setBlinkingLED(bool status){
Expand Down
8 changes: 0 additions & 8 deletions lib/obp60task/OBP60Extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

#include <Arduino.h>
#include "OBP60Hardware.h"
#define FASTLED_ALL_PINS_HARDWARE_SPI
#define FASTLED_ESP32_SPI_BUS FSPI
#define FASTLED_ESP32_FLASH_LOCK 1
#include <FastLED.h> // Driver for WS2812 RGB LED
#include <GxEPD2_BW.h> // E-paper lib V2

// Fonts declarations for display (#inclues see OBP60Extensions.cpp)
Expand Down Expand Up @@ -44,10 +40,6 @@ void setPortPin(uint pin, bool value); // Set port pin for extension po

void togglePortPin(uint pin); // Toggle extension port pin

CHSV colorMapping(String colorString); // Color mapping string to CHSV colors
void setBacklightLED(uint brightness, CHSV color);// Set backlight LEDs
void toggleBacklightLED(uint brightness, CHSV color);// Toggle backlight LEDs

void setFlashLED(bool status); // Set flash LED
void blinkingFlashLED(); // Blinking function for flash LED
void setBlinkingLED(bool on); // Set blinking flash LED active
Expand Down
19 changes: 2 additions & 17 deletions lib/obp60task/obp60task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ void OBP60Init(GwApi *api){
api->getLogger()->logDebug(GwLog::DEBUG,"Backlight Mode is: %s", backlightMode);
uint brightness = uint(api->getConfig()->getConfigItem(api->getConfig()->blBrightness,true)->asInt());
String backlightColor = api->getConfig()->getConfigItem(api->getConfig()->blColor,true)->asString();
if(String(backlightMode) == "On"){
setBacklightLED(brightness, colorMapping(backlightColor));
}
if(String(backlightMode) == "Off"){
setBacklightLED(0, CHSV(HUE_BLUE, 255, 0)); // Backlight LEDs off (blue without britghness)
}
if(String(backlightMode) == "Control by Key"){
setBacklightLED(0, CHSV(HUE_BLUE, 255, 0)); // Backlight LEDs off (blue without britghness)
}

// Settings flash LED mode
String ledMode = api->getConfig()->getConfigItem(api->getConfig()->flashLED,true)->asString();
Expand Down Expand Up @@ -413,7 +404,7 @@ void OBP60Task(GwApi *api){
String gpsOn=api->getConfig()->getConfigItem(api->getConfig()->useGPS,true)->asString();
String tz = api->getConfig()->getConfigItem(api->getConfig()->timeZone,true)->asString();
String backlightColor = api->getConfig()->getConfigItem(api->getConfig()->blColor,true)->asString();
CHSV color = colorMapping(backlightColor);

uint brightness = 2.55 * uint(api->getConfig()->getConfigItem(api->getConfig()->blBrightness,true)->asInt());
bool uvoltage = api->getConfig()->getConfigItem(api->getConfig()->underVoltage,true)->asBoolean();

Expand Down Expand Up @@ -489,7 +480,7 @@ void OBP60Task(GwApi *api){
if(String(backlight) == "Control by Key"){
if(keyboardMessage == 6){
LOG_DEBUG(GwLog::LOG,"Toggle Backlight LED");
toggleBacklightLED(brightness, color);

}
}
// #9 Swipe right
Expand Down Expand Up @@ -531,12 +522,6 @@ void OBP60Task(GwApi *api){
commonData.sundata = calcSunsetSunrise(api, time->value , date->value, lat->value, lon->value, tz.toDouble());
// Backlight with sun control
if(String(backlight) == "Control by Sun"){
if(commonData.sundata.sunDown == true){
setBacklightLED(brightness, color);
}
else{
setBacklightLED(0, CHSV(HUE_BLUE, 255, 0)); // Backlight LEDs off (blue without britghness)
}

}
}
Expand Down

0 comments on commit da4089c

Please sign in to comment.