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

Various bugfixes, timer rollover bugs, encoder, long press freeze bug, encoder issue at higher values #2967

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Next Next commit
Various bugfixes, timer rollover bugs, encoder, long freeze bug, enco…
…der bug

Solves various timer rollover bugs
Solves the encoder not working well bug
Solves the long press freeze bug
Corrects the UART6 pins on MKS TFT35 V1.0

Enhancements, improved handling of back button and long press button
2 additional serial baud rates
Adds several long press functions (jump temp, adjust movement speed, jump to temp from extruder menu)
rondlh committed Dec 11, 2024
commit 3698c62d95cf4c34b076103d03cfff4cdc204e4e
2 changes: 1 addition & 1 deletion Copy to SD Card root directory to update/config.ini
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@
# P2: [min: 0, max: 11]
# P3: [min: 0, max: 11]
# P4: [min: 0, max: 11]
# Options: [OFF (port disabled): 0, 2400: 1, 9600: 2, 19200: 3, 38400: 4, 57600: 5, 115200: 6, 230400: 7, 250000: 8, 500000: 9, 921600: 10, 1000000: 11]
# Options: [OFF (port disabled): 0, 2400: 1, 9600: 2, 19200: 3, 38400: 4, 57600: 5, 115200: 6, 230400: 7, 250K: 8, 500K: 9, 921600: 10, 1M: 11, 1958400: 12, 2M: 13]
serial_port:P1:6 P2:0 P3:0 P4:0

#### TX Slots
2 changes: 1 addition & 1 deletion Copy to SD Card root directory to update/config_rrf.ini
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@
# P2: [min: 0, max: 11]
# P3: [min: 0, max: 11]
# P4: [min: 0, max: 11]
# Options: [OFF (port disabled): 0, 2400: 1, 9600: 2, 19200: 3, 38400: 4, 57600: 5, 115200: 6, 230400: 7, 250000: 8, 500000: 9, 921600: 10, 1000000: 11]
# Options: [OFF (port disabled): 0, 2400: 1, 9600: 2, 19200: 3, 38400: 4, 57600: 5, 115200: 6, 230400: 7, 250K: 8, 500K: 9, 921600: 10, 1M: 11, 1958400: 12, 2M: 13]
serial_port:P1:5 P2:0 P3:0 P4:0

#### TX Slots
18 changes: 9 additions & 9 deletions TFT/src/User/API/AddonHardware.c
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ enum
FILAMENT_SENSOR_SMART,
};

static uint32_t posE_nextUpdateTime = FIL_ALARM_REMINDER_TIME; // give TFT time to connect to mainboard first before polling for runout
static uint32_t posE_lastUpdateTime = FIL_ALARM_REMINDER_TIME; // give TFT time to connect to mainboard first before polling for runout
static bool posE_sendingWaiting = false;
static bool sfs_alive = false; // use an encoder disc to toggles the runout. Suitable for BigTreeTech Smart Filament Sensor

@@ -87,9 +87,9 @@ static bool FIL_NormalRunoutDetect(void)
{
static bool runout = false;
static int32_t trigBalance = 0;
static uint32_t nextUpdateTime = 0;
static uint32_t lastUpdateTime = 0;

if (OS_GetTimeMs() < nextUpdateTime)
if (OS_GetTimeMs() - lastUpdateTime < infoSettings.runout_noise)
{
bool pinState = false;
uint8_t toolNum = heatGetToolIndex();
@@ -144,7 +144,7 @@ static bool FIL_NormalRunoutDetect(void)

runout = (trigBalance > 0);
trigBalance = 0;
nextUpdateTime = OS_GetTimeMs() + infoSettings.runout_noise;
lastUpdateTime = OS_GetTimeMs();

return runout;
}
@@ -160,10 +160,10 @@ static inline bool FIL_SmartRunoutDetect(void)
do
{ // send M114 E to query extrude position continuously

if (OS_GetTimeMs() < posE_nextUpdateTime) // if next check time not yet elapsed, do nothing
if (OS_GetTimeMs() - posE_lastUpdateTime < FIL_POS_E_REFRESH_TIME) // if next check time not yet elapsed, do nothing
break;

posE_nextUpdateTime = OS_GetTimeMs() + FIL_POS_E_REFRESH_TIME; // extend next check time
posE_lastUpdateTime = OS_GetTimeMs(); // extend next check time

// if M114 previously enqueued and not yet sent or pending command
// (to avoid collision in gcode response processing), do nothing
@@ -219,7 +219,7 @@ void FIL_BE_CheckRunout(void)

void FIL_FE_CheckRunout(void)
{
static uint32_t nextReminderTime = 0;
static uint32_t lastReminderTime = 0;

if (!getPrintRunout() && !getRunoutAlarm())
return;
@@ -230,10 +230,10 @@ void FIL_FE_CheckRunout(void)
popupDialog(DIALOG_TYPE_ALERT, LABEL_WARNING, LABEL_FILAMENT_RUNOUT, LABEL_CONFIRM, LABEL_NULL, setRunoutAlarmFalse, NULL, NULL);
}

if (OS_GetTimeMs() >= nextReminderTime && getRunoutAlarm())
if ((OS_GetTimeMs() - lastReminderTime >= FIL_ALARM_REMINDER_TIME) && getRunoutAlarm())
{
BUZZER_PLAY(SOUND_ERROR);
nextReminderTime = OS_GetTimeMs() + FIL_ALARM_REMINDER_TIME;
lastReminderTime = OS_GetTimeMs();
}
}

6 changes: 3 additions & 3 deletions TFT/src/User/API/FanControl.c
Original file line number Diff line number Diff line change
@@ -74,12 +74,12 @@ uint8_t fanGetCurPercent(const uint8_t i)

void loopCheckFan(void)
{
static uint32_t nextUpdateTime = 0;
static uint32_t lastUpdateTime = 0;

if (OS_GetTimeMs() < nextUpdateTime) // avoid rapid fire, clogging the queue
if (OS_GetTimeMs() - lastUpdateTime < FAN_REFRESH_TIME) // avoid rapid fire, clogging the queue
return;

nextUpdateTime = OS_GetTimeMs() + FAN_REFRESH_TIME; // extend next check time
lastUpdateTime = OS_GetTimeMs();

for (uint8_t i = 0; i < MAX_FAN_COUNT; i++)
{
22 changes: 11 additions & 11 deletions TFT/src/User/API/Mainboard_FlowControl.c
Original file line number Diff line number Diff line change
@@ -54,6 +54,16 @@ void loopBackEnd(void)
USB_LoopProcess();
#endif

// check changes in encoder steps
#if LCD_ENCODER_SUPPORT
#ifdef HAS_EMULATOR
if (MENU_IS_NOT(menuMarlinMode))
#endif
{
LCD_Enc_CheckSteps();
}
#endif

if ((priorityCounter.be++ % BE_PRIORITY_DIVIDER) != 0) // a divider value of 16 -> run 6% of the time only
return;

@@ -81,16 +91,6 @@ void loopBackEnd(void)
FIL_BE_CheckRunout();
#endif

// check changes in encoder steps
#if LCD_ENCODER_SUPPORT
#ifdef HAS_EMULATOR
if (MENU_IS_NOT(menuMarlinMode))
#endif
{
LCD_Enc_CheckSteps();
}
#endif

// check mode switching
#ifdef HAS_EMULATOR
Mode_CheckSwitching();
@@ -103,7 +103,7 @@ void loopBackEnd(void)

// check if Back is pressed and held
#ifdef SMART_HOME
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this entire block is no more needed, remove it all (also the SMART_HOME definition and usage)

loopCheckBackPress();
// loopCheckBackPress(); // not needed anymore, done in menu.c
#endif

// check LCD screen dimming
4 changes: 2 additions & 2 deletions TFT/src/User/API/Notification.c
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ void drawToast(bool redraw)
if (!redraw) // if notification is new
{
BUZZER_PLAY(curSound); // play sound
nextToastTime = OS_GetTimeMs() + SEC_TO_MS(TOAST_DURATION); // set new timer
nextToastTime = OS_GetTimeMs();
}

GUI_SetTextMode(GUI_TEXTMODE_TRANS);
@@ -121,7 +121,7 @@ static inline bool toastAvailable(void)
void loopToast(void)
{
// if no new toast is available or it is not yet expired on screen or in case a full screen menu is displayed, do nothing
if (_toastAvailable == false || OS_GetTimeMs() < nextToastTime || getMenuType() == MENU_TYPE_FULLSCREEN)
if (_toastAvailable == false || ((OS_GetTimeMs() - nextToastTime) < SEC_TO_MS(TOAST_DURATION)) || getMenuType() == MENU_TYPE_FULLSCREEN)
return;

if (toastAvailable())
9 changes: 5 additions & 4 deletions TFT/src/User/API/Printing.c
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ static bool extrusionDuringPause = false; // flag for extrusion during Print ->
static bool filamentRunoutAlarm = false;
static float lastEPos = 0; // used only to update stats in infoPrintSummary

static uint32_t nextUpdateTime = 0;
static uint32_t lastUpdateTime = 0;
static bool sendingWaiting = false;

PRINT_SUMMARY infoPrintSummary = {.name[0] = '\0', 0, 0, 0, 0, false};
@@ -917,7 +917,7 @@ void loopPrintFromTFT(void)

void printSetNextUpdateTime(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if no more used, remove this function (its name is also wrong now; should be renamed to printSetLastUpdateTime)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I left it in for reference, removed now

{
nextUpdateTime = OS_GetTimeMs() + SEC_TO_MS(infoSettings.m27_refresh_time);
lastUpdateTime = OS_GetTimeMs();
}

void printClearSendingWaiting(void)
@@ -940,10 +940,11 @@ void loopPrintFromOnboard(void)
do
{ // send M27 to query SD print status continuously

if (OS_GetTimeMs() < nextUpdateTime) // if next check time not yet elapsed, do nothing
if ((OS_GetTimeMs() - lastUpdateTime) < SEC_TO_MS(infoSettings.m27_refresh_time)) // if next check time not yet elapsed, do nothing
break;

printSetNextUpdateTime(); // extend next check time
//printSetNextUpdateTime(); // extend next check time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if no more used, remove it

lastUpdateTime = OS_GetTimeMs();

// if M27 previously enqueued and not yet sent, do nothing
if (sendingWaiting)
6 changes: 3 additions & 3 deletions TFT/src/User/API/ProbeHeightControl.c
Original file line number Diff line number Diff line change
@@ -109,12 +109,12 @@ void probeHeightMove(float unit)
// query for new coordinates
void probeHeightQueryCoord(void)
{
static uint32_t nextUpdateTime = 0;
static uint32_t lastUpdateTime = 0;

if (OS_GetTimeMs() < nextUpdateTime)
if ((OS_GetTimeMs() - lastUpdateTime) < PROBE_REFRESH_TIME)
return;

nextUpdateTime = OS_GetTimeMs() + PROBE_REFRESH_TIME;
lastUpdateTime = OS_GetTimeMs();

coordinateQuery(0); // query position manually for delay less than 1 second
}
6 changes: 3 additions & 3 deletions TFT/src/User/API/RRFStatusControl.c
Original file line number Diff line number Diff line change
@@ -121,12 +121,12 @@ void rrfStatusQuery(void)
{
if (infoHost.connected)
{
static uint32_t rrf_next_query_time = 0;
static uint32_t rrf_last_query_time = 0;

if (OS_GetTimeMs() < rrf_next_query_time)
if ((OS_GetTimeMs() - rrf_last_query_time) < rrf_query_interval)
return;

rrf_next_query_time = OS_GetTimeMs() + rrf_query_interval;
rrf_last_query_time = OS_GetTimeMs();

// don't send status queries while in the terminal menu to avoid flooding the console
if (MENU_IS(menuTerminal))
4 changes: 2 additions & 2 deletions TFT/src/User/API/SerialConnection.c
Original file line number Diff line number Diff line change
@@ -25,10 +25,10 @@ const SERIAL_PORT_INFO serialPort[SERIAL_PORT_COUNT] = {
};

const uint32_t baudrateValues[BAUDRATE_COUNT] = {
0, 2400, 9600, 19200, 38400, 57600, 115200, 230400, 250000, 500000, 921600, 1000000};
0, 2400, 9600, 19200, 38400, 57600, 115200, 230400, 250000, 500000, 921600, 1000000, 1958400, 2000000};

const char * const baudrateNames[BAUDRATE_COUNT] = {
"OFF", "2400", "9600", "19200", "38400", "57600", "115200", "230400", "250000", "500000", "921600", "1000000"};
"OFF", "2400", "9600", "19200", "38400", "57600", "115200", "230400", "250K", "500K", "921600", "1M", "1958400", "2M"};

void Serial_Init(SERIAL_PORT_INDEX portIndex)
{
2 changes: 1 addition & 1 deletion TFT/src/User/API/SerialConnection.h
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ extern "C" {
#include "variants.h" // for SERIAL_PORT_2 etc.
#include "Serial.h" // for dmaL1DataTX etc.

#define BAUDRATE_COUNT 12
#define BAUDRATE_COUNT 14

typedef enum
{
6 changes: 3 additions & 3 deletions TFT/src/User/API/SpeedControl.c
Original file line number Diff line number Diff line change
@@ -36,12 +36,12 @@ uint16_t speedGetCurPercent(const uint8_t tool)

void loopCheckSpeed(void)
{
static uint32_t nextUpdateTime = 0;
static uint32_t lastUpdateTime = 0;

if (OS_GetTimeMs() < nextUpdateTime) // avoid rapid fire, clogging the queue
if ((OS_GetTimeMs() - lastUpdateTime) < SPEED_REFRESH_TIME) // avoid rapid fire, clogging the queue
return;

nextUpdateTime = OS_GetTimeMs() + SPEED_REFRESH_TIME; // extend next check time
lastUpdateTime = OS_GetTimeMs(); // extend next check time

for (uint8_t i = 0; i < SPEED_NUM; i++)
{
13 changes: 7 additions & 6 deletions TFT/src/User/API/Temperature.c
Original file line number Diff line number Diff line change
@@ -216,10 +216,10 @@ void heatSyncUpdateSeconds(const uint8_t seconds)

void heatSetNextUpdateTime(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if no more used, remove it (heat_next_update_time should also be renamed to heat_last_update_time) and use directly OS_GetTimeMs() insstead of calling this function

{
heat_next_update_time = OS_GetTimeMs() + SEC_TO_MS(heat_update_seconds);
heat_next_update_time = OS_GetTimeMs();

if (infoMachineSettings.autoReportTemp)
heat_next_update_time += AUTOREPORT_TIMEOUT;
// if (infoMachineSettings.autoReportTemp)
// heat_next_update_time += AUTOREPORT_TIMEOUT;
}

void heatClearSendingWaiting(void)
@@ -234,10 +234,11 @@ void loopCheckHeater(void)
// feature to automatically report the temperatures or (if M155 is supported) check temperature auto-report timeout
// and resend M155 command in case of timeout expired

if (OS_GetTimeMs() < heat_next_update_time) // if next check time not yet elapsed, do nothing
break;
if ((OS_GetTimeMs() - heat_next_update_time) < (SEC_TO_MS(heat_update_seconds) + (infoMachineSettings.autoReportTemp ? AUTOREPORT_TIMEOUT : 0))) // if next check time not yet elapsed, do nothing
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong indentation?


heatSetNextUpdateTime(); // extend next check time
// heatSetNextUpdateTime(); // extend next check time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not more used, remove it

heat_next_update_time = OS_GetTimeMs();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you did for other, rename heat_nect_update_time to heat_last_update_time


// if M105/M155 previously enqueued and not yet sent or pending command
// (to avoid collision in gcode response processing), do nothing
1 change: 0 additions & 1 deletion TFT/src/User/API/Touch_Encoder.c
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ bool Touch_Enc_ReadPen(uint16_t duration)
if (XPT2046_Read_Pen()) // if touch screen not pressed
{
lastTime = OS_GetTimeMs();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not remove the empty line before any return statement

return false;
}

19 changes: 11 additions & 8 deletions TFT/src/User/API/Touch_Screen.c
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ uint16_t TS_KeyValue(uint8_t totalRect, const GUI_RECT * menuRect)

for (i = 0; i < totalRect; i++)
{
if ((x > menuRect[i].x0) && (x < menuRect[i].x1) && (y > menuRect[i].y0) && (y < menuRect[i].y1))
if ((x >= menuRect[i].x0) && (x <= menuRect[i].x1) && (y >= menuRect[i].y0) && (y <= menuRect[i].y1))
{
#ifdef BUZZER_PIN
if (TS_Sound == true)
@@ -106,21 +106,21 @@ uint16_t KEY_GetValue(uint8_t totalRect, const GUI_RECT * menuRect)
{
if (firstPress)
{
key_num = TS_KeyValue(totalRect, menuRect);
key_num = TS_KeyValue(totalRect, menuRect); // store the pressed key number
firstPress = false;

if (TS_ReDrawIcon)
TS_ReDrawIcon(key_num, 1);
}
}
else
else // not pressed
{
if (firstPress == false)
if (!firstPress) // not pressed anymore
{
if (TS_ReDrawIcon)
TS_ReDrawIcon(key_num, 0);

key_return = key_num;
key_return = key_num; // return stored key number
key_num = IDLE_TOUCH;
firstPress = true;

@@ -163,6 +163,7 @@ static inline uint8_t TS_CalibrationEnsure(uint16_t x, uint16_t y)

if (lcd_x < x + TS_ERR_RANGE && lcd_x > x - TS_ERR_RANGE && lcd_y > y - TS_ERR_RANGE && lcd_y < y + TS_ERR_RANGE)
{
Buzzer_AddSound(BUZZER_FREQUENCY_HZ, BUZZER_FREQUENCY_DURATION_MS);
GUI_DispStringCenter(LCD_WIDTH / 2, LCD_HEIGHT - 40, (int32_t)LABEL_ADJUST_OK);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line before this GUI call

Delay_ms(1000);
}
@@ -174,6 +175,7 @@ static inline uint8_t TS_CalibrationEnsure(uint16_t x, uint16_t y)
GUI_DispStringCenter(LCD_WIDTH / 2, LCD_HEIGHT - 40, (int32_t)LABEL_ADJUST_FAILED);
GUI_DispDec(0, 0, lcd_x, 3, 0);
GUI_DispDec(0, 20, lcd_y, 3, 0);
Buzzer_AddSound(100, 200);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move the buzzer call before the first GUI call and add an empty line before the first GUI call (separate GUI call from non GUI calls, when possible)

Delay_ms(1000);

return 0;
@@ -211,12 +213,13 @@ void TS_Calibrate(void)
GUI_DrawPoint(LCD_X[tp_num], LCD_Y[tp_num] - i);
}

while (TS_IsPressed() == false);

while (!TS_IsPressed());
Buzzer_AddSound(BUZZER_FREQUENCY_HZ, BUZZER_FREQUENCY_DURATION_MS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line before this buzzer call. while, if, switch etc. must be always separated by empty line


TP_X[tp_num] = XPT2046_Repeated_Compare_AD(CMD_RDX);
TP_Y[tp_num] = XPT2046_Repeated_Compare_AD(CMD_RDY);

while (TS_IsPressed() != false);
while (TS_IsPressed());
}

K = (X1 - X3) * (Y2 - Y3) - (X2 - X3) * (Y1 - Y3);
2 changes: 1 addition & 1 deletion TFT/src/User/API/UI/ListManager.c
Original file line number Diff line number Diff line change
@@ -156,7 +156,7 @@ uint8_t listViewGetCurPage(void)

uint16_t listViewGetSelectedIndex(void)
{
KEY_VALUES key_num = menuKeyGetValue();
KEY_VALUES key_num = menuKeyGetValue(false);

if (key_num < LISTITEM_PER_PAGE)
{
4 changes: 2 additions & 2 deletions TFT/src/User/API/UI/Numpad.c
Original file line number Diff line number Diff line change
@@ -236,7 +236,7 @@ double numPadFloat(uint8_t * title, double param_val, double reset_val, bool neg

while (TS_Sound == false) // TS_TouchSound gets true only when exit from numpad is requested
{
key_num = menuKeyGetValue();
key_num = menuKeyGetValue(false);

switch (key_num)
{
@@ -421,7 +421,7 @@ int32_t numPadInt(uint8_t * title, int32_t param_val, int32_t reset_val, bool ne

while (TS_Sound == false) // TS_TouchSound gets true only when exit from numpad is requested
{
key_num = menuKeyGetValue();
key_num = menuKeyGetValue(false);

switch (key_num)
{
Loading