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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
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
Expand Up @@ -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
Expand Down
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
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions TFT/src/User/API/AddonHardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
}

Expand Down
6 changes: 3 additions & 3 deletions TFT/src/User/API/FanControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/HW_Init.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void HW_Init(void)
LCD_Enc_InitActiveSignal();
#endif

if (readIsTSCExist() == false) // read settings parameter
if (!readIsTSCExist()) // read settings parameter
{
LCD_RefreshDirection(infoSettings.rotated_ui);
TS_Calibrate();
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/Language/utf8_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ uint16_t GUI_StrPixelWidth_label(int16_t index)
{
uint8_t tempstr[MAX_LANG_LABEL_LENGTH];

if (loadLabelText((uint8_t *)tempstr, index) == false)
if (!loadLabelText((uint8_t *)tempstr, index))
return 0;

return GUI_StrPixelWidth_str(tempstr);
Expand Down
4 changes: 2 additions & 2 deletions TFT/src/User/API/LevelingControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void levelingMoveToPoint(LEVELING_POINT point)

levelingGetPointCoords(coords);

if (coordinateIsKnown() == false)
if (!coordinateIsKnown())
storeCmd("G28\n");

storeCmd("G0 Z%.3f F%d\n", infoSettings.level_z_raise, infoSettings.level_feedrate[FEEDRATE_Z]);
Expand All @@ -86,7 +86,7 @@ void levelingProbePoint(LEVELING_POINT point)

levelingGetPointCoords(coords);

if (coordinateIsKnown() == false)
if (!coordinateIsKnown())
probeHeightHomeAndRaise(); // home and raise nozzle

if (infoSettings.touchmi_sensor != 0)
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/Mainboard_AckHandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void parseAck(void)
// TFT to printer connection handling
//----------------------------------------

if (infoHost.connected == false)
if (!infoHost.connected)
{
// parse error information even though not connected to printer
if (ack_seen(magic_error))
Expand Down
12 changes: 6 additions & 6 deletions TFT/src/User/API/Mainboard_CmdHandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ static bool openRemoteTFT(bool writingMode)
if (!writingMode) // if reading mode
{
// mount FS and open the file (infoFile.source and infoFile.path are used)
if (mountFS() == true && f_open(&file, infoFile.path, FA_OPEN_EXISTING | FA_READ) == FR_OK)
if (mountFS() && f_open(&file, infoFile.path, FA_OPEN_EXISTING | FA_READ) == FR_OK)
{
char buf[10];

Expand All @@ -436,7 +436,7 @@ static bool openRemoteTFT(bool writingMode)
else // if writing mode
{
// mount FS and open the file (infoFile.source and infoFile.path are used)
if (mountFS() == true && f_open(&file, infoFile.path, FA_OPEN_ALWAYS | FA_WRITE) == FR_OK)
if (mountFS() && f_open(&file, infoFile.path, FA_OPEN_ALWAYS | FA_WRITE) == FR_OK)
{
Serial_Forward(cmd_port_index, "Writing to file: ");
Serial_Forward(cmd_port_index, infoFile.path);
Expand Down Expand Up @@ -700,7 +700,7 @@ void sendQueueCmd(void)
Serial_Forward(cmd_port_index, "Begin file list\n");

// then mount FS and scan for files (infoFile.source and infoFile.path are used)
if (mountFS() == true && scanPrintFiles() == true)
if (mountFS() && scanPrintFiles())
{
for (uint16_t i = 0; i < infoFile.fileCount; i++)
{
Expand Down Expand Up @@ -857,7 +857,7 @@ void sendQueueCmd(void)
if (initRemoteTFT()) // examples: "M30 SD:/test/cap2.gcode\n", "M30 S /test/cap2.gcode\n"
{
// then mount FS and delete the file (infoFile.source and infoFile.path are used)
if (mountFS() == true && f_unlink(infoFile.path) == FR_OK)
if (mountFS() && f_unlink(infoFile.path) == FR_OK)
Serial_Forward(cmd_port_index, "File deleted: ");
else
Serial_Forward(cmd_port_index, "Deletion failed, File: ");
Expand Down Expand Up @@ -912,7 +912,7 @@ void sendQueueCmd(void)
msgText = parseM118(rawMsg, &hasE, &hasA);

// format: <E prefix> + <A prefix> + <text> + "\n"
snprintf(msg, CMD_MAX_SIZE, "%s%s%s\n", (hasE == true) ? "echo:" : "", (hasA == true) ? "//" : "", msgText);
snprintf(msg, CMD_MAX_SIZE, "%s%s%s\n", hasE ? "echo:" : "", hasA ? "//" : "", msgText);

int32_t fwdPort = cmd_seen('P') ? cmd_value() : SUP_PORTS;

Expand Down Expand Up @@ -1570,7 +1570,7 @@ void sendQueueCmd(void)
// - if TFT is connected, update tx slots and tx count
// - if TFT is not connected, consider the command as an out of band message
//
if (sendCmd(false, avoid_terminal) == true && infoHost.connected == true)
if (sendCmd(false, avoid_terminal) && infoHost.connected)
{
// decrease the number of available tx slots and increase the pending commands tx count
//
Expand Down
22 changes: 11 additions & 11 deletions TFT/src/User/API/Mainboard_FlowControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions TFT/src/User/API/Notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static bool _toastRunning = false; // "true" when a toast notification is
static bool _toastAvailable = false; // "true" when a new toast is added. "false" when no more toasts to display are available
static uint8_t nextToastIndex = 0; // next index to store new toast
static uint8_t curToastDisplay = 0; // current toast notification being displayed
static uint32_t nextToastTime = 0; // time to change to next toast notification
static uint32_t lastToastTime = 0; // time to change to next toast notification

// message notification variables
static NOTIFICATION msglist[MAX_MSG_COUNT]; // message notification array
Expand All @@ -45,7 +45,7 @@ void drawToast(bool redraw)
if (!redraw)
curToastDisplay = (curToastDisplay + 1) % TOAST_MSG_COUNT;

if (toastlist[curToastDisplay].isNew == true || redraw)
if (toastlist[curToastDisplay].isNew || redraw)
{
// set toast notification running status
_toastRunning = true;
Expand Down Expand Up @@ -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
lastToastTime = OS_GetTimeMs();
}

GUI_SetTextMode(GUI_TEXTMODE_TRANS);
Expand Down Expand Up @@ -110,7 +110,7 @@ static inline bool toastAvailable(void)
{
for (int i = 0; i < TOAST_MSG_COUNT; i++)
{
if (toastlist[i].isNew == true)
if (toastlist[i].isNew)
return true;
}

Expand All @@ -121,14 +121,14 @@ 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 || ((OS_GetTimeMs() - lastToastTime) < SEC_TO_MS(TOAST_DURATION)) || getMenuType() == MENU_TYPE_FULLSCREEN)
return;

if (toastAvailable())
{
drawToast(false);
}
else if (_toastRunning == true)
else if (_toastRunning)
{
_toastRunning = false;
_toastAvailable = false;
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/PowerFailed.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ bool powerFailedInitRestore(void)
mustStoreCmd("G92 E%.5f\nG1 F%d\n", infoBreakPoint.axis[E_AXIS], infoBreakPoint.feedrate);
mustStoreCmd(infoBreakPoint.relative ? "G91\n" : "G90\n");

if (infoBreakPoint.relative_e == false)
if (!infoBreakPoint.relative_e)
mustStoreCmd("M82\n");
}

Expand Down
29 changes: 15 additions & 14 deletions TFT/src/User/API/Printing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -614,7 +614,7 @@ bool pausePrint(bool isPause, PAUSE_TYPE pauseType)
{
case FS_TFT_SD:
case FS_TFT_USB:
if (isPause == true && pauseType == PAUSE_M0)
if (isPause && pauseType == PAUSE_M0)
TASK_LOOP_WHILE(isNotEmptyCmdQueue()); // wait for the communication to be clean

static COORDINATE tmp;
Expand All @@ -632,8 +632,8 @@ bool pausePrint(bool isPause, PAUSE_TYPE pauseType)
{
coordinateGetAll(&tmp);

if (isCoorRelative == true) mustStoreCmd("G90\n");
if (isExtrudeRelative == true) mustStoreCmd("M82\n");
if (isCoorRelative) mustStoreCmd("G90\n");
if (isExtrudeRelative) mustStoreCmd("M82\n");

if (heatGetCurrentTemp(heatGetCurrentHotend()) > infoSettings.min_ext_temp)
{
Expand All @@ -648,8 +648,8 @@ bool pausePrint(bool isPause, PAUSE_TYPE pauseType)
infoSettings.pause_feedrate[FEEDRATE_XY]);
}

if (isCoorRelative == true) mustStoreCmd("G91\n");
if (isExtrudeRelative == true) mustStoreCmd("M83\n");
if (isCoorRelative) mustStoreCmd("G91\n");
if (isExtrudeRelative) mustStoreCmd("M83\n");
}

// store pause type only on pause
Expand All @@ -663,10 +663,10 @@ bool pausePrint(bool isPause, PAUSE_TYPE pauseType)
}
else if (pauseType == PAUSE_NORMAL) // send command only for pause originated from TFT
{
if (isCoorRelative == true) mustStoreCmd("G90\n");
if (isExtrudeRelative == true) mustStoreCmd("M82\n");
if (isCoorRelative) mustStoreCmd("G90\n");
if (isExtrudeRelative) mustStoreCmd("M82\n");

if (extrusionDuringPause == true) // check if extrusion done during Print -> Pause
if (extrusionDuringPause) // check if extrusion done during Print -> Pause
{ // no purge
extrusionDuringPause = false;
}
Expand All @@ -685,8 +685,8 @@ bool pausePrint(bool isPause, PAUSE_TYPE pauseType)
mustStoreCmd("G92 E%.5f\n", tmp.axis[E_AXIS]);
mustStoreCmd("G1 F%d\n", tmp.feedrate);

if (isCoorRelative == true) mustStoreCmd("G91\n");
if (isExtrudeRelative == true) mustStoreCmd("M83\n");
if (isCoorRelative) mustStoreCmd("G91\n");
if (isExtrudeRelative) mustStoreCmd("M83\n");
}
}
break;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/Printing.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern "C" {

#ifdef RAPID_SERIAL_COMM
#define RAPID_SERIAL_LOOP() loopBackEnd()
#define RAPID_PRINTING_COMM() if (isPrinting() == true && infoSettings.serial_always_on != 1) {loopBackEnd();}
#define RAPID_PRINTING_COMM() if (isPrinting() && infoSettings.serial_always_on != 1) {loopBackEnd();}
#else
#define RAPID_SERIAL_LOOP()
#define RAPID_PRINTING_COMM()
Expand Down
Loading