Skip to content
Open
54 changes: 54 additions & 0 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4850,6 +4850,59 @@ static const char _data_FX_MODE_FLOWSTRIPE[] PROGMEM = "Flow Stripe@Hue speed,Ef
#define XY(x,y) SEGMENT.XY(x,y)


/////////////////////////////
// 2D Analog Clock //
/////////////////////////////
uint16_t mode_2DAnalogClock(void) { // By Andras Fekete (bandi13)
if (!strip.isMatrix || !SEGMENT.is2D()) return mode_static(); // not a 2D set-up

const int cols = SEGMENT.virtualWidth();
const int rows = SEGMENT.virtualHeight();
const int centerX = (cols-!(cols%2)) >> 1; // use odd sized circle
const int centerY = (rows-!(rows%2)) >> 1; // use odd sized circle
const int radius = min(centerX, centerY);
const bool soft = radius > 6 && SEGMENT.check2;

if (SEGENV.call == 0) { // set up defaults
if (SEGMENT.colors[0] == DEFAULT_COLOR) SEGMENT.colors[0] = RED;
if (SEGMENT.colors[1] == BLACK) SEGMENT.colors[1] = GREEN;
if (SEGMENT.colors[2] == BLACK) SEGMENT.colors[2] = BLUE;
}

SEGMENT.fadeToBlackBy(240);
SEGMENT.drawCircle(centerX, centerY, radius, DARKGREY, soft);
if (radius > 8) SEGMENT.drawCircle(centerX, centerY, radius-1, DARKGREY, soft); // thicker circle
Comment on lines +4873 to +4874
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Verify DARKGREY is defined

The code uses DARKGREY which doesn't appear to be a standard WLED color constant. This might cause a compilation error if not defined elsewhere.

Consider using a defined color constant or an explicit color value:

-  SEGMENT.drawCircle(centerX, centerY, radius, DARKGREY, soft);
-  if (radius > 8) SEGMENT.drawCircle(centerX, centerY, radius-1, DARKGREY, soft); // thicker circle
+  SEGMENT.drawCircle(centerX, centerY, radius, RGBW32(64, 64, 64, 0), soft);
+  if (radius > 8) SEGMENT.drawCircle(centerX, centerY, radius-1, RGBW32(64, 64, 64, 0), soft); // thicker circle
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
SEGMENT.drawCircle(centerX, centerY, radius, DARKGREY, soft);
if (radius > 8) SEGMENT.drawCircle(centerX, centerY, radius-1, DARKGREY, soft); // thicker circle
SEGMENT.drawCircle(centerX, centerY, radius, RGBW32(64, 64, 64, 0), soft);
if (radius > 8) SEGMENT.drawCircle(centerX, centerY, radius-1, RGBW32(64, 64, 64, 0), soft); // thicker circle
🤖 Prompt for AI Agents
In wled00/FX.cpp around lines 4873 to 4874, the color constant DARKGREY used in
the drawCircle calls may not be defined, potentially causing a compilation
error. Verify if DARKGREY is defined elsewhere in the codebase; if not, replace
DARKGREY with a valid predefined color constant or an explicit color value that
is recognized by the WLED framework to ensure successful compilation.


time_t hours_in_day = (localTime / (60 * 60)) % 12;
time_t minutes_in_day = (localTime / (60)) % 60;
time_t seconds_in_day = (localTime) % 60;

float hour_angle = radians(30.0f * (hours_in_day + minutes_in_day / 60.0f) - 90.0f);
int hour_len = radius / 2;
int hour_x = centerX + hour_len * cos_t(hour_angle);
int hour_y = centerY + hour_len * sin_t(hour_angle);

float minute_angle = radians(6.0f * (minutes_in_day + seconds_in_day / 60.0f) - 90.0f);
int minute_len = (radius * 7) / 10;
int minute_x = centerX + minute_len * cos_t(minute_angle);
int minute_y = centerY + minute_len * sin_t(minute_angle);

if (SEGMENT.check1) {
float second_angle = radians(6.0f * seconds_in_day - 90.0f);
int second_len = (radius * 9) / 10;
int second_x = centerX + second_len * cos_t(second_angle);
int second_y = centerY + second_len * sin_t(second_angle);
SEGMENT.drawLine(centerX, centerY, second_x, second_y, SEGCOLOR(2), soft);
}

SEGMENT.drawLine(centerX, centerY, minute_x, minute_y, SEGCOLOR(1), soft);
SEGMENT.drawLine(centerX, centerY, hour_x, hour_y, SEGCOLOR(0), soft);

return FRAMETIME;
} // mode_2DAnalogClock()
static const char _data_FX_MODE_2DANALOGCLOCK[] PROGMEM = "Analog Clock@,,,,,Seconds,Soft;Hour,Minute,Second;;2;o1=1,o2=1";
Copy link
Author

Choose a reason for hiding this comment

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

Any way to make the default colors actually correct? On startup, Hour=white, Minute=black, Second=black for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately you can't but I guess you are not using every effect using default values. Or are you?
If you are not, you should consider using presets which save every configuration item.

Copy link
Member

@softhack007 softhack007 May 10, 2024

Choose a reason for hiding this comment

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

Effect metadata format is documented here:
https://kno.wled.ge/interfaces/json-api/#effect-metadata

It looks like you can define default colors in metadata, too.

Edit: you can only specify the names of the 3 colors that appear below the color wheel, sorry.

Copy link
Author

Choose a reason for hiding this comment

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

The default values should be ones that work for most cases out of the box. When you buy a car/phone/computer/anything it should work out of the box without you having to edit parameters to make it functional. Note that I didn't say customized, just functional out of the gate.

Maybe you could have a special case, that if the Hour=White and Minute=Second=Black that it would set the colors to Red, Green, Blue respectively?

Copy link
Contributor

Choose a reason for hiding this comment

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

When you buy it, yes. If you get it for free, it is just a nice touch.

Maybe you could have a special case, that if the Hour=White and Minute=Second=Black that it would set the colors to Red, Green, Blue respectively?

You can do that in effect initialisation code that starts as:

if (SEGENV.call == 0) {
  SEGMENT.colors[0] = <hour_color>;
...
}

But I would only change those if they a black.
There are examples elsewhere in the code.

The other option is to enhance metadata. That will be a lot more work IMO.



// Black hole
uint16_t mode_2DBlackHole(void) { // By: Stepko https://editor.soulmatelights.com/gallery/1012 , Modified by: Andrew Tuline
if (!strip.isMatrix || !SEGMENT.is2D()) return mode_static(); // not a 2D set-up
Expand Down Expand Up @@ -8080,6 +8133,7 @@ void WS2812FX::setupEffectData() {

addEffect(FX_MODE_2DGEQ, &mode_2DGEQ, _data_FX_MODE_2DGEQ); // audio

addEffect(FX_MODE_2DANALOGCLOCK, &mode_2DAnalogClock, _data_FX_MODE_2DANALOGCLOCK);
addEffect(FX_MODE_2DNOISE, &mode_2Dnoise, _data_FX_MODE_2DNOISE);

addEffect(FX_MODE_2DFIRENOISE, &mode_2Dfirenoise, _data_FX_MODE_2DFIRENOISE);
Expand Down
2 changes: 1 addition & 1 deletion wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
#define FX_MODE_TWO_DOTS 50
#define FX_MODE_FAIRYTWINKLE 51 //was Two Areas prior to 0.13.0-b6 (use "Two Dots" with full intensity)
#define FX_MODE_RUNNING_DUAL 52
// #define FX_MODE_HALLOWEEN 53 // removed in 0.14!
#define FX_MODE_2DANALOGCLOCK 53 // was HALLOWEEN, removed in 0.14!
#define FX_MODE_TRICOLOR_CHASE 54
#define FX_MODE_TRICOLOR_WIPE 55
#define FX_MODE_TRICOLOR_FADE 56
Expand Down