@@ -903,12 +903,13 @@ uint16_t CreateRgb(double h, double s, double v) {
903
903
void DGUSScreenHandler::UpdateMeshValue (const int8_t x, const int8_t y, const float z) {
904
904
SERIAL_ECHOPAIR (" X" , x);
905
905
SERIAL_ECHOPAIR (" Y" , y);
906
- SERIAL_ECHOPAIR_F_P (" Z" , z );
907
- SERIAL_ECHOLN ( " " );
906
+ SERIAL_ECHO (" Z" );
907
+ SERIAL_ECHO_F (z, 4 );
908
908
909
909
// Determine the screen X and Y value
910
910
if (x % SkipMeshPoint != 0 || y % SkipMeshPoint != 0 ) {
911
911
// Skip this point
912
+ SERIAL_ECHOLN (" " );
912
913
return ;
913
914
}
914
915
@@ -917,7 +918,26 @@ void DGUSScreenHandler::UpdateMeshValue(const int8_t x, const int8_t y, const fl
917
918
918
919
// Each Y is a full edge of X values
919
920
const uint16_t vpAddr = VP_MESH_LEVEL_X0_Y0 + (scrY * MESH_LEVEL_VP_SIZE) + (scrX * MESH_LEVEL_VP_EDGE_SIZE);
920
- dgusdisplay.WriteVariable (vpAddr, z);
921
+
922
+ // ... DWIN is inconsistently truncating floats. Examples: 0.1811 becomes 0.181, 0.1810 becomes 0.180. But 0.1800 is not 0.179
923
+ // so we need to calculate a good number here that will not overflow
924
+ float displayZ = z;
925
+
926
+ {
927
+ constexpr float correctionFactor = 0.0001 ;
928
+
929
+ if (round (z * cpow (10 ,3 )) == round ((z + correctionFactor) * cpow (10 ,3 ))) {
930
+ // If we don't accidently overshoot to the next number, trick the display by upping the number 0.0001 💩
931
+ displayZ += correctionFactor;
932
+
933
+ SERIAL_ECHO (" displayZ: " );
934
+ SERIAL_ECHO_F (z, 4 );
935
+ }
936
+ }
937
+
938
+ SERIAL_ECHOLN (" " );
939
+
940
+ dgusdisplay.WriteVariable (vpAddr, displayZ);
921
941
922
942
// Set color
923
943
const uint16_t spAddr = SP_MESH_LEVEL_X0_Y0 + (scrY * MESH_LEVEL_SP_SIZE) + (scrX * MESH_LEVEL_SP_EDGE_SIZE);
@@ -958,7 +978,8 @@ void DGUSScreenHandler::HandleMeshPoint(DGUS_VP_Variable &var, void *val_ptr) {
958
978
959
979
SERIAL_ECHOPAIR (" Overriding mesh value. X:" , x);
960
980
SERIAL_ECHOPAIR (" Y:" , y);
961
- SERIAL_ECHOPAIR_F (" Z:" , z);
981
+ SERIAL_ECHO (" Z:" );
982
+ SERIAL_ECHO_F (z, 4 );
962
983
SERIAL_ECHOPAIR (" [raw: " , rawZ);
963
984
SERIAL_ECHOPAIR (" ] [point " , probe_point, " ] " );
964
985
SERIAL_ECHOPAIR (" [VP: " , var.VP );
0 commit comments