Skip to content

Commit

Permalink
Merge pull request #328 from Duet3D/327-display-two-digits-of-axis-on…
Browse files Browse the repository at this point in the history
…ly-if-max-axis-value-is-less-or-equal-to-1000

327 display two digits of axis only if max axis value is less or equal to 1000
  • Loading branch information
mfs12 committed Nov 28, 2023
2 parents 792fb83 + e0b9628 commit 89cb57e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/PanelDue.cpp
Expand Up @@ -294,6 +294,7 @@ enum ReceivedDataEvent
rcvMoveAxesHomed,
rcvMoveAxesLetter,
rcvMoveAxesMachinePosition,
rcvMoveAxesMax,
rcvMoveAxesUserPosition,
rcvMoveAxesVisible,
rcvMoveAxesWorkplaceOffsets,
Expand Down Expand Up @@ -409,6 +410,7 @@ static FieldTableEntry fieldTable[] =
{ rcvMoveAxesHomed, "move:axes^:homed" },
{ rcvMoveAxesLetter, "move:axes^:letter" },
{ rcvMoveAxesMachinePosition, "move:axes^:machinePosition" },
{ rcvMoveAxesMax, "move:axes^:max" },
{ rcvMoveAxesUserPosition, "move:axes^:userPosition" },
{ rcvMoveAxesVisible, "move:axes^:visible" },
{ rcvMoveAxesWorkplaceOffsets, "move:axes^:workplaceOffsets^" },
Expand Down Expand Up @@ -1461,6 +1463,16 @@ static void ProcessReceivedValue(StringRef id, const char data[], const size_t i
}
break;

case rcvMoveAxesMax:
{
float val;
if (GetFloat(data, val))
{
UI::SetAxisMax(indices[0], val);
}
}
break;

case rcvMoveAxesUserPosition:
{
float fval;
Expand Down
10 changes: 10 additions & 0 deletions src/UI/Display.hpp
Expand Up @@ -288,6 +288,16 @@ class FloatField : public FieldWithText
changed = true;
}

void SetNumDecimals(uint8_t decimals)
{
if (numDecimals == decimals)
{
return;
}
numDecimals = decimals;
changed = true;
}

void SetLabel(const char* _ecv_array s)
{
if (strcmp(label, s) == 0)
Expand Down
24 changes: 24 additions & 0 deletions src/UI/UserInterface.cpp
Expand Up @@ -84,6 +84,8 @@ static StaticTextField *areYouSureTextField, *areYouSureQueryField;
static DisplayField *emptyRoot, *baseRoot, *commonRoot, *controlRoot, *printRoot, *messageRoot, *setupRoot;
static SingleButton *homeAllButton, *bedCompButton;
static IconButtonWithText *homeButtons[MaxDisplayableAxes], *toolButtons[MaxSlots];

static float axisMaxVal = 0.0;
static FloatField *controlTabAxisPos[MaxDisplayableAxes];
#if DISPLAY_X == 800
static FloatField *printTabAxisPos[MaxDisplayableAxes];
Expand Down Expand Up @@ -388,6 +390,18 @@ static void ChangeBrightness(bool up)
SetBrightness(nvData.GetBrightness() + adjust);
}


void UI::SetAxisMax(size_t index, float val)
{
if (index >= MaxTotalAxes)
{
return;
}

axisMaxVal = max(axisMaxVal, val);
}


// Cycle through available display dimmer types
static void ChangeDisplayDimmerType()
{
Expand Down Expand Up @@ -1326,6 +1340,16 @@ namespace UI
if (axis != nullptr && axis->slot < MaxDisplayableAxes)
{
size_t slot = axis->slot;

if (axisMaxVal > 1000)
{
controlTabAxisPos[slot]->SetNumDecimals(1);
#if DISPLAY_X == 800
printTabAxisPos[slot]->SetNumDecimals(1);
#endif
movePopupAxisPos[slot]->SetNumDecimals(1);
}

controlTabAxisPos[slot]->SetValue(fval);
#if DISPLAY_X == 800
printTabAxisPos[slot]->SetValue(fval);
Expand Down
1 change: 1 addition & 0 deletions src/UI/UserInterface.hpp
Expand Up @@ -103,6 +103,7 @@ namespace UI

extern void SetBabystepOffset(size_t index, float f);
extern void SetAxisLetter(size_t index, char l);
extern void SetAxisMax(size_t index, float val);
extern void SetAxisVisible(size_t index, bool v);
extern void SetAxisWorkplaceOffset(size_t axisIndex, size_t workplaceIndex, float offset);
extern void SetCurrentWorkplaceNumber(uint8_t workplaceNumber);
Expand Down

0 comments on commit 89cb57e

Please sign in to comment.