Skip to content

Commit ceabb6a

Browse files
committed
Fix interpretation of negative numbers from DWIN #209
1 parent 449587c commit ceabb6a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -964,12 +964,14 @@ void DGUSScreenHandler::HandleMeshPoint(DGUS_VP_Variable &var, void *val_ptr) {
964964
const uint8_t x = probe_point / col_size; // Will be 0 to 3 inclusive
965965
const uint8_t y = (probe_point - (x * col_size)) / MESH_INPUT_DATA_SIZE;
966966

967-
float z = swap16(*(int16_t*)val_ptr) * 0.001;
967+
int16_t rawZ = *(int16_t*)val_ptr;
968+
float z = swap16(rawZ) * 0.001;
968969

969970
SERIAL_ECHOPAIR("Overriding mesh value. X:", x);
970971
SERIAL_ECHOPAIR(" Y:", y);
971972
SERIAL_ECHOPAIR_F(" Z:", z);
972-
SERIAL_ECHOPAIR(" [point ", probe_point, "] ");
973+
SERIAL_ECHOPAIR(" [raw: ", rawZ);
974+
SERIAL_ECHOPAIR("] [point ", probe_point, "] ");
973975
SERIAL_ECHOPAIR(" [VP: ", var.VP);
974976
SERIAL_ECHOLN("]");
975977

Marlin/src/lcd/extui/lib/dgus_creality/DGUSVPVariable.h

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ struct DGUS_VP_Variable {
5151
// endianness swap
5252
FORCE_INLINE uint16_t swap16(const uint16_t value) { return (value & 0xffU) << 8U | (value >> 8U); }
5353

54+
FORCE_INLINE int16_t swap16(const int16_t value) { return (value & 0xffU) << 8U | (value >> 8U); }
55+
5456
FORCE_INLINE uint32_t swap32(const uint32_t value) { return ((value>>24)&0xff) | ((value<<8)&0xff0000) | ((value>>8)&0xff00) | ((value<<24)&0xff000000); }
5557

5658
FORCE_INLINE uint16_t uInt16Value(void *val_ptr) { return swap16(*static_cast<uint16_t*>(val_ptr)); }

0 commit comments

Comments
 (0)