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

FW size reduction & bugfixes #2766

Merged
merged 3 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More size reduction
  • Loading branch information
kisslorand committed Apr 11, 2023
commit 63b78bc833b323e8013c526764b79c27094257ed
32 changes: 5 additions & 27 deletions TFT/src/User/API/BabystepControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ static float babystep_value = BABYSTEP_DEFAULT_VALUE;
#define BABYSTEP_CMD "M290 Z%.2f\n"
#define BABYSTEP_CMD_SMW "G43.2 Z%.2f\n"

// Reset only babystep value to default value
float babystepReset(void)
{
babystep_value = BABYSTEP_DEFAULT_VALUE;

return babystep_value;
}

// Set current babystep value
void babystepSetValue(const float value)
{
Expand Down Expand Up @@ -59,30 +51,16 @@ float babystepResetValue(void)
}

// Update babystep value
float babystepUpdateValue(float unit, const int8_t direction)
float babystepUpdateValue(float unit)
{
char * babyStepCmd = (infoMachineSettings.firmwareType == FW_SMOOTHIEWARE) ? BABYSTEP_CMD_SMW : BABYSTEP_CMD;
float diff;
unit = NOBEYOND(BABYSTEP_MIN_VALUE, babystep_value + unit, BABYSTEP_MAX_VALUE) - babystep_value;

if (direction < 0)
if (unit != 0)
{
if (babystep_value <= BABYSTEP_MIN_VALUE)
return babystep_value;
babystep_value += unit;

diff = babystep_value - BABYSTEP_MIN_VALUE;
mustStoreCmd((infoMachineSettings.firmwareType == FW_SMOOTHIEWARE) ? BABYSTEP_CMD_SMW : BABYSTEP_CMD, unit);
}
else
{
if (babystep_value >= BABYSTEP_MAX_VALUE)
return babystep_value;

diff = BABYSTEP_MAX_VALUE - babystep_value;
}

unit = ((diff > unit) ? unit : diff) * direction;
babystep_value += unit;

mustStoreCmd(babyStepCmd, unit);

return babystep_value;
}
5 changes: 1 addition & 4 deletions TFT/src/User/API/BabystepControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ extern "C" {

#include <stdint.h>

// Reset only babystep value to default value
float babystepReset(void);

// Set current babystep value
void babystepSetValue(float value);

Expand All @@ -20,7 +17,7 @@ float babystepGetValue(void);
float babystepResetValue(void);

// Update babystep value
float babystepUpdateValue(float unit, int8_t direction);
float babystepUpdateValue(float unit);

#ifdef __cplusplus
}
Expand Down
38 changes: 12 additions & 26 deletions TFT/src/User/API/HomeOffsetControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,28 @@ float homeOffsetGetValue(void)
// Reset Z offset value to default value
float homeOffsetResetValue(void)
{
if (z_offset_value == HOME_Z_OFFSET_DEFAULT_VALUE) // if already default value, nothing to do
return z_offset_value;

float unit = z_offset_value - HOME_Z_OFFSET_DEFAULT_VALUE;

z_offset_value = HOME_Z_OFFSET_DEFAULT_VALUE;
sendParameterCmd(P_HOME_OFFSET, AXIS_INDEX_Z, z_offset_value); // set Z offset value
mustStoreCmd("G1 Z%.2f\n", unit); // move nozzle
if (z_offset_value != HOME_Z_OFFSET_DEFAULT_VALUE) // if already default value, nothing to do
{
sendParameterCmd(P_HOME_OFFSET, AXIS_INDEX_Z, HOME_Z_OFFSET_DEFAULT_VALUE); // set Z home offset value
mustStoreCmd("G1 Z%.2f\n", z_offset_value - HOME_Z_OFFSET_DEFAULT_VALUE); // move nozzle
z_offset_value = HOME_Z_OFFSET_DEFAULT_VALUE;
}

return z_offset_value;
}

// Update Z offset value
float homeOffsetUpdateValue(float unit, int8_t direction)
float homeOffsetUpdateValue(float unit)
{
float diff;
unit = z_offset_value - NOBEYOND(HOME_Z_OFFSET_MIN_VALUE, z_offset_value - unit, HOME_Z_OFFSET_MAX_VALUE);

if (direction < 0)
if (unit != 0)
{
if (z_offset_value <= HOME_Z_OFFSET_MIN_VALUE)
return z_offset_value;
z_offset_value -= unit;

diff = z_offset_value - HOME_Z_OFFSET_MIN_VALUE;
sendParameterCmd(P_HOME_OFFSET, AXIS_INDEX_Z, z_offset_value); // set Z home offset value
mustStoreCmd("G1 Z%.2f\n", unit); // move nozzle
}
else
{
if (z_offset_value >= HOME_Z_OFFSET_MAX_VALUE)
return z_offset_value;

diff = HOME_Z_OFFSET_MAX_VALUE - z_offset_value;
}

unit = ((diff > unit) ? unit : diff) * direction;
z_offset_value -= unit;
sendParameterCmd(P_HOME_OFFSET, AXIS_INDEX_Z, z_offset_value); // set Z offset value
mustStoreCmd("G1 Z%.2f\n", unit); // move nozzle

return z_offset_value;
}
2 changes: 1 addition & 1 deletion TFT/src/User/API/HomeOffsetControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ float homeOffsetGetValue(void);
float homeOffsetResetValue(void);

// Update Z offset value
float homeOffsetUpdateValue(float unit, int8_t direction);
float homeOffsetUpdateValue(float unit);

#ifdef __cplusplus
}
Expand Down
5 changes: 2 additions & 3 deletions TFT/src/User/API/ProbeHeightControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ void probeHeightAbsolute(void)
}

// Change probe height
void probeHeightMove(float unit, int8_t direction)
void probeHeightMove(float unit)
{
storeCmd(MOVE_Z_CMD, unit * direction,
infoSettings.level_feedrate[FEEDRATE_Z]);
storeCmd(MOVE_Z_CMD, unit, infoSettings.level_feedrate[FEEDRATE_Z]);
}

// Query for new coordinates
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/ProbeHeightControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void probeHeightRelative(void);
void probeHeightAbsolute(void);

// Change probe height
void probeHeightMove(float unit, int8_t direction);
void probeHeightMove(float unit);

// Query for new coordinates
void probeHeightQueryCoord(void);
Expand Down
38 changes: 12 additions & 26 deletions TFT/src/User/API/ProbeOffsetControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,42 +80,28 @@ float probeOffsetGetValue(void)
// Reset Z offset value to default value
float probeOffsetResetValue(void)
{
if (z_offset_value == PROBE_Z_OFFSET_DEFAULT_VALUE) // if already default value, nothing to do
return z_offset_value;

float unit = z_offset_value - PROBE_Z_OFFSET_DEFAULT_VALUE;

z_offset_value = PROBE_Z_OFFSET_DEFAULT_VALUE;
sendParameterCmd(P_PROBE_OFFSET, AXIS_INDEX_Z, z_offset_value); // set Z offset value
mustStoreCmd("G1 Z%.2f\n", -unit); // move nozzle
if (z_offset_value != PROBE_Z_OFFSET_DEFAULT_VALUE) // if already default value, nothing to do
{
sendParameterCmd(P_PROBE_OFFSET, AXIS_INDEX_Z, PROBE_Z_OFFSET_DEFAULT_VALUE); // set Z probe offset value
mustStoreCmd("G1 Z%.2f\n", PROBE_Z_OFFSET_DEFAULT_VALUE - z_offset_value); // move nozzle
z_offset_value = PROBE_Z_OFFSET_DEFAULT_VALUE;
}

return z_offset_value;
}

// Update Z offset value
float probeOffsetUpdateValue(float unit, int8_t direction)
float probeOffsetUpdateValue(float unit)
{
float diff;
unit = NOBEYOND(PROBE_Z_OFFSET_MIN_VALUE, z_offset_value + unit, PROBE_Z_OFFSET_MAX_VALUE) - z_offset_value;

if (direction < 0)
if (unit != 0)
{
if (z_offset_value <= PROBE_Z_OFFSET_MIN_VALUE)
return z_offset_value;
z_offset_value += unit;

diff = z_offset_value - PROBE_Z_OFFSET_MIN_VALUE;
sendParameterCmd(P_PROBE_OFFSET, AXIS_INDEX_Z, z_offset_value); // set Z probe offset value
mustStoreCmd("G1 Z%.2f\n", unit); // move nozzle
}
else
{
if (z_offset_value >= PROBE_Z_OFFSET_MAX_VALUE)
return z_offset_value;

diff = PROBE_Z_OFFSET_MAX_VALUE - z_offset_value;
}

unit = ((diff > unit) ? unit : diff) * direction;
z_offset_value += unit;
sendParameterCmd(P_PROBE_OFFSET, AXIS_INDEX_Z, z_offset_value); // set Z offset value
mustStoreCmd("G1 Z%.2f\n", unit); // move nozzle

return z_offset_value;
}
2 changes: 1 addition & 1 deletion TFT/src/User/API/ProbeOffsetControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ float probeOffsetGetValue(void);
float probeOffsetResetValue(void);

// Update Z offset value
float probeOffsetUpdateValue(float unit, int8_t direction);
float probeOffsetUpdateValue(float unit);

#ifdef __cplusplus
}
Expand Down
8 changes: 3 additions & 5 deletions TFT/src/User/API/UI/ListItem.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ void ListItem_Display(const GUI_RECT * rect, uint8_t position, const LISTITEM *
{
drawCharIcon(rect, CENTER, curitem->icon, true, infoSettings.list_button_bg_color);
}
else if (curitem->icon == CHARICON_BLANK && curitem->titlelabel.index != LABEL_NULL)
else if (curitem->titlelabel.index != LABEL_NULL)
{
GUI_SetBkColor(infoSettings.list_button_bg_color);
GUI_ClearPrect(rect);
GUI_DispStringInPrect(rect, curitem->titlelabel.index);
}

if (pressed)
{
GUI_SetColor(LI_KEY_PRESSED_COLOR);
Expand Down Expand Up @@ -185,10 +186,7 @@ void ListItem_DisplayToggle(uint16_t sx, uint16_t sy, uint8_t iconchar_state)
GUI_SetTextMode(GUI_TEXTMODE_TRANS);
GUI_SetColor(charIconColor[iconchar_state]);

if (iconchar_state == CHARICON_TOGGLE_OFF)
_GUI_DispString(sx, sy, IconCharSelect(CHARICON_TOGGLE_SWITCH));
else
_GUI_DispString(sx + BYTE_HEIGHT, sy, IconCharSelect(CHARICON_TOGGLE_SWITCH));
_GUI_DispString(sx + (iconchar_state == CHARICON_TOGGLE_OFF ? 0 : BYTE_HEIGHT), sy, IconCharSelect(CHARICON_TOGGLE_SWITCH));

GUI_RestoreColorDefault();
}
Expand Down
5 changes: 1 addition & 4 deletions TFT/src/User/API/UI/ListManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ void listViewCreate(LABEL title, LISTITEM * items, uint16_t maxItems, uint16_t *
action_prepareItem = prepareItem_action;
curPageIndexSource = curPage;

if (curPage != NULL)
curPageIndex = *curPage;
else
curPageIndex = 0;
curPageIndex = (curPage == NULL) ? 0 : *curPage;

listViewSetCurPage(curPageIndex);
menuDrawListPage(&listItems);
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/interfaceCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ void sendQueueCmd(void)

case 28: // G28
coordinateSetKnown(true);
babystepReset();
babystepSetValue(BABYSTEP_DEFAULT_VALUE); // reset babystep
if (infoMachineSettings.leveling != BL_DISABLED)
storeCmd("M420\n"); // check bed leveling state
break;
Expand Down
4 changes: 2 additions & 2 deletions TFT/src/User/Menu/Babystep.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ void menuBabystep(void)
// decrease babystep / Z offset
case KEY_ICON_0:
case KEY_DECREASE:
babystep = babystepUpdateValue(unit, -1);
babystep = babystepUpdateValue(-unit);
break;

// increase babystep / Z offset
case KEY_ICON_3:
case KEY_INCREASE:
babystep = babystepUpdateValue(unit, 1);
babystep = babystepUpdateValue(unit);
break;

// save to EEPROM and apply Z offset
Expand Down
12 changes: 6 additions & 6 deletions TFT/src/User/Menu/LEDColor.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ static inline uint8_t ledEditComponentValue(uint8_t index)
return ledColor[realIndex] = editIntValue(LED_MIN_VALUE, LED_MAX_VALUE, ledColor[realIndex], ledColor[realIndex]);
}

uint8_t ledUpdateComponentValue(uint8_t index, int8_t unit, int8_t direction)
uint8_t ledUpdateComponentValue(uint8_t index, int8_t unit)
{
uint8_t realIndex = ledGetComponentIndex(index);

return ledColor[realIndex] = NOBEYOND(LED_MIN_VALUE, ledColor[realIndex] + (int16_t) (direction * unit), LED_MAX_VALUE);
return ledColor[realIndex] = NOBEYOND(LED_MIN_VALUE, ledColor[realIndex] + unit, LED_MAX_VALUE);
}

uint8_t ledGetControlIndex(uint8_t keyNum)
Expand Down Expand Up @@ -375,11 +375,11 @@ void menuLEDColorCustom(void)

// use rotary encoder to update LED component value
case LED_KEY_INCREASE:
curValue = ledUpdateComponentValue(ledIndex, 1, 1);
curValue = ledUpdateComponentValue(ledIndex, 1);
break;

case LED_KEY_DECREASE:
curValue = ledUpdateComponentValue(ledIndex, 1, -1);
curValue = ledUpdateComponentValue(ledIndex, -1);
break;

case LED_KEY_IDLE:
Expand All @@ -404,12 +404,12 @@ void menuLEDColorCustom(void)

// decrease LED component value
case 2:
curValue = ledUpdateComponentValue(ledIndex, 1, -1);
curValue = ledUpdateComponentValue(ledIndex, -1);
break;

// increase LED component value
case 3:
curValue = ledUpdateComponentValue(ledIndex, 1, 1);
curValue = ledUpdateComponentValue(ledIndex, 1);
break;

default:
Expand Down
6 changes: 3 additions & 3 deletions TFT/src/User/Menu/MBL.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void menuMBL(void)
if (!mblRunning)
mblNotifyError(false);
else
probeHeightMove(unit, -1);
probeHeightMove(-unit);
break;

case KEY_INFOBOX:
Expand All @@ -200,7 +200,7 @@ void menuMBL(void)
if (!mblRunning)
mblNotifyError(false);
else
probeHeightMove(unit, 1);
probeHeightMove(unit);
break;

// change unit
Expand All @@ -217,7 +217,7 @@ void menuMBL(void)
if (!mblRunning)
mblNotifyError(false);
else
probeHeightMove(curValue.axis[Z_AXIS], -1);
probeHeightMove(-curValue.axis[Z_AXIS]);
break;

// start MBL or move to next mesh point
Expand Down
6 changes: 3 additions & 3 deletions TFT/src/User/Menu/MeshTuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ float menuMeshTuner(uint16_t col, uint16_t row, float value)
// decrease Z height
case KEY_ICON_0:
case KEY_DECREASE:
probeHeightMove(unit, -1);
probeHeightMove(-unit);
break;

// increase Z height
case KEY_ICON_3:
case KEY_INCREASE:
probeHeightMove(unit, 1);
probeHeightMove(unit);
break;

// change unit
Expand All @@ -128,7 +128,7 @@ float menuMeshTuner(uint16_t col, uint16_t row, float value)

// reset Z height
case KEY_ICON_5:
probeHeightMove(curValue.axis[Z_AXIS] - (value + shim), -1);
probeHeightMove((value + shim) - curValue.axis[Z_AXIS]);
break;

// return new Z height
Expand Down
Loading