Skip to content

Commit

Permalink
Bugfixes on top of last merged PR (#2901)
Browse files Browse the repository at this point in the history
  • Loading branch information
digant73 committed Feb 28, 2024
1 parent c0b0f20 commit 69ac0d3
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 101 deletions.
25 changes: 24 additions & 1 deletion TFT/src/User/API/LCD_Dimming.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@

#ifdef LCD_LED_PWM_CHANNEL

// in percentage 0-100
#define BRIGHTNESS_0 0
#define BRIGHTNESS_5 5
#define BRIGHTNESS_10 10
#define BRIGHTNESS_20 20
#define BRIGHTNESS_30 30
#define BRIGHTNESS_40 40
#define BRIGHTNESS_50 50
#define BRIGHTNESS_60 60
#define BRIGHTNESS_70 70
#define BRIGHTNESS_80 80
#define BRIGHTNESS_90 90
#define BRIGHTNESS_100 100

// in seconds
#define IDLE_TIME_OFF 0 // off
#define IDLE_TIME_5 5
#define IDLE_TIME_10 10
#define IDLE_TIME_30 30
#define IDLE_TIME_60 60
#define IDLE_TIME_120 120
#define IDLE_TIME_300 300

const uint8_t lcd_brightness[LCD_BRIGHTNESS_COUNT] = {
BRIGHTNESS_0,
BRIGHTNESS_5,
Expand All @@ -27,7 +50,7 @@ const uint16_t lcd_idle_times[LCD_IDLE_TIME_COUNT] = {
IDLE_TIME_60,
IDLE_TIME_120,
IDLE_TIME_300,
IDLE_TIME_CUSTOM
IDLE_TIME_CUSTOM // custom value predefined in Configuration.h
};

const LABEL lcd_idle_time_names[LCD_IDLE_TIME_COUNT] = {
Expand Down
26 changes: 2 additions & 24 deletions TFT/src/User/API/LCD_Dimming.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,11 @@
extern "C" {
#endif

#include "variants.h" // for LCD_LED_PWM_CHANNEL
#include "variants.h" // for LCD_LED_PWM_CHANNEL, KNOB_LED_COLOR_PIN etc...
#include "menu.h"

#ifdef LCD_LED_PWM_CHANNEL

#define BRIGHTNESS_0 0
#define BRIGHTNESS_5 5
#define BRIGHTNESS_10 10
#define BRIGHTNESS_20 20
#define BRIGHTNESS_30 30
#define BRIGHTNESS_40 40
#define BRIGHTNESS_50 50
#define BRIGHTNESS_60 60
#define BRIGHTNESS_70 70
#define BRIGHTNESS_80 80
#define BRIGHTNESS_90 90
#define BRIGHTNESS_100 100

#define IDLE_TIME_OFF 0 // Off
#define IDLE_TIME_5 5 // seconds
#define IDLE_TIME_10 10 // seconds
#define IDLE_TIME_30 30 // seconds
#define IDLE_TIME_60 60 // seconds
#define IDLE_TIME_120 120 // seconds
#define IDLE_TIME_300 300 // seconds
//#define IDLE_TIME_CUSTOM IDLE_TIME_5 // custom value predefined in Configuration.h

typedef enum
{
LCD_BRIGHTNESS_0 = 0,
Expand All @@ -58,7 +36,7 @@ extern "C" {
LCD_IDLE_TIME_60,
LCD_IDLE_TIME_120,
LCD_IDLE_TIME_300,
LCD_IDLE_TIME_CUSTOM,
LCD_IDLE_TIME_CUSTOM, // the related custom value is IDLE_TIME_CUSTOM predefined in Configuration.h
LCD_IDLE_TIME_COUNT
} LCD_IDLE_TIME_;

Expand Down
2 changes: 0 additions & 2 deletions TFT/src/User/API/Settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const uint16_t default_z_speed[] = {SPEED_Z_SLOW, SPEED_Z_NORMAL, SPEED_Z_
const uint16_t default_ext_speed[] = {EXTRUDE_SLOW_SPEED, EXTRUDE_NORMAL_SPEED, EXTRUDE_FAST_SPEED};
const uint16_t default_pause_speed[] = {NOZZLE_PAUSE_XY_FEEDRATE, NOZZLE_PAUSE_Z_FEEDRATE, NOZZLE_PAUSE_E_FEEDRATE};
const uint16_t default_level_speed[] = {LEVELING_XY_FEEDRATE, LEVELING_Z_FEEDRATE};
const uint16_t default_preheat_ext[] = PREHEAT_HOTEND;
const uint16_t default_preheat_bed[] = PREHEAT_BED;
const uint8_t default_led_color[] = {LED_R, LED_G, LED_B, LED_W, LED_P, LED_I};
const uint8_t default_custom_enabled[] = CUSTOM_GCODE_ENABLED;

Expand Down
4 changes: 1 addition & 3 deletions TFT/src/User/API/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ typedef struct
typedef struct
{
char preheat_name[PREHEAT_COUNT][MAX_STRING_LENGTH + 1];
uint16_t preheat_temp[PREHEAT_COUNT];
uint16_t preheat_hotend[PREHEAT_COUNT];
uint16_t preheat_bed[PREHEAT_COUNT];
} PREHEAT_STORE;

Expand Down Expand Up @@ -365,8 +365,6 @@ extern const uint16_t default_move_speed[];
extern const uint16_t default_ext_speed[];
extern const uint16_t default_level_speed[];
extern const uint16_t default_pause_speed[];
extern const uint16_t default_preheat_ext[];
extern const uint16_t default_preheat_bed[];
extern const uint8_t default_custom_enabled[];

// Init settings data with default values
Expand Down
3 changes: 0 additions & 3 deletions TFT/src/User/API/Temperature.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ void heatSetCurrentTemp(uint8_t index, const int16_t temp)
return;

heater.T[index].current = NOBEYOND(-99, temp, 999);

if (infoMachineSettings.autoReportTemp)
heatSetNextUpdateTime(); // set next timeout for temperature auto-report
}

int16_t heatGetCurrentTemp(uint8_t index)
Expand Down
14 changes: 11 additions & 3 deletions TFT/src/User/API/UI/GUI.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,17 +866,25 @@ void _GUI_DispStringOnIcon(uint16_t iconIndex, GUI_POINT iconPoint, GUI_POINT te
{
if (p == NULL) return;

CHAR_INFO info;
uint16_t _iconBuffer[LARGE_BYTE_WIDTH * LARGE_BYTE_HEIGHT];
BMP_INFO iconInfo = {.index = iconIndex, .address = 0};
CHAR_INFO info;

iconBuffer = _iconBuffer;
GUI_SetTextMode(GUI_TEXTMODE_ON_ICON);

getBMPsize(&iconInfo);

while (*p)
{
getCharacterInfo(p, &info);
ICON_ReadBuffer(iconBuffer, textPos.x, textPos.y, info.pixelWidth, info.pixelHeight, iconIndex);
GUI_DispOne(iconPoint.x + textPos.x, iconPoint.y + textPos.y, &info);

if ((textPos.x >= 0 && textPos.x + info.pixelWidth <= iconInfo.width) &&
(textPos.y >= 0 && textPos.y + info.pixelHeight <= iconInfo.height))
{
ICON_ReadBuffer(iconBuffer, textPos.x, textPos.y, info.pixelWidth, info.pixelHeight, iconIndex);
GUI_DispOne(iconPoint.x + textPos.x, iconPoint.y + textPos.y, &info);
}

textPos.x += info.pixelWidth;
p += info.bytes;
Expand Down
7 changes: 2 additions & 5 deletions TFT/src/User/API/UI/ui_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,10 @@ typedef struct
uint16_t height;
} BMP_INFO;

// uint32_t _getBMPsizeAddr(uint8_t *w, uint8_t *h, uint32_t address);
// uint32_t _getBMPsizeIndex(uint8_t *w, uint8_t *h, uint16_t index);

//#define getBMPsize(x, y, c) _Generic(((c+0)), uint32_t: _getBMPsizeAddr, uint32_t*: _getBMPsizeAddr, default: _getBMPsizeIndex)(x, y, c)

void lcd_buffer_display(uint16_t sx, uint16_t sy, uint16_t w, uint16_t h, uint16_t *buf, GUI_RECT *limit);

void getBMPsize(BMP_INFO *bmp);

void LOGO_ReadDisplay(void);
void ICON_ReadDisplay(uint16_t sx, uint16_t sy, uint8_t icon);
void ICON_ReadBuffer(uint16_t *buf, uint16_t x, uint16_t y, int16_t w, int16_t h, uint16_t icon);
Expand Down
90 changes: 53 additions & 37 deletions TFT/src/User/API/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,17 @@ const GUI_RECT recterrortxt = {BYTE_WIDTH/2, BYTE_HEIGHT*2+4, LCD_WI
const GUI_RECT rectProgressframe = {BYTE_WIDTH/2-2, LCD_HEIGHT-(BYTE_HEIGHT*2+BYTE_HEIGHT/2), LCD_WIDTH-BYTE_WIDTH/2+2,LCD_HEIGHT-BYTE_HEIGHT/2};
const GUI_POINT pointProgressText = {BYTE_WIDTH/2-2, LCD_HEIGHT-(BYTE_HEIGHT*4)};

const char * const cgList[] = CUSTOM_GCODE_LIST;
const char * const cgNames[] = CUSTOM_GCODE_LABELS;
const char * const preheatNames[] = PREHEAT_LABELS;
const uint16_t preheatHotend[] = PREHEAT_HOTEND;
const uint16_t preheatBed[] = PREHEAT_BED;
const char * const cgNames[] = CUSTOM_GCODE_LABELS;
const char * const cgList[] = CUSTOM_GCODE_LIST;

CONFIGFILE* CurConfigFile;
CUSTOM_GCODES* configCustomGcodes = NULL;
PRINT_GCODES* configPrintGcodes = NULL;
STRINGS_STORE* configStringsStore = NULL;
PREHEAT_STORE* configPreheatStore = NULL;
PRINT_GCODES* configPrintGcodes = NULL;
CUSTOM_GCODES* configCustomGcodes = NULL;

char * cur_line = NULL;
uint16_t c_index = 0;
Expand Down Expand Up @@ -577,7 +579,7 @@ void parseConfigKey(uint16_t index)

case C_INDEX_MARLIN_TITLE:
{
char * pchr = strrchr(cur_line, ':') + 1;
char * pchr = strchr(cur_line, ':') + 1;
int utf8len = getUTF8Length((uint8_t*)pchr);
int bytelen = strlen(pchr) + 1;
if (inLimit(utf8len, NAME_MIN_LENGTH, MAX_STRING_LENGTH) && inLimit(bytelen, NAME_MIN_LENGTH, MAX_GCODE_LENGTH))
Expand Down Expand Up @@ -763,7 +765,7 @@ void parseConfigKey(uint16_t index)
case C_INDEX_PREHEAT_NAME_6:
{
char pchr[LINE_MAX_CHAR];
strcpy(pchr, strrchr(cur_line, ':') + 1);
strcpy(pchr, strchr(cur_line, ':') + 1);
int utf8len = getUTF8Length((uint8_t *)pchr);
int bytelen = strlen(pchr) + 1;
if (inLimit(utf8len, NAME_MIN_LENGTH, MAX_STRING_LENGTH) && inLimit(bytelen, NAME_MIN_LENGTH, MAX_STRING_LENGTH))
Expand All @@ -779,7 +781,7 @@ void parseConfigKey(uint16_t index)
case C_INDEX_PREHEAT_TEMP_6:
{
int val_index = index - C_INDEX_PREHEAT_TEMP_1;
if (key_seen("T")) SET_VALID_INT_VALUE(configPreheatStore->preheat_temp[val_index], MIN_TOOL_TEMP, MAX_TOOL_TEMP);
if (key_seen("T")) SET_VALID_INT_VALUE(configPreheatStore->preheat_hotend[val_index], MIN_TOOL_TEMP, MAX_TOOL_TEMP);
if (key_seen("B")) SET_VALID_INT_VALUE(configPreheatStore->preheat_bed[val_index], MIN_BED_TEMP, MAX_BED_TEMP);
break;
}
Expand Down Expand Up @@ -925,7 +927,7 @@ void parseConfigKey(uint16_t index)
case C_INDEX_CUSTOM_LABEL_15:
{
char pchr[LINE_MAX_CHAR];
strcpy(pchr, strrchr(cur_line, ':') + 1);
strcpy(pchr, strchr(cur_line, ':') + 1);
int utf8len = getUTF8Length((uint8_t*)pchr);
int bytelen = strlen(pchr) + 1;
if (inLimit(utf8len, NAME_MIN_LENGTH, MAX_GCODE_NAME_LENGTH) && inLimit(bytelen, NAME_MIN_LENGTH, MAX_GCODE_LENGTH))
Expand Down Expand Up @@ -957,7 +959,7 @@ void parseConfigKey(uint16_t index)
{
int lineIndex = index - C_INDEX_CUSTOM_GCODE_1; // actual gcode index in config file
char pchr[LINE_MAX_CHAR];
strcpy(pchr, strrchr(cur_line, ':') + 1);
strcpy(pchr, strchr(cur_line, ':') + 1);
int len = strlen(pchr) + 1;
// check if gcode length is ok and the name was ok
if (inLimit(len, GCODE_MIN_LENGTH, MAX_GCODE_LENGTH) && (customcode_good[lineIndex] == 1))
Expand All @@ -977,7 +979,7 @@ void parseConfigKey(uint16_t index)

case C_INDEX_START_GCODE:
{
char * pchr = strrchr(cur_line, ':') + 1;
char * pchr = strchr(cur_line, ':') + 1;
int len = strlen(pchr);
if (inLimit(len, GCODE_MIN_LENGTH, MAX_GCODE_LENGTH))
{
Expand All @@ -994,7 +996,7 @@ void parseConfigKey(uint16_t index)

case C_INDEX_END_GCODE:
{
char * pchr = strrchr(cur_line, ':') + 1;
char * pchr = strchr(cur_line, ':') + 1;
int len = strlen(pchr);
if (inLimit(len, GCODE_MIN_LENGTH, MAX_GCODE_LENGTH))
{
Expand All @@ -1011,7 +1013,7 @@ void parseConfigKey(uint16_t index)

case C_INDEX_CANCEL_GCODE:
{
char * pchr = strrchr(cur_line, ':') + 1;
char * pchr = strchr(cur_line, ':') + 1;
int len = strlen(pchr);
if (inLimit(len, GCODE_MIN_LENGTH, MAX_GCODE_LENGTH))
{
Expand Down Expand Up @@ -1195,10 +1197,10 @@ void writeConfig(uint8_t * dataBytes, uint16_t numBytes, uint32_t addr, uint32_t

void saveConfig(void)
{
writeConfig((uint8_t *)configCustomGcodes, sizeof(CUSTOM_GCODES), CUSTOM_GCODE_ADDR, CUSTOM_GCODE_MAX_SIZE);
writeConfig((uint8_t *)configPrintGcodes, sizeof(PRINT_GCODES), PRINT_GCODES_ADDR, PRINT_GCODES_MAX_SIZE);
writeConfig((uint8_t *)configStringsStore, sizeof(STRINGS_STORE), STRINGS_STORE_ADDR, STRINGS_STORE_MAX_SIZE);
writeConfig((uint8_t *)configPreheatStore, sizeof(PREHEAT_STORE), PREHEAT_STORE_ADDR, PREHEAT_STORE_MAX_SIZE);
writeConfig((uint8_t *)configPrintGcodes, sizeof(PRINT_GCODES), PRINT_GCODES_ADDR, PRINT_GCODES_MAX_SIZE);
writeConfig((uint8_t *)configCustomGcodes, sizeof(CUSTOM_GCODES), CUSTOM_GCODE_ADDR, CUSTOM_GCODE_MAX_SIZE);

#ifdef CONFIG_DEBUG
CUSTOM_GCODES tempgcode; // = NULL;
Expand All @@ -1214,41 +1216,45 @@ void saveConfig(void)
// Reset & store config settings
void resetConfig(void)
{
CUSTOM_GCODES tempCG;
STRINGS_STORE tempST;
PRINT_GCODES tempPC;
PREHEAT_STORE tempPH;

// restore custom gcode presets
int n = 0;
for (int i = 0; i < CUSTOM_GCODES_COUNT; i++)
{
if (default_custom_enabled[i] == 1)
{
strcpy(tempCG.gcode[n],cgList[i]);
strcpy(tempCG.name[n],cgNames[i]);
n++;
}
}
tempCG.count = n;
PRINT_GCODES tempPC;
CUSTOM_GCODES tempCG;

// restore strings store
strcpy(tempST.marlin_title, MARLIN_TITLE);

// restore preheat presets
for (int i = 0; i < PREHEAT_COUNT; i++)
{
strcpy(tempPH.preheat_name[i], preheatNames[i]);
tempPH.preheat_hotend[i] = preheatHotend[i];
tempPH.preheat_bed[i] = preheatBed[i];
}

// restore print gcodes
strcpy(tempPC.start_gcode, START_GCODE);
strcpy(tempPC.end_gcode, END_GCODE);
strcpy(tempPC.cancel_gcode, CANCEL_GCODE);

// restore custom gcode presets
int n = 0;
for (int i = 0; i < CUSTOM_GCODES_COUNT; i++)
{
if (default_custom_enabled[i] == 1)
{
strcpy(tempCG.name[n], cgNames[i]);
strcpy(tempCG.gcode[n], cgList[i]);
n++;
}
}
tempCG.count = n;

// write restored config
writeConfig((uint8_t *)&tempCG, sizeof(CUSTOM_GCODES), CUSTOM_GCODE_ADDR, CUSTOM_GCODE_MAX_SIZE);
writeConfig((uint8_t *)&tempPC, sizeof(PRINT_GCODES), PRINT_GCODES_ADDR, PRINT_GCODES_MAX_SIZE);
writeConfig((uint8_t *)&tempST, sizeof(STRINGS_STORE), STRINGS_STORE_ADDR, STRINGS_STORE_MAX_SIZE);
writeConfig((uint8_t *)&tempPH, sizeof(PREHEAT_STORE), PREHEAT_STORE_ADDR, PREHEAT_STORE_MAX_SIZE);
writeConfig((uint8_t *)&tempPC, sizeof(PRINT_GCODES), PRINT_GCODES_ADDR, PRINT_GCODES_MAX_SIZE);
writeConfig((uint8_t *)&tempCG, sizeof(CUSTOM_GCODES), CUSTOM_GCODE_ADDR, CUSTOM_GCODE_MAX_SIZE);
}

bool getConfigFromFile(char * configPath)
Expand All @@ -1259,18 +1265,25 @@ bool getConfigFromFile(char * configPath)
return false;
}

CUSTOM_GCODES tempCustomGcodes;
PRINT_GCODES tempPrintCodes;
// initialize all settings to default values before eventually overwriting them with the values from configuration file.
// resetConfig() function is also invoked by initSettings() function just to initialize the following 4 data structures
// into the flash before loading them from the flash
initSettings();

STRINGS_STORE tempStringStore;
PREHEAT_STORE tempPreheatStore;
PRINT_GCODES tempPrintCodes;
CUSTOM_GCODES tempCustomGcodes;

// initialize all settings to default values before eventually overwriting them with values from configuration file
initSettings();
W25Qxx_ReadBuffer((uint8_t*)&tempStringStore, STRINGS_STORE_ADDR, sizeof(STRINGS_STORE));
W25Qxx_ReadBuffer((uint8_t*)&tempPreheatStore, PREHEAT_STORE_ADDR, sizeof(PREHEAT_STORE));
W25Qxx_ReadBuffer((uint8_t*)&tempPrintCodes, PRINT_GCODES_ADDR, sizeof(PRINT_GCODES));
W25Qxx_ReadBuffer((uint8_t*)&tempCustomGcodes, CUSTOM_GCODE_ADDR, sizeof(CUSTOM_GCODES));

configCustomGcodes = &tempCustomGcodes;
configPrintGcodes = &tempPrintCodes;
configStringsStore = &tempStringStore;
configPreheatStore = &tempPreheatStore;
configPrintGcodes = &tempPrintCodes;
configCustomGcodes = &tempCustomGcodes;
customcode_index = 0;
foundkeys = 0;

Expand All @@ -1286,13 +1299,16 @@ bool getConfigFromFile(char * configPath)

PRINTDEBUG("\nCustom gcode stored at 1:");
PRINTDEBUG(configCustomGcodes->gcode[1]);

if (scheduleRotate)
{
LCD_RefreshDirection(infoSettings.rotated_ui);
TS_Calibrate();
}

storePara(); // TODO: The touch sign will also be written if the touch calibration data is invalid
saveConfig();

PRINTDEBUG("config saved\n");
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/Menu/MeshValid.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void menuMeshValid(void)
// MESHVALID NYLON
case KEY_ICON_5:
mustStoreCmd("G28\n");
mustStoreCmd("G26 H%u B%u R99\n", preheatStore.preheat_temp[key_num], preheatStore.preheat_bed[key_num]);
mustStoreCmd("G26 H%u B%u R99\n", preheatStore.preheat_hotend[key_num], preheatStore.preheat_bed[key_num]);
mustStoreCmd("G1 Z10 F%d\n", infoSettings.level_feedrate[FEEDRATE_Z]);
mustStoreCmd("G1 X0 F%d\n", infoSettings.level_feedrate[FEEDRATE_XY]);
refreshPreheatIcon(&preheatStore, key_num, false);
Expand Down
Loading

0 comments on commit 69ac0d3

Please sign in to comment.