Skip to content

Commit

Permalink
Add coding standards, language pack size check during compiling, fix …
Browse files Browse the repository at this point in the history
…incorrect temperature for mixing hotend, reduce program memory usage (bigtreetech#1427)
  • Loading branch information
guruathwal authored Dec 25, 2020
1 parent a300ba6 commit 6f23161
Show file tree
Hide file tree
Showing 70 changed files with 2,826 additions and 2,436 deletions.
18 changes: 6 additions & 12 deletions TFT/src/User/API/BabystepControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@

static float babystep_value = BABYSTEP_DEFAULT_VALUE;

/* Reset only babystep value to default value */
// Reset only babystep value to default value
float babystepReset(void)
{
babystep_value = BABYSTEP_DEFAULT_VALUE;

return babystep_value;
}

/* Get current babystep value */
// Get current babystep value
float babystepGetValue(void)
{
return babystep_value;
}

/* Reset babystep value to default value */
// Reset babystep value to default value
float babystepResetValue(void)
{
if (babystep_value == BABYSTEP_DEFAULT_VALUE) // if already default value, nothing to do
if (babystep_value == BABYSTEP_DEFAULT_VALUE) // if already default value, nothing to do
return babystep_value;

int step_count;
Expand All @@ -35,15 +35,13 @@ float babystepResetValue(void)
for (; step_count > 0; step_count--)
{
mustStoreCmd("M290 Z%.2f\n", -(BABYSTEP_MAX_UNIT * neg));

processed_baby_step += BABYSTEP_MAX_UNIT;
}

last_unit = (babystep_value * neg) - processed_baby_step;
if (last_unit > 0.0f)
{
mustStoreCmd("M290 Z%.2f\n", -(last_unit * neg));

processed_baby_step += last_unit;
}

Expand All @@ -60,9 +58,7 @@ float babystepDecreaseValue(float unit)
float diff = babystep_value - BABYSTEP_MIN_VALUE;

unit = (diff > unit) ? unit : diff;

mustStoreCmd("M290 Z-%.2f\n", unit);

babystep_value -= unit;
}

Expand All @@ -77,9 +73,7 @@ float babystepIncreaseValue(float unit)
float diff = BABYSTEP_MAX_VALUE - babystep_value;

unit = (diff > unit) ? unit : diff;

mustStoreCmd("M290 Z%.2f\n", unit);

babystep_value += unit;
}

Expand All @@ -89,9 +83,9 @@ float babystepIncreaseValue(float unit)
// Update babystep value by encoder
float babystepUpdateValueByEncoder(float unit, int8_t direction)
{
float overall_unit = (direction > 0) ? (direction * unit) : (-direction * unit); // always positive unit
float overall_unit = (direction > 0) ? (direction * unit) : (-direction * unit); // always positive unit

if (direction < 0) // if negative encoder value, decrease the value. Otherwise increase the value
if (direction < 0) // if negative encoder value, decrease the value. Otherwise increase the value
babystepDecreaseValue(overall_unit);
else
babystepIncreaseValue(overall_unit);
Expand Down
16 changes: 7 additions & 9 deletions TFT/src/User/API/FanControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ void fanBuildList(void)
if (infoSettings.fan_ctrl_count > 0)
i = (MAX_FAN_COUNT - MAX_FAN_CTRL_COUNT);
else
i= MAX_FAN_COUNT;
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]));
memcpy(fanID + j, fanIDTemp + i, sizeof(fanIDTemp[i]));
memcpy(fanCmd + j, fanCmdTemp + i, sizeof(fanCmdTemp[i]));
memcpy(fanType + j, fanTypeTemp + i, sizeof(fanTypeTemp[i]));
}
}
}
Expand All @@ -53,11 +53,9 @@ 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)
Expand Down
20 changes: 9 additions & 11 deletions TFT/src/User/API/Gcode/gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ static void resetRequestCommandInfo(
requestCommandInfo.errorMagic[0] = string_error0;
requestCommandInfo.errorMagic[1] = string_error1;
requestCommandInfo.errorMagic[2] = string_error2;
if (string_error0) {
if (string_error0)
requestCommandInfo.error_num = 1;
}
if (string_error1) {
if (string_error1)
requestCommandInfo.error_num = 2;
}
if (string_error2) {
if (string_error2)
requestCommandInfo.error_num = 3;
}

while(infoCmd.count || infoHost.wait) {
while(infoCmd.count || infoHost.wait)
{
loopProcess(); // Wait for the communication to be clean before requestCommand
}

Expand Down Expand Up @@ -152,7 +150,8 @@ long request_M23(char *filename)
{
loopProcess();
}
if (requestCommandInfo.inError) {
if (requestCommandInfo.inError)
{
clearRequestCommandInfo();
return 0;
}
Expand All @@ -168,11 +167,10 @@ long request_M23(char *filename)
**/
bool request_M24(int pos)
{
if(pos == 0){
if(pos == 0)
mustStoreCmd("M24\n");
} else {
else
mustStoreCmd("M24 S%d\n", pos);
}
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion TFT/src/User/API/LCD_Encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ void loopCheckEncoderSteps(void)
#define encrot3 1

// Manage encoder rotation
#define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: encoderDiff += encoderDirection; break; case _E2: encoderDiff -= encoderDirection; }
#define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: encoderDiff += encoderDirection; break; \
case _E2: encoderDiff -= encoderDirection; }

if (buttons != lastEncoderBits)
{
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/Language/Language.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ uint32_t getLabelFlashAddr(uint16_t index);
bool loadLabelText(uint8_t * buf, uint16_t index);

//initialize and preload label text
#define labelChar(x, i) char x[MAX_LANG_LABEL_LENGTH]; loadLabelText((u8*)&x, i);
#define LABELCHAR(x, i) char x[MAX_LANG_LABEL_LENGTH]; loadLabelText((u8*)&x, i);

#ifdef __cplusplus
}
Expand Down
99 changes: 50 additions & 49 deletions TFT/src/User/API/MachineParameters.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,58 +68,59 @@ float getParameter(PARAMETER_NAME name, u8 index)
if(index >= parameter_element_count[name]) return 0.0f;
switch (name)
{
case P_STEPS_PER_MM:
return infoParameters.StepsPerMM[index];
case P_CURRENT:
return infoParameters.Current[index];
case P_MAX_FEED_RATE:
return infoParameters.MaxFeedRate[index];
case P_MAX_ACCELERATION:
return infoParameters.MaxAcceleration[index];
case P_ACCELERATION:
return infoParameters.Acceleration[index];
case P_JERK:
return infoParameters.Jerk[index];
case P_JUNCTION_DEVIATION:
return infoParameters.JunctionDeviation[index];
case P_PROBE_OFFSET:
return infoParameters.ProbeOffset[index];
case P_HOME_OFFSET:
return infoParameters.HomeOffset[index];
case P_BUMPSENSITIVITY:
return infoParameters.BumpSensitivity[index];
case P_FWRETRACT:
return infoParameters.FwRetract[index];
case P_FWRECOVER:
return infoParameters.FwRecover[index];
case P_AUTO_RETRACT:
return infoParameters.AutoRetract[index];
case P_LIN_ADV:
return infoParameters.LinAdvance[index];
case P_ABL_STATE:
return infoParameters.ABLState[index];
case P_OFFSET_TOOL:
return infoParameters.OffsetTool[index];
case P_HYBRID_THRESHOLD:
return infoParameters.HybridThreshold[index];
default:
return 0.0f;
case P_STEPS_PER_MM:
return infoParameters.StepsPerMM[index];
case P_CURRENT:
return infoParameters.Current[index];
case P_MAX_FEED_RATE:
return infoParameters.MaxFeedRate[index];
case P_MAX_ACCELERATION:
return infoParameters.MaxAcceleration[index];
case P_ACCELERATION:
return infoParameters.Acceleration[index];
case P_JERK:
return infoParameters.Jerk[index];
case P_JUNCTION_DEVIATION:
return infoParameters.JunctionDeviation[index];
case P_PROBE_OFFSET:
return infoParameters.ProbeOffset[index];
case P_HOME_OFFSET:
return infoParameters.HomeOffset[index];
case P_BUMPSENSITIVITY:
return infoParameters.BumpSensitivity[index];
case P_FWRETRACT:
return infoParameters.FwRetract[index];
case P_FWRECOVER:
return infoParameters.FwRecover[index];
case P_AUTO_RETRACT:
return infoParameters.AutoRetract[index];
case P_LIN_ADV:
return infoParameters.LinAdvance[index];
case P_ABL_STATE:
return infoParameters.ABLState[index];
case P_OFFSET_TOOL:
return infoParameters.OffsetTool[index];
case P_HYBRID_THRESHOLD:
return infoParameters.HybridThreshold[index];
default:
return 0.0f;
}
}

void setParameter(PARAMETER_NAME name, u8 index, float val)
{
if(index >= parameter_element_count[name]) return;
switch (name)
{
if (index >= parameter_element_count[name])
return;
switch (name)
{
case P_STEPS_PER_MM:
infoParameters.StepsPerMM[index] = val;
break;
case P_CURRENT:
infoParameters.Current[index] = val;
break;
case P_MAX_FEED_RATE:
infoParameters.MaxFeedRate[index] = val;
infoParameters.MaxFeedRate[index] = val;
break;
case P_MAX_ACCELERATION:
infoParameters.MaxAcceleration[index] = val;
Expand Down Expand Up @@ -165,7 +166,7 @@ void setParameter(PARAMETER_NAME name, u8 index, float val)
break;
default:
break;
}
}
}

u8 getParameterElementCount(PARAMETER_NAME para)
Expand All @@ -192,14 +193,14 @@ void sendParameterCmd(PARAMETER_NAME para, u8 stepper_index, float Value)
{
storeCmd(parameter_Cmd[para][stepper_index], Value);
if (dualstepper[stepper_index] && stepper_index < AXIS_NUM)
{
if(para == P_CURRENT)
storeCmd(dualStepperParameter_cmd[0][stepper_index], Value);
if(para == P_BUMPSENSITIVITY)
storeCmd(dualStepperParameter_cmd[1][stepper_index], Value);
if(para == P_HYBRID_THRESHOLD)
storeCmd(dualStepperParameter_cmd[2][stepper_index], Value);
}
{
if (para == P_CURRENT)
storeCmd(dualStepperParameter_cmd[0][stepper_index], Value);
if (para == P_BUMPSENSITIVITY)
storeCmd(dualStepperParameter_cmd[1][stepper_index], Value);
if (para == P_HYBRID_THRESHOLD)
storeCmd(dualStepperParameter_cmd[2][stepper_index], Value);
}
}

void saveEepromSettings(void)
Expand Down
Loading

0 comments on commit 6f23161

Please sign in to comment.