Skip to content

🐛 Fix negative int16 values on classic DGUS - #28748

Merged
thinkyhead merged 1 commit into
MarlinFirmware:bugfix-2.1.xfrom
thinkyhead:bf2_fix_dgus_int16
Oct 25, 2026
Merged

thinkyhead merged 1 commit into
MarlinFirmware:bugfix-2.1.xfrom
thinkyhead:bf2_fix_dgus_int16

Conversation

@thinkyhead

Copy link
Copy Markdown
Member

Description

DGUSDisplay::writeVariable(uint16_t, int16_t) swaps bytes with (value & 0xFFU) << 8U | (value >> 8U) on the signed value. For a negative value, value >> 8 sign-extends, and the OR overwrites the high byte with 0xFF. So most negative numbers reach the display wrong:

Value Sent before Display shows Sent after
-2 FF FF -1 FF FE
-125 FF FF -1 FF 83
-300 FE FF -257 FE D4

This change sends the value through the existing uint16_t overload, so the swap is done on an unsigned value.

The path is used by sendFloatAsIntValueToDisplay, e.g. for a negative probe Z offset shown with 2 decimals (-1.25 is sent as -125 and shows as -0.01).

The CR6Community fork had already fixed this in its own copy of the DGUS code. I found it while porting that fork's work for #19958.

Requirements

A classic DGUS display: DGUS_LCD_UI ORIGIN, FYSETC, HIPRECY or MKS. DGUS Reloaded and the other DWIN UIs have their own code and aren't affected.

Benefits

Negative values (e.g. Z offset) display correctly on classic DGUS screens.

Testing

  • A host test of the old and new swap over all 65536 int16_t values: 32640 values were wrong before, none after.
  • Built mega2560ext tests 1 (FYSETC) and 2 (MKS).
  • Not tested on a display. Testers with an ORIGIN, FYSETC, HIPRECY or MKS screen and a negative Z offset are welcome.

Configurations

buildroot/tests/mega2560ext config-01 / config-02.

Related Issues

None filed. Found while working on #19958.

@thinkyhead
thinkyhead merged commit d140a1d into MarlinFirmware:bugfix-2.1.x Oct 25, 2026
78 checks passed
@thinkyhead
thinkyhead deleted the bf2_fix_dgus_int16 branch October 25, 2026 18:13
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.

1 participant