Skip to content

Commit

Permalink
Added Marlin ADVANCED_OK + static ADVANCED_OK support (#2824)
Browse files Browse the repository at this point in the history
* Added ADVANCED_OK support + #2761 bugfix
* added tx_slots parameter on config.ini file
  • Loading branch information
digant73 authored Sep 26, 2023
1 parent cd69550 commit 38d7efe
Show file tree
Hide file tree
Showing 72 changed files with 627 additions and 163 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ the following options must be enabled in Marlin firmware.
`SET_PROGRESS_MANUALLY` (in Configuration_adv.h)<br>
`M73_REPORT` (in Configuration_adv.h)<br>

**Options to support ADVANCED_OK with host:**

`ADVANCED_OK` (in Configuration_adv.h)<br>

**Options to support M600 with host & (Un)Load menu:**

`Options to support dialog with host` (as pre requisite)<br>
Expand Down
47 changes: 22 additions & 25 deletions TFT/src/User/API/AddonHardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum
FILAMENT_SENSOR_SMART,
};

static uint32_t nextUpdateTime = FIL_ALARM_REMINDER_TIME; // Give TFT time to connect to mainboard first before polling for runout
static bool posE_updateWaiting = false;
static bool sfs_alive = false; // Use an encoder disc to toggles the runout. Suitable for BigTreeTech Smart Filament Sensor

Expand Down Expand Up @@ -72,6 +73,11 @@ void FIL_Runout_Init(void)
#endif
}

static inline void FIL_SetNextUpdateTime(uint32_t timeInterval)
{
nextUpdateTime = OS_GetTimeMs() + timeInterval;
}

// Set whether we need to query the current position
void FIL_PosE_SetUpdateWaiting(bool waiting)
{
Expand All @@ -87,13 +93,12 @@ bool FIL_NormalRunoutDetect(void)
{
static bool runout = false;
static int32_t trigBalance = 0;
static uint32_t nextRunoutTime = 0;

if (OS_GetTimeMs() > nextRunoutTime)
if (OS_GetTimeMs() > nextUpdateTime)
{
runout = (trigBalance > 0);
trigBalance = 0;
nextRunoutTime = OS_GetTimeMs() + infoSettings.runout_noise;
FIL_SetNextUpdateTime(infoSettings.runout_noise);
}
else
{
Expand Down Expand Up @@ -146,30 +151,30 @@ bool FIL_SmartRunoutDetect(void)
{
static float lastPosE = 0.0f;
static bool lastRunout = false;
static uint32_t nextUpdateTime = 0;

float posE = coordinateGetExtruderActual();
bool runout = FIL_NormalRunoutDetect();

do
{ // Send M114 E to query extrude position continuously
{
// Send M114 E to query extrude position continuously
if (posE_updateWaiting == true)
{
nextUpdateTime = OS_GetTimeMs() + FIL_POS_E_UPDATE_TIME;
FIL_SetNextUpdateTime(FIL_POS_E_UPDATE_TIME);
break;
}

if (OS_GetTimeMs() < nextUpdateTime)
break;

if (requestCommandInfoIsRunning()) // To avoid colision in gcode response processing
if (requestCommandInfoIsRunning()) // To avoid collision in gcode response processing
break;

if (storeCmd("M114 E\n") == false)
if (!storeCmd("M114 E\n"))
break;

FIL_SetNextUpdateTime(FIL_POS_E_UPDATE_TIME);
posE_updateWaiting = true;
nextUpdateTime = OS_GetTimeMs() + FIL_POS_E_UPDATE_TIME;
} while (0);

if (sfs_alive == false)
Expand Down Expand Up @@ -200,30 +205,22 @@ bool FIL_SmartRunoutDetect(void)

bool FIL_IsRunout(void)
{
if (GET_BIT(infoSettings.runout, RUNOUT_ENABLED))
switch (GET_BIT(infoSettings.runout, RUNOUT_SENSOR_TYPE))
{
// Get sensor type
uint8_t sensorType = GET_BIT(infoSettings.runout, RUNOUT_SENSOR_TYPE);

switch (sensorType)
{
case FILAMENT_SENSOR_NORMAL:
return FIL_NormalRunoutDetect();
case FILAMENT_SENSOR_NORMAL:
return FIL_NormalRunoutDetect();

case FILAMENT_SENSOR_SMART:
return FIL_SmartRunoutDetect();
case FILAMENT_SENSOR_SMART:
return FIL_SmartRunoutDetect();

default:
return false;
}
default:
return false;
}

return false;
}

void FIL_BE_CheckRunout(void)
{
if (!(GET_BIT(infoSettings.runout, 0))) // Filament runout turn off
if (!GET_BIT(infoSettings.runout, RUNOUT_ENABLED)) // Filament runout turned off
return;

setPrintRunout(FIL_IsRunout()); // Need constant scanning to filter interference
Expand Down
4 changes: 2 additions & 2 deletions TFT/src/User/API/FanControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ void ctrlFanQuerySetWait(const bool wait)

// query for controller fan only
void ctrlFanQuery(void)
{
if (infoHost.connected && !infoHost.wait && !ctrlFanQueryWait && infoSettings.ctrl_fan_en)
{ // following conditions ordered by importance
if (!ctrlFanQueryWait && infoHost.tx_slots != 0 && infoHost.connected && infoSettings.ctrl_fan_en)
{
ctrlFanQueryWait = storeCmd("M710\n");
}
Expand Down
40 changes: 40 additions & 0 deletions TFT/src/User/API/Gcode/gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,46 @@ static void resetRequestCommandInfo(
requestCommandInfo.inError = false;
}

void detectAdvancedOk(void)
{
uint8_t advanced_ok = GET_BIT(infoSettings.general_settings, INDEX_ADVANCED_OK); // backup the configured ADVANCED_OK setting
uint8_t cmd_index = 0;

// temporary disable the ADVANCED_OK feature (if enabled) just to allow the TFT to send only one gcode
// per time and the mainboard to reply with an ADVANCED_OK response with the maximum available buffers
SET_BIT_OFF(infoSettings.general_settings, INDEX_ADVANCED_OK);

TASK_LOOP_WHILE(isPendingCmd() && isNotEmptyCmdQueue()); // wait for the communication to be clean

resetRequestCommandInfo("ok", // The magic to identify the start
"ok", // The magic to identify the stop
NULL, // The first magic to identify the error response
NULL, // The second error magic
NULL); // The third error magic

// send any gcode replied by the mainboard with a regular OK response ("ok\n") or an ADVANCED_OK response (e.g. "ok N10 P15 B3\n")
mustStoreCmd("M220\n");

// Wait for response
loopProcessToCondition(&isWaitingResponse);

while (requestCommandInfo.cmd_rev_buf[cmd_index] != '\0')
{
if (requestCommandInfo.cmd_rev_buf[cmd_index++] == 'B')
{
if (strtol(&requestCommandInfo.cmd_rev_buf[cmd_index], NULL, 10) != 0) // if different than 0
{
// set infoHost.target_tx_slots and infoSettings.tx_slots to the value detected by TFT
infoHost.target_tx_slots = infoSettings.tx_slots = strtol(&requestCommandInfo.cmd_rev_buf[cmd_index], NULL, 10);
}
}
}

clearRequestCommandInfo();

SET_BIT_VALUE(infoSettings.general_settings, INDEX_ADVANCED_OK, advanced_ok); // restore the configured ADVANCED_OK setting
}

/**
* Send M21 command and wait for response
*
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ bool isWaitingResponse(void); // condition callback for loopProcessToCondition(
bool requestCommandInfoIsRunning(void);
void clearRequestCommandInfo(void);

void detectAdvancedOk(void);
bool request_M21(void);
char * request_M20(void);
char * request_M33(const char * filename);
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/Language.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// config.ini Parameter Settings - Screen Settings and Feature Settings
X_WORD (LANGUAGE)
X_WORD (ADVANCED_OK)
X_WORD (EMULATED_M600)
X_WORD (EMULATED_M109_M190)
X_WORD (EVENT_LED)
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_am.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Հայերեն"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulated M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_br.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Português BRASIL"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "M600 emulado"
#define STRING_EMULATED_M109_M190 "M109 / M190 emulado"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_ca.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Català"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulated M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_cn.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "简体中文"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "模拟M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_cz.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Čeština"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulace M600"
#define STRING_EMULATED_M109_M190 "Emulace M109 / M190"
#define STRING_EVENT_LED "LED události"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_de.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Deutsch"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emuliere M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "English"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulated M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_es.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Español"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulated M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_fr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Français"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emuler M600"
#define STRING_EMULATED_M109_M190 "Emuler M109 / M190"
#define STRING_EVENT_LED "LED Neopixel"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_gr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Ελληνικά"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulated M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_hr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Hrvatski"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emuliraj M600"
#define STRING_EMULATED_M109_M190 "Emuliraj M109 / M190"
#define STRING_EVENT_LED "LED event"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_hu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Magyar"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulált M600"
#define STRING_EMULATED_M109_M190 "Emulált M109 / M190"
#define STRING_EVENT_LED "Esemény LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Italiano"
#define STRING_ADVANCED_OK "OK avanzato"
#define STRING_EMULATED_M600 "M600 emulato"
#define STRING_EMULATED_M109_M190 "M109 / M190 emulati"
#define STRING_EVENT_LED "LED evento"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_jp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "日本語"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulated M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_keywords.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern "C" {

// config.ini Parameter Settings - Screen Settings and Feature Settings
#define LANG_KEY_LANGUAGE "label_language:"
#define LANG_KEY_ADVANCED_OK "label_advanced_ok:"
#define LANG_KEY_EMULATED_M600 "label_emulated_m600:"
#define LANG_KEY_EMULATED_M109_M190 "label_emulated_m109_m190:"
#define LANG_KEY_EVENT_LED "label_event_led:"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_nl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Dutch"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulated M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_pl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Polski"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulowane M600"
#define STRING_EMULATED_M109_M190 "Emulowane M109 / M190"
#define STRING_EVENT_LED "Sygn. zdarzenia diodą LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_pt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Portugues"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulated M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_ru.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Русский"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Эмуляция M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_sk.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Slovensky"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulated M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_sl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Slovenski"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulated M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_tc.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "正體中文"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulated M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_tr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Türkçe"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulated M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/API/Language/language_uk.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// config.ini Parameter Settings - Screen Settings and Feature Settings
#define STRING_LANGUAGE "Українська"
#define STRING_ADVANCED_OK "Advanced OK"
#define STRING_EMULATED_M600 "Emulated M600"
#define STRING_EMULATED_M109_M190 "Emulated M109 / M190"
#define STRING_EVENT_LED "Event LED"
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/ModeSwitching.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void Mode_Switch(void)
LOGO_ReadDisplay();
updateNextHeatCheckTime(); // send "M105" after a delay, because of mega2560 will be hanged when received data at startup

TASK_LOOP_WHILE(OS_GetTimeMs() - startUpTime < BTT_BOOTSCREEN_TIME) // display logo BTT_BOOTSCREEN_TIME ms
TASK_LOOP_WHILE(OS_GetTimeMs() - startUpTime < BTT_BOOTSCREEN_TIME); // display logo BTT_BOOTSCREEN_TIME ms

heatSetUpdateSeconds(TEMPERATURE_QUERY_SLOW_SECONDS);
modeFreshBoot = false;
Expand Down
Loading

0 comments on commit 38d7efe

Please sign in to comment.