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
Next Next commit
FW size reduction
  • Loading branch information
kisslorand committed Apr 11, 2023
commit b2b80d1d6664ed505a3d8d62434ad605f8264a86
36 changes: 0 additions & 36 deletions TFT/src/User/API/CaseLightControl.c

This file was deleted.

21 changes: 0 additions & 21 deletions TFT/src/User/API/CaseLightControl.h

This file was deleted.

1 change: 1 addition & 0 deletions TFT/src/User/API/Temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum
BED = MAX_HOTEND_COUNT,
CHAMBER,
INVALID_HEATER,
LAST_NOZZLE,
};

typedef struct
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 @@ -1219,7 +1219,7 @@ void sendQueueCmd(void)
caseLightSetState(cmd_value() > 0);

if (cmd_seen('P'))
caseLightSetBrightness(cmd_value());
caseLightSetPercent(cmd_value());
break;

case 376: // M376 (Reprap FW)
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/parseACK.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ void parseACK(void)
else
{
caseLightSetState(true);
caseLightSetBrightness(ack_value());
caseLightSetPercent(ack_value());
}
}
// parse and store M420 V1 T1, mesh data (e.g. from Mesh Editor menu)
Expand Down
107 changes: 63 additions & 44 deletions TFT/src/User/Menu/CaseLight.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,36 @@

#define CASE_LIGHT_UPDATE_TIME 1000 // 1 seconds is 1000

// Icons list for Case Light
const ITEM itemCaseLight[2] = {
// icon label
{ICON_RGB_OFF, LABEL_OFF},
{ICON_RGB_WHITE, LABEL_ON},
};
static uint8_t caseLightPercent = 0;
static bool caseLightState;

static uint8_t curUnit_index = 1;

static inline void updateCaseLightIcon(MENUITEMS * curmenu, bool state)
static void updateCaseLightIcon(MENUITEMS * curmenu, const bool state)
{
curmenu->items[KEY_ICON_5] = itemCaseLight[state ? 1 : 0];
curmenu->items[KEY_ICON_5].icon = state ? ICON_RGB_WHITE : ICON_RGB_OFF;
curmenu->items[KEY_ICON_5].label.index = state ? LABEL_ON : LABEL_OFF;
}

void caseLightBrightnessReDraw()
void caseLightPercentReDraw(void)
{
char tempstr[20];

sprintf(tempstr, " %d%% ", caseLightGetBrightnessPercent());
sprintf(tempstr, " %d%% ", caseLightPercent);
setFontSize(FONT_SIZE_LARGE);
GUI_DispStringInPrect(&exhibitRect, (uint8_t *)tempstr);
setFontSize(FONT_SIZE_NORMAL);
}

void caseLightSetPercent(uint8_t brightness)
{
brightness = NOBEYOND(0, brightness, 255);
caseLightPercent = (brightness * 100.0f) / 255 + 0.5f;
}

void caseLightSetState(const bool state)
{
caseLightState = state;
}

void menuCaseLight(void)
{
// 1 title, ITEM_PER_PAGE items (icon + label)
Expand All @@ -47,19 +53,26 @@ void menuCaseLight(void)
};

KEY_VALUES key_num = KEY_IDLE;
bool currentCaseLightState = caseLightGetState();
bool previousCaseLightState = currentCaseLightState;
uint8_t currentCaseLightBrightness = caseLightGetBrightness();
uint8_t previousCaseLightBrightness = currentCaseLightBrightness;
bool sendingNeeded = false;
uint8_t requestedCLpercent = caseLightPercent;
uint8_t requestedCLstate = caseLightState;
static uint8_t percent_index = 1;

storeCmd("M355\n"); // retrieve the case light's state and brightness. Value will be compared in while loop
enum
{
SEND_NOTHING = 0B0000,
DO_SEND_PERCENT = 0B0001,
NOT_SEND_PERCENT = 0B1110,
DO_SEND_STATE = 0B0010,
NOT_SEND_STATE = 0B1101,
} sendingNeeded = SEND_NOTHING;

caseLightItems.items[KEY_ICON_4] = itemPercent[curUnit_index];
updateCaseLightIcon(&caseLightItems, currentCaseLightState);
caseLightItems.items[KEY_ICON_4] = itemPercent[percent_index];
updateCaseLightIcon(&caseLightItems, caseLightState);

menuDrawPage(&caseLightItems);
caseLightBrightnessReDraw();
caseLightPercentReDraw();

mustStoreCmd("M355\n");

while (MENU_IS(menuCaseLight))
{
Expand All @@ -70,26 +83,27 @@ void menuCaseLight(void)
// decrease case light
case KEY_ICON_0:
case KEY_DECREASE:
caseLightSetBrightnessPercent(- percentSteps[curUnit_index]);
break;

// increase case light
case KEY_ICON_3:
case KEY_INCREASE:
caseLightSetBrightnessPercent(+ percentSteps[curUnit_index]);
requestedCLpercent = (key_num == KEY_ICON_3 || key_num == KEY_INCREASE) ?
NOBEYOND(0, requestedCLpercent + percentSteps[percent_index], 100) :
NOBEYOND(0, requestedCLpercent - percentSteps[percent_index], 100);
sendingNeeded |= DO_SEND_PERCENT;
break;

// change unit
case KEY_ICON_4:
curUnit_index = (curUnit_index + 1) % ITEM_PERCENT_STEPS_NUM;
percent_index = (percent_index + 1) % ITEM_PERCENT_STEPS_NUM;

caseLightItems.items[key_num] = itemPercent[curUnit_index];
caseLightItems.items[key_num] = itemPercent[percent_index];
menuDrawItem(&caseLightItems.items[key_num], key_num);
break;

// switch on/off case light
case KEY_ICON_5:
caseLightSetState(!currentCaseLightState);
TOGGLE_BIT(requestedCLstate, 0);
sendingNeeded |= DO_SEND_STATE;
break;

case KEY_ICON_7:
Expand All @@ -100,32 +114,37 @@ void menuCaseLight(void)
break;
}

currentCaseLightState = caseLightGetState();
if (previousCaseLightState != currentCaseLightState) // dynamically change the light on/off icon based on the current state
if (requestedCLpercent != caseLightPercent)
{
previousCaseLightState = currentCaseLightState;

updateCaseLightIcon(&caseLightItems, currentCaseLightState);
menuDrawItem(&caseLightItems.items[KEY_ICON_5], KEY_ICON_5);
if (sendingNeeded & DO_SEND_PERCENT)
caseLightPercent = requestedCLpercent;
else
requestedCLpercent = caseLightPercent;

sendingNeeded = true;
caseLightPercentReDraw();
}

currentCaseLightBrightness = caseLightGetBrightness();
if (previousCaseLightBrightness != currentCaseLightBrightness)
if (requestedCLstate != caseLightState)
{
previousCaseLightBrightness = currentCaseLightBrightness;
if (sendingNeeded & DO_SEND_STATE)
caseLightState = requestedCLstate;
else
requestedCLstate = caseLightState;

caseLightBrightnessReDraw();

sendingNeeded = true;
updateCaseLightIcon(&caseLightItems, caseLightState);
menuDrawItem(&caseLightItems.items[KEY_ICON_5], KEY_ICON_5);
}

if (sendingNeeded && nextScreenUpdate(CASE_LIGHT_UPDATE_TIME))
if (sendingNeeded & DO_SEND_PERCENT)
{
storeCmd("M355 S%d P%d\n", currentCaseLightState ? 1 : 0, currentCaseLightBrightness);
if (storeCmd("M355 P%d\n", requestedCLpercent * 255U / 100))
sendingNeeded &= NOT_SEND_PERCENT;
}

sendingNeeded = false;
if (sendingNeeded & DO_SEND_STATE)
{
if (storeCmd("M355 S%d\n", requestedCLstate))
sendingNeeded &= NOT_SEND_STATE;
}

loopProcess();
Expand Down
5 changes: 5 additions & 0 deletions TFT/src/User/Menu/CaseLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
extern "C" {
#endif

#include <stdbool.h>
#include <stdint.h>

void menuCaseLight(void);
void caseLightSetPercent(uint8_t brightness);
void caseLightSetState(bool state);

#ifdef __cplusplus
}
Expand Down
16 changes: 8 additions & 8 deletions TFT/src/User/Menu/Fan.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#include "Fan.h"
#include "includes.h"

const ITEM itemFan[2] = {
// icon label
{ICON_FAN, LABEL_FAN},
{ICON_FAN_HALF_SPEED, LABEL_HALF},
};

static uint8_t fan_index = 0;

void menuFan(void)
Expand Down Expand Up @@ -35,9 +29,15 @@ void menuFan(void)
lastFan = (LASTFAN) {fanGetCurSpeed(fan_index), fanGetSetSpeed(fan_index)};

if ((infoSettings.fan_count + infoSettings.ctrl_fan_en) > 1)
fanItems.items[KEY_ICON_4] = itemFan[0];
{
fanItems.items[KEY_ICON_4].icon = ICON_FAN;
fanItems.items[KEY_ICON_4].label.index = LABEL_FAN;
}
else
fanItems.items[KEY_ICON_4] = itemFan[1];
{
fanItems.items[KEY_ICON_4].icon = ICON_FAN_HALF_SPEED;
fanItems.items[KEY_ICON_4].label.index = LABEL_HALF;
}

menuDrawPage(&fanItems);
fanReDraw(fan_index, true);
Expand Down
20 changes: 6 additions & 14 deletions TFT/src/User/Menu/Heat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@
#include "includes.h"

static uint8_t tool_index = NOZZLE0;
static uint8_t last_hotend_index = NOZZLE0;
static uint8_t last_bed_index = BED;
static uint8_t degreeSteps_index = 1;
static uint8_t last_nozzle_index = NOZZLE0;

void heatSetCurrentIndex(int8_t index)
void heatSetCurrentIndex(uint8_t index)
{
if (index >= 0) // set specific tool
tool_index = (uint8_t)(index);
else if (index == -1) // set last used hotend index
tool_index = last_hotend_index;
else // set last used bed index
tool_index = last_bed_index;
tool_index = (index == LAST_NOZZLE) ? last_nozzle_index : index;
}

void menuHeat(void)
Expand All @@ -35,6 +28,7 @@ void menuHeat(void)
}
};

static uint8_t degreeSteps_index = 1;
KEY_VALUES key_num = KEY_IDLE;
int16_t lastCurrent = heatGetCurrentTemp(tool_index);
int16_t lastTarget = heatGetTargetTemp(tool_index);
Expand Down Expand Up @@ -122,10 +116,8 @@ void menuHeat(void)
loopProcess();
}

if (tool_index < BED)
last_hotend_index = tool_index; // save last used hotend index
else
last_bed_index = tool_index; // save last used bed index
if (WITHIN(tool_index, NOZZLE0, NOZZLE5))
last_nozzle_index = tool_index; // save last used hotend index

// Set slow update time if not waiting for target temperature
if (heatHasWaiting() == false)
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/Menu/Heat.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern "C" {
* index == -1 to set the last used hotend index
* index == -2 to set the last used bed index
*/
void heatSetCurrentIndex(int8_t index);
void heatSetCurrentIndex(uint8_t index);
void menuHeat(void);

#ifdef __cplusplus
Expand Down
10 changes: 6 additions & 4 deletions TFT/src/User/Menu/MachineSettings.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,17 @@ void menuMachineSettings(void)

if (infoMachineSettings.firmwareType == FW_REPRAPFW)
{
ITEM no_custom = { ICON_NULL, LABEL_NULL };
machineSettingsItems.items[2] = no_custom;
machineSettingsItems.items[2].icon = ICON_NULL;
machineSettingsItems.items[2].label.index = LABEL_NULL;
}

KEY_VALUES curIndex = KEY_IDLE;
const ITEM itemCaseLight = {ICON_CASE_LIGHT, LABEL_CASE_LIGHT};

if (infoMachineSettings.caseLightsBrightness == ENABLED)
machineSettingsItems.items[KEY_ICON_6] = itemCaseLight;
{
machineSettingsItems.items[KEY_ICON_6].icon = ICON_CASE_LIGHT;
machineSettingsItems.items[KEY_ICON_6].label.index = LABEL_CASE_LIGHT;
}

menuDrawPage(&machineSettingsItems);

Expand Down
Loading