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 14 commits into
base: 0_15
Choose a base branch
from

Conversation

bandi13
Copy link

@bandi13 bandi13 commented Apr 30, 2024

Added a 2D Analog Clock effect. It needed some antialiased lines and circles, so I've implemented that as well. On my 48x48 pixel display it looks like this:
IMG_20240430_001047063_HDR

Also cleaned up some function naming to be more consistent with the majority of the source code.

@blazoncek
Copy link
Collaborator

Please revert all unnecessary changes (renamed functions).

@bandi13
Copy link
Author

bandi13 commented Apr 30, 2024

There aren't any unnecessary changes. I needed to create 2 new functions drawCircleAntialiased and drawLineAntialiased. The coding style for the circle functions were an anomaly compared to the rest of the code so I modified them to be like the rest of the code base.

@blazoncek
Copy link
Collaborator

You are not requested to change existing code unless necessary.
There is no need to change existing functions.

@softhack007
Copy link
Collaborator

softhack007 commented Apr 30, 2024

Hi, thanks for taking the time to add this nice new effect:-)

If you need anti-aliased pixel drawing, you might want to look into existing variants of setPixelColorXY that take a "float" argument. These functions are already able to perform anti-aliased plotting. It should be simple to create a line drawing/arc drawing routine based on these.

The coding style for the circle functions were an anomaly compared to the rest of the code so I modified them to be like the rest of the code base.

Please focus on the feature you would like to add - I agree with @blazoncek that correcting coding style is not needed. There are other forks that sometimes like to cherry-pick single commits; unfortunately the "coding style fix" will make it very hard to do so for future commits that come after your PR.

@bandi13 bandi13 force-pushed the analog_clock_2d_branch0_15 branch from bbe411f to 1b799f7 Compare May 1, 2024 01:49
@bandi13
Copy link
Author

bandi13 commented May 1, 2024

I don't agree with that mentality, but not my repo so I will do as you ask. As for the setPixelColorXY my drawCircleAntialiased function does use that.

Do you want me to add -DWLED_USE_AA_PIXELS into platformio.ini's build_flags as this effect depends on those gates being enabled.

int16_t err = (dx-dy)/2, e2, x2;
int16_t ed = (dx+dy == 0) ? 1 : sqrt((float)dx*dx + (float)dy*dy);

for (;;) {
Copy link
Collaborator

@softhack007 softhack007 May 1, 2024

Choose a reason for hiding this comment

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

Coding style: please re-write this for loop into a while{} or do{}while loop that does not rely on existing with break. The gcc optimizer will thank you ;-)

Copy link
Author

Choose a reason for hiding this comment

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

This function's style is nearly identical to the existing drawLine() including the for (;;) loop.

wled00/FX_2Dfcn.cpp Outdated Show resolved Hide resolved
wled00/FX_2Dfcn.cpp Outdated Show resolved Hide resolved
wled00/FX.cpp Outdated Show resolved Hide resolved
@bandi13
Copy link
Author

bandi13 commented May 7, 2024

Do you need anything from me to merge this PR?

@blazoncek
Copy link
Collaborator

Do you need anything from me to merge this PR?

I will be adding some optimisations and modifications later. Once I'm done, you'll check if everything is still working and then it can be merged.

@blazoncek
Copy link
Collaborator

I've had a thorough look and test of this new effect and changes made to WLED.

I do not like drawCircleAntialiased() and the issue it creates when you want to draw a thin anti-aliased circle. It cannot do it.
I will update drawCircle() and drawLine() to allow anti-aliased circles and lines that are thin (1 pixel) without using floating point math.

I also do not like the idea that an effect is conditionally compiled. This is unacceptable for single effect IMO.
Another problem with anti-aliased approach taken in this effect is that it looks awful on anything less than 20x20 sized segment so I added an option to disable anti-aliasing while testing and it looked acceptable on 10x10 segments (without seconds hand).

I'll move the PR into draft until AA circle and line are finished and included in 0_15 branch.

@blazoncek blazoncek marked this pull request as draft May 8, 2024 08:34
@blazoncek
Copy link
Collaborator

@bandi13 please review and comment.

@blazoncek blazoncek marked this pull request as ready for review May 9, 2024 22:13
Copy link
Collaborator

@blazoncek blazoncek left a comment

Choose a reason for hiding this comment

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

Reworked & approved

Copy link
Author

@bandi13 bandi13 left a comment

Choose a reason for hiding this comment

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

I left a few comments, most are for my understanding. Seems to work though the default colors are terrible.

wled00/FX.cpp Show resolved Hide resolved
wled00/FX.cpp Show resolved Hide resolved

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
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

@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
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.

wled00/FX.cpp Show resolved Hide resolved
wled00/FX.cpp Show resolved Hide resolved
wled00/FX.cpp Show resolved Hide resolved
@blazoncek
Copy link
Collaborator

Do we pursue this further or do we close? As far as I'm concerned this is completed.

BTW none of the effects have "default" colors but some have default (some even hardcoded) palettes.

Note that by default, 0xFFAA00 is ultimately set, not DEFAULT_COLOR (0xFFA000). Probably something to do with brightness.
@bandi13
Copy link
Author

bandi13 commented May 14, 2024

I put in the default colors. Seems to work well enough.

Sorry it took some time, I'm only doing this as a hobby. Weekends = family time. Strictly enforced. ;-)

@blazoncek
Copy link
Collaborator

One more thing occurred to me tonight. WLED has "analog clock overlay" feature (for strips) and since segments now can support overlapping (if coded properly) it would be ok IMO to move that overlay code into this effect and make it 1D + 2D.

This would add 2 benefits to analog clock overlay:

  1. it could be turned on/off using segment power button (or JSON API) instead of in settings
  2. it could only encompass part of the strip instead of entire strip

@softhack007 what do you think?

BTW @bandi13 do you think I'm doing WLED professionally? No, I do not. My sleep and spare time suffer so that I can do WLED. 😀

@bandi13
Copy link
Author

bandi13 commented Jun 10, 2024

Should that overlay code refactor be a separate PR?

@blazoncek
Copy link
Collaborator

IMO if this effect (analog clock) can replace existing overlay, no. I'll remove overlay code once effect can handle 1D and 2D.

@softhack007 @Aircoookie your opinion?

@blazoncek
Copy link
Collaborator

Reference usermod: #2736

@softhack007 softhack007 added this to the 0.15.1 candidate milestone Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants