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

Closed
1 task done
classicrocker883 opened this issue Dec 20, 2023 · 6 comments
Closed
1 task done

Comments

@classicrocker883
Copy link
Contributor

classicrocker883 commented Dec 20, 2023

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

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

Bug Timeline

could be older, only noticed it now

Expected behavior

should not give error for invalid conversion

Actual behavior

gives error for invalid conversion

Steps to Reproduce

  1. inside pins_(YOUR_BOARD).h -- i.e. Marlin\src\pins\stm32f1\pins_CREALITY_V4.h
  2. add #define LCD_LED_PIN EXP3_02_PIN -- or any pin
  3. 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

@ellensp
Copy link
Contributor

ellensp commented Dec 20, 2023

- struct { uint8_t g, r, b; } led_data[LED_NUM];
+    struct { uint32_t g, r, b; } led_data[LED_NUM];

So you want to use 4 bytes for each of R,G and B that can only be 0-255 and fits with in a single byte??

@robherc
Copy link
Contributor

robherc commented Dec 20, 2023

That error is saying you're converting from a signed 1+byte (depending on arch) type to an unsigned byte type. I don't think converting to a uint128_t would get rid of the warning anywise, as it still couldn't store -3. ...might need to find where the variable oor data was declared as a signed type to fix this.

@classicrocker883
Copy link
Contributor Author

- struct { uint8_t g, r, b; } led_data[LED_NUM];
+    struct { uint32_t g, r, b; } led_data[LED_NUM];

So you want to use 4 bytes for each of R,G and B that can only be 0-255 and fits with in a single byte??

well no, i tried different things and that was the first which cleared the error. if it were me making the choice then definitely not, but something else.

its just an example of how to think, not what to think.

Copy link

Greetings from the Marlin AutoBot!
This issue has had no activity for the last 90 days.
Do you still see this issue with the latest bugfix-2.1.x code?
Please add a reply within 14 days or this issue will be automatically closed.
To keep a confirmed issue open we can also add a "Bug: Confirmed" tag.

Disclaimer: This is an open community project with lots of activity and limited
resources. The main project contributors will do a bug sweep ahead of the next
release, but any skilled member of the community may jump in at any time to fix
this issue. That can take a while depending on our busy lives so please be patient,
and take advantage of other resources such as the MarlinFirmware Discord to help
solve the issue.

@thisiskeithb
Copy link
Member

Closing since you’ve opened a PR.

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators May 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants