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

Analog clock 2d branch0 15 #3943

Open
wants to merge 13 commits into
base: 0_15
Choose a base branch
from
48 changes: 48 additions & 0 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4861,6 +4861,53 @@ 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();
bandi13 marked this conversation as resolved.
Show resolved Hide resolved
const int rows = SEGMENT.virtualHeight();
const int centerX = (cols-!(cols%2)) >> 1; // use odd sized circle
bandi13 marked this conversation as resolved.
Show resolved Hide resolved
const int centerY = (rows-!(rows%2)) >> 1; // use odd sized circle
const int radius = min(centerX, centerY);
const bool soft = radius > 6 && SEGMENT.check2;

SEGMENT.fadeToBlackBy(240);
SEGMENT.drawCircle(centerX, centerY, radius, DARKGREY, soft);
bandi13 marked this conversation as resolved.
Show resolved Hide resolved
if (radius > 8) SEGMENT.drawCircle(centerX, centerY, radius-1, DARKGREY, soft); // thicker circle

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);
blazoncek marked this conversation as resolved.
Show resolved Hide resolved
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;
bandi13 marked this conversation as resolved.
Show resolved Hide resolved
} // 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
Collaborator

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
Collaborator

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
Collaborator

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 @@ -8096,6 +8143,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