Skip to content

Commit

Permalink
some cleanup after last PRs (bigtreetech#1360)
Browse files Browse the repository at this point in the history
  • Loading branch information
digant73 authored Dec 10, 2020
1 parent 858df63 commit 159d620
Show file tree
Hide file tree
Showing 34 changed files with 508 additions and 462 deletions.
Binary file removed BIGTREE_TFT35_V3.0_E3.26.x.bin
Binary file not shown.
File renamed without changes.
File renamed without changes.
18 changes: 10 additions & 8 deletions Copy to SD Card root directory to update/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,11 @@ long_filename_support:2
fan_speed_percent:1

#### Pause Settings
# Pause retract distance
# Pause XY position
# Pause Z raise
# Pause feed rate
# Actions applied when a print is paused, such as:
# Pause retract distance
# Pause XY position
# Pause Z raise
# Pause feed rate
#
# Format: [pause_retract: R<retract length> P<Resume Purge length>]
# [pause_pos: X<position in mm> Y<position in mm>]
Expand All @@ -394,10 +395,11 @@ pause_z_raise:10
pause_feedrate:X6000 Y6000 Z6000 E600

#### Manual Level Points Edge Distance
# Leveling edge distance
# Leveling Z position
# Leveling Z raise
# Leveling feed rate
# Settings used by Manual Leveling menu, such as:
# Leveling edge distance
# Leveling Z position
# Leveling Z raise
# Leveling feed rate
#
# Format: [level_edge_distance: <distance from edge in mm>]
# [level_z_pos: Z<position in mm>]
Expand Down
77 changes: 42 additions & 35 deletions TFT/src/User/API/FanControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ char* fanID[MAX_FAN_COUNT];
char* fanCmd[MAX_FAN_COUNT];
uint8_t fanType[MAX_FAN_COUNT];

static uint8_t desiredFanSpeed[MAX_FAN_COUNT] = {0}; // by Lori
static uint8_t newFanSpeed[MAX_FAN_COUNT] = {0}; // by Lori
static uint8_t curFanSpeed[MAX_FAN_COUNT] = {0}; // by Lori
static uint8_t desiredFanSpeed[MAX_FAN_COUNT] = {0};
static uint8_t newFanSpeed[MAX_FAN_COUNT] = {0};
static uint8_t curFanSpeed[MAX_FAN_COUNT] = {0};

static bool fan_send_waiting[MAX_FAN_COUNT] = {false};
static bool fanQueryWait = false;
static bool fanQueryEnable = false;

static uint32_t nextSendTime = 0;
#define nextSendWait 500 // 1 second is 1000
static uint32_t nextFanTime = 0;

uint8_t fanGetTypID(uint8_t startIndex, uint8_t type) {
for(uint8_t i = startIndex; i < MAX_FAN_COUNT; i++) {
if(fanType[i] == type) return i;
#define NEXT_FAN_WAIT 500 // 1 second is 1000

uint8_t fanGetTypID(uint8_t startIndex, uint8_t type)
{
for (uint8_t i = startIndex; i < MAX_FAN_COUNT; i++)
{
if (fanType[i] == type)
return i;
}
return FAN_TYPE_UNKNOWN;
}
Expand All @@ -28,40 +32,45 @@ void fanBuildList(void)
char* fanCmdTemp[MAX_FAN_COUNT] = FAN_CMD;
uint8_t fanTypeTemp[MAX_FAN_COUNT] = FAN_TYPE;

for (uint8_t i = 0, j=0; i < MAX_FAN_COUNT; i++,j++)
for (uint8_t i = 0, j = 0; i < MAX_FAN_COUNT; i++, j++)
{
if( infoSettings.fan_count == i ) {
if( infoSettings.fan_ctrl_count > 0 ) i= (MAX_FAN_COUNT - MAX_FAN_CTRL_COUNT);
else i= MAX_FAN_COUNT;
if (infoSettings.fan_count == i)
{
if (infoSettings.fan_ctrl_count > 0)
i = (MAX_FAN_COUNT - MAX_FAN_CTRL_COUNT);
else
i= MAX_FAN_COUNT;
}
if(i < MAX_FAN_COUNT) {
if (i < MAX_FAN_COUNT)
{
memcpy(fanID+j, fanIDTemp+i, sizeof(fanIDTemp[i]));
memcpy(fanCmd+j, fanCmdTemp+i, sizeof(fanCmdTemp[i]));
memcpy(fanType+j, fanTypeTemp+i, sizeof(fanTypeTemp[i]));
}
}
}

void fanControlInit(void) {
void fanControlInit(void)
{
fanBuildList();

fanQueryEnable =
( infoSettings.fan_ctrl_count > 0 &&
(fanGetTypID( infoSettings.fan_count -1,FAN_TYPE_CTRL_I ) ||
fanGetTypID( infoSettings.fan_count -1,FAN_TYPE_CTRL_S ) )
fanQueryEnable =
(infoSettings.fan_ctrl_count > 0 &&
(fanGetTypID(infoSettings.fan_count -1, FAN_TYPE_CTRL_I) ||
fanGetTypID(infoSettings.fan_count -1, FAN_TYPE_CTRL_S))
);
}

bool fanIsType(uint8_t i, uint8_t type) {
bool fanIsType(uint8_t i, uint8_t type)
{
return (fanType[i] == type);
}

void fanSetRcvSpeed(uint8_t i, uint8_t speed) // by Lori
void fanSetRcvSpeed(uint8_t i, uint8_t speed)
{
curFanSpeed[i] = newFanSpeed[i]= desiredFanSpeed[i] = speed; // avoid resend received values
curFanSpeed[i] = newFanSpeed[i] = desiredFanSpeed[i] = speed; // avoid resend received values
}


void fanSetDesiredSpeed(uint8_t i, uint8_t speed)
{
desiredFanSpeed[i] = speed;
Expand Down Expand Up @@ -124,33 +133,31 @@ void fanSpeedQuerySetWait(bool wait)
fanQueryWait = wait;
}


void loopFan(void)
{
for (uint8_t i = 0; i < (infoSettings.fan_count + infoSettings.fan_ctrl_count); i++)
{
if ((newFanSpeed[i] != desiredFanSpeed[i]) && (OS_GetTimeMs() > nextSendTime))
if ((newFanSpeed[i] != desiredFanSpeed[i]) && (OS_GetTimeMs() > nextFanTime))
{
if(fan_send_waiting[i] == false)
{
if(fanIsType(i,FAN_TYPE_F) || fanIsType(i,FAN_TYPE_CTRL_S)) {
fan_send_waiting[i] = storeCmd("%s S%d\n", fanCmd[i],desiredFanSpeed[i]);
}
else if (fanIsType(i,FAN_TYPE_CTRL_I)) {
fan_send_waiting[i] = storeCmd("%s I%d\n", fanCmd[i],desiredFanSpeed[i]);
}
if(fanIsType(i,FAN_TYPE_F) || fanIsType(i,FAN_TYPE_CTRL_S))
fan_send_waiting[i] = storeCmd("%s S%d\n", fanCmd[i], desiredFanSpeed[i]);
else if (fanIsType(i,FAN_TYPE_CTRL_I))
fan_send_waiting[i] = storeCmd("%s I%d\n", fanCmd[i], desiredFanSpeed[i]);
}
if (fan_send_waiting[i] == true) newFanSpeed[i] = desiredFanSpeed[i];
nextSendTime = OS_GetTimeMs() + nextSendWait; // avoid rapid fire, clogging the queue
if (fan_send_waiting[i] == true)
newFanSpeed[i] = desiredFanSpeed[i];
nextFanTime = OS_GetTimeMs() + NEXT_FAN_WAIT; // avoid rapid fire, clogging the queue
}
}
}

void fanSpeedQuery(void)
{
if( fanQueryEnable && infoHost.connected &&
!infoHost.wait && !fanQueryWait )
{
if (fanQueryEnable && infoHost.connected &&
!infoHost.wait && !fanQueryWait)
{
storeCmd("M710\n");
fanQueryWait = true;
}
Expand Down
10 changes: 5 additions & 5 deletions TFT/src/User/API/Printing.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ void abortPrinting(void)
{
case BOARD_SD:
infoHost.printing = false;
breakAndContinue(); //Several M108 is sent to Marlin because consecutive blocking oprations such as heat bed, heat extruder may defer processing of M524
breakAndContinue();
breakAndContinue();
breakAndContinue();
breakAndContinue(); //Several M108 is sent to Marlin because consecutive blocking oprations such as heat bed, heat extruder may defer processing of M524
breakAndContinue();
breakAndContinue();
breakAndContinue();
request_M524();
break;

Expand Down Expand Up @@ -419,7 +419,7 @@ void loopCheckPrinting(void)
if (!hasPrintingMenu())
infoMenu.menu[++infoMenu.cur] = menuPrinting;
}

if (!infoPrinting.printing && (infoMenu.menu[infoMenu.cur] == menuPrinting)) {
infoMenu.cur = 0;
}
Expand Down
24 changes: 14 additions & 10 deletions TFT/src/User/API/SpeedControl.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include "SpeedControl.h"
#include "includes.h"

static uint16_t percent[SPEED_NUM] = {100, 100}; //Speed Flow
static uint16_t lastPercent[SPEED_NUM] = {100, 100}; //Speed Flow
static uint16_t curPercent[SPEED_NUM] = {100, 100}; //Speed Flow
static uint16_t percent[SPEED_NUM] = {100, 100}; //Speed Flow
static uint16_t lastPercent[SPEED_NUM] = {100, 100}; //Speed Flow
static uint16_t curPercent[SPEED_NUM] = {100, 100}; //Speed Flow

static bool send_waiting[SPEED_NUM];
static bool queryWait = false;

static uint32_t nextSpeedTime = 0;
#define nextSpeedWait 500 // 1 second is 1000

#define NEXT_SPEED_WAIT 500 // 1 second is 1000

void speedSetSendWaiting(u8 tool, bool isWaiting)
{
Expand Down Expand Up @@ -53,18 +54,21 @@ bool SpeedChanged(u8 i)

void loopSpeed(void)
{
for(u8 i = 0; i < SPEED_NUM;i++)
if((curPercent[i] != percent[i]) && (OS_GetTimeMs() > nextSpeedTime))
for (u8 i = 0; i < SPEED_NUM;i++)
{
if ((curPercent[i] != percent[i]) && (OS_GetTimeMs() > nextSpeedTime))
{
if(send_waiting[i] == false)
if (send_waiting[i] == false)
{
send_waiting[i] = true;
const char *speedCmd[SPEED_NUM] = {"M220","M221"};
send_waiting[i] = storeCmd("%s S%d\n",speedCmd[i], percent[i]);
send_waiting[i] = storeCmd("%s S%d\n", speedCmd[i], percent[i]);
}
if (send_waiting[i] == true) curPercent[i] = percent[i];
nextSpeedTime = OS_GetTimeMs() + nextSpeedWait; // avoid rapid fire, clogging the queue
if (send_waiting[i] == true)
curPercent[i] = percent[i];
nextSpeedTime = OS_GetTimeMs() + NEXT_SPEED_WAIT; // avoid rapid fire, clogging the queue
}
}
}

void speedQuery(void)
Expand Down
67 changes: 43 additions & 24 deletions TFT/src/User/API/Temperature.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ bool heatGetIsWaiting(uint8_t index)
// Check all heater if there is a heater waiting to be waited
bool heatHasWaiting(void)
{
for(uint8_t i = 0; i < MAX_HEATER_COUNT; i++)
for (uint8_t i = 0; i < MAX_HEATER_COUNT; i++)
{
if(heater.T[i].waiting != WAIT_NONE)
if (heater.T[i].waiting != WAIT_NONE)
return true;
}
return false;
Expand All @@ -66,19 +66,19 @@ void heatSetIsWaiting(uint8_t tool, HEATER_WAIT isWaiting)
{
heater.T[tool].waiting = isWaiting;

if(isWaiting != WAIT_NONE) // wait heating now, query more frequently
if (isWaiting != WAIT_NONE) // wait heating now, query more frequently
{
heatSetUpdateSeconds(TEMPERATURE_QUERY_FAST_SECONDS);
}
else if(heatHasWaiting() == false)
else if (heatHasWaiting() == false)
{
heatSetUpdateSeconds(TEMPERATURE_QUERY_SLOW_SECONDS);
}
}

void heatClearIsWaiting(void)
{
for(uint8_t i = 0; i < MAX_HEATER_COUNT; i++)
for (uint8_t i = 0; i < MAX_HEATER_COUNT; i++)
{
heater.T[i].waiting = WAIT_NONE;
}
Expand All @@ -88,7 +88,8 @@ void heatClearIsWaiting(void)
// Set current Tool (Extruder)
void heatSetCurrentTool(uint8_t tool)
{
if(tool >= infoSettings.ext_count) return;
if (tool >= infoSettings.ext_count)
return;
heater.toolIndex = tool;
}

Expand All @@ -107,9 +108,12 @@ uint8_t heatGetCurrentHotend(void)
// Check whether the index is a valid heater index.
bool heaterIsValid(uint8_t index)
{
if (index >= infoSettings.hotend_count && index < MAX_HOTEND_COUNT) return false;
if (!infoSettings.bed_en && index == BED) return false;
if (!infoSettings.chamber_en && index == CHAMBER) return false;
if (index >= infoSettings.hotend_count && index < MAX_HOTEND_COUNT)
return false;
if (!infoSettings.bed_en && index == BED)
return false;
if (!infoSettings.chamber_en && index == CHAMBER)
return false;
return true;
}

Expand Down Expand Up @@ -166,31 +170,46 @@ void loopCheckHeater(void)
if (!infoMachineSettings.autoReportTemp) // TFT need not M105 to query the temperature, but uses M155 to automatically report if motherboard supports AUTO_REPORT_TEMPERATURESS feature
{
do
{ // Send M105 query temperature continuously
if (heat_update_waiting == true) {updateNextHeatCheckTime();break;}
if (OS_GetTimeMs() < nextHeatCheckTime) break;
if (requestCommandInfoIsRunning()) break; // To avoid colision in Gcode response processing
if (storeCmd("M105\n") == false) break;
{ // Send M105 query temperature continuously
if (heat_update_waiting == true)
{
updateNextHeatCheckTime();
break;
}
if (OS_GetTimeMs() < nextHeatCheckTime)
break;
if (requestCommandInfoIsRunning()) // To avoid colision in Gcode response processing
break;
if (storeCmd("M105\n") == false)
break;
updateNextHeatCheckTime();
heat_update_waiting = true;
}while(0);
}
while(0);
}

// Query the heater that needs to wait for the temperature to rise, whether it reaches the set temperature
for (uint8_t i=0; i< MAX_HEATER_COUNT; i++)
for (uint8_t i = 0; i < MAX_HEATER_COUNT; i++)
{
if (heater.T[i].waiting == WAIT_NONE) continue;
else if (heater.T[i].waiting == WAIT_HEATING) {
if (heater.T[i].current+2 <= heater.T[i].target) continue;
if (heater.T[i].waiting == WAIT_NONE)
continue;
else if (heater.T[i].waiting == WAIT_HEATING)
{
if (heater.T[i].current + 2 <= heater.T[i].target)
continue;
}
else if (heater.T[i].waiting == WAIT_COOLING_HEATING) {
if (inRange(heater.T[i].current, heater.T[i].target, 2) != true) continue;
else if (heater.T[i].waiting == WAIT_COOLING_HEATING)
{
if (inRange(heater.T[i].current, heater.T[i].target, 2) != true)
continue;
}

heater.T[i].waiting = WAIT_NONE;
if (heatHasWaiting()) continue;
if (heatHasWaiting())
continue;

if (infoMenu.menu[infoMenu.cur] == menuHeat) break;
if (infoMenu.menu[infoMenu.cur] == menuHeat)
break;
heatSetUpdateSeconds(TEMPERATURE_QUERY_SLOW_SECONDS);
}

Expand All @@ -202,7 +221,7 @@ void loopCheckHeater(void)
if (heat_send_waiting[i] != true)
{
heat_send_waiting[i] = true;
storeCmd("%s ",heatCmd[i]);
storeCmd("%s ", heatCmd[i]);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions TFT/src/User/API/coordinate.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ void coordinateSetKnown(bool known)

void coordinateSetAxisTarget(AXIS axis,float position)
{
bool r = (axis == E_AXIS)
? relative_e || relative_mode
: relative_mode;
bool r = (axis == E_AXIS) ? relative_e || relative_mode : relative_mode;

if(r==false)
{
Expand Down
Loading

0 comments on commit 159d620

Please sign in to comment.