Skip to content

Commit

Permalink
Merge pull request #4328 from dawidpieper/m850_addselection
Browse files Browse the repository at this point in the history
M850 add possibility to set sheet as active
  • Loading branch information
3d-gussner authored Sep 11, 2023
2 parents 7cdd175 + 14306e5 commit c84985e
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions Firmware/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7757,14 +7757,14 @@ SERIAL_PROTOCOLPGM("\n\n");

case 850: {
//! ### M850 - set sheet parameters
//! //!@n M850 - Set sheet data S[id] Z[offset] L[label] B[bed_temp] P[PINDA_TEMP]
bool bHasZ = false, bHasLabel = false, bHasBed = false, bHasPinda = false;
//! //!@n M850 - Set sheet data S[id] Z[offset] L[label] B[bed_temp] P[PINDA_TEMP] A[IS_ACTIVE]
uint8_t iSel = 0;
int16_t zraw = 0;
float z_val = 0;
char strLabel[8];
uint8_t iBedC = 0;
uint8_t iPindaC = 0;
bool bIsActive=false;
strLabel[7] = '\0'; // null terminate.
size_t max_sheets = sizeof(EEPROM_Sheets_base->s)/sizeof(EEPROM_Sheets_base->s[0]);

Expand All @@ -7780,6 +7780,7 @@ SERIAL_PROTOCOLPGM("\n\n");
} else {
break;
}

if (code_seen('Z')){
z_val = code_value();
zraw = z_val*cs.axis_steps_per_mm[Z_AXIS];
Expand All @@ -7788,7 +7789,7 @@ SERIAL_PROTOCOLPGM("\n\n");
SERIAL_PROTOCOLLNPGM(" Z VALUE OUT OF RANGE");
break;
}
bHasZ = true;
eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[iSel].z_offset)),zraw);
}
else
{
Expand All @@ -7798,13 +7799,13 @@ SERIAL_PROTOCOLPGM("\n\n");

if (code_seen('L'))
{
bHasLabel = true;
char *src = strchr_pointer + 1;
while (*src == ' ') ++src;
if (*src != '\0')
{
strncpy(strLabel,src,7);
}
eeprom_update_block(strLabel,EEPROM_Sheets_base->s[iSel].name,sizeof(Sheet::name));
}
else
{
Expand All @@ -7813,8 +7814,8 @@ SERIAL_PROTOCOLPGM("\n\n");

if (code_seen('B'))
{
bHasBed = true;
iBedC = code_value_uint8();
eeprom_update_byte(&EEPROM_Sheets_base->s[iSel].bed_temp, iBedC);
}
else
{
Expand All @@ -7823,35 +7824,29 @@ SERIAL_PROTOCOLPGM("\n\n");

if (code_seen('P'))
{
bHasPinda = true;
iPindaC = code_value_uint8();
eeprom_update_byte(&EEPROM_Sheets_base->s[iSel].pinda_temp, iPindaC);
}
else
{
iPindaC = eeprom_read_byte(&EEPROM_Sheets_base->s[iSel].pinda_temp);
}

if (code_seen('A'))
{
bIsActive |= code_value_uint8() || (eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)) == iSel);
if(bIsActive) eeprom_update_byte(&EEPROM_Sheets_base->active_sheet, iSel);
}
else
{
bIsActive = (eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)) == iSel);
}

SERIAL_PROTOCOLPGM("Sheet ");
SERIAL_PROTOCOL((int)iSel);
if (!eeprom_is_sheet_initialized(iSel))
SERIAL_PROTOCOLLNPGM(" NOT INITIALIZED");

if (bHasZ)
{
eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[iSel].z_offset)),zraw);
}
if (bHasLabel)
{
eeprom_update_block(strLabel,EEPROM_Sheets_base->s[iSel].name,sizeof(Sheet::name));
}
if (bHasBed)
{
eeprom_update_byte(&EEPROM_Sheets_base->s[iSel].bed_temp, iBedC);
}
if (bHasPinda)
{
eeprom_update_byte(&EEPROM_Sheets_base->s[iSel].pinda_temp, iPindaC);
}

SERIAL_PROTOCOLPGM(" Z");
SERIAL_PROTOCOL_F(z_val,4);
Expand All @@ -7863,7 +7858,8 @@ SERIAL_PROTOCOLPGM("\n\n");
SERIAL_PROTOCOL((int)iBedC);
SERIAL_PROTOCOLPGM(" P");
SERIAL_PROTOCOLLN((int)iPindaC);

SERIAL_PROTOCOLPGM(" A");
SERIAL_PROTOCOLLN((int)bIsActive);
break;
}

Expand Down

0 comments on commit c84985e

Please sign in to comment.