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

[BUG] LED control in encoder.cpp - invalid narrowing conversion #27356

Open
classicrocker883 opened this issue Aug 17, 2024 · 0 comments
Open

Comments

@classicrocker883
Copy link
Contributor

classicrocker883 commented Aug 17, 2024

Did you test the latest bugfix-2.1.x code?

Yes, and the problem still exists.

Bug Description

invalid narrowing conversion from "int" to "unsigned char"

image

It is apparent that R and G are swapped, generally it should follow RGB, not GRB, and also you see G (or g) shifts 16 bits, not 8 which it is supposed to, as for R (or r) it shifts 8. so basically, these are backwards. I was messing around and saw LED_Action() commented out and wondered why

      #if PIN_EXISTS(LCD_LED)
        //LED_Action();
      #endif

so I enabled that pin, and stumbled upon this error.

one possible fix is

-    struct { uint8_t g, r, b; } led_data[LED_NUM];
     for (uint8_t i = 0; i < LED_NUM; i++) {
       switch (RGB_Scale) {
         case RGB_SCALE_R10_G7_B5:
-           led_data[i] = { luminance * 7/10, luminance * 10/10, luminance * 5/10 };

+    struct { uint32_t g, r, b; } led_data[LED_NUM];
     for (uint8_t i = 0; i < LED_NUM; i++) {
       switch (RGB_Scale) {
         case RGB_SCALE_R10_G7_B5:
+          led_data[i] = { luminance * (u_int)7/10, luminance * (u_int)10/10, luminance * (u_int)5/10 };

I would also like to point out this code:

  // LED initialization
  void LED_Configuration() {
    SET_OUTPUT(LCD_LED_PIN);
  }

It is unused, so chime in if anyone has experience in this area so I can test this properly

Bug Timeline

opened #26552 but the issue was closed without the PR I created being merged

Expected behavior

should not give error for invalid conversion

Actual behavior

gives error for invalid conversion

Steps to Reproduce

  1. make sure you define HAS_DWIN_E3V2 -- i.e. DWIN_LCD_PROUI
  2. inside pins_(YOUR_BOARD).h -- i.e. Marlin\src\pins\stm32f1\pins_CREALITY_V4.h
  3. add #define LCD_LED_PIN EXP3_02_PIN -- or any pin
  4. go to encoder.cpp and you will see the error

Version of Marlin Firmware

bugfix-2.1.x

Printer model

Aquila

Electronics

No response

LCD/Controller

No response

Other add-ons

No response

Bed Leveling

None

Your Slicer

None

Host Software

None

Don't forget to include

  • A ZIP file containing your Configuration.h and Configuration_adv.h.

Additional information & file uploads

No response

I may be able to test this at some point using #26946

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant