Implement CRC16, develop mesh allocation table

- Add crc16 utility function
 - Implement CRC16 for config store, remove old checksum, increment layout version
 - Move UBL mesh store/load to MarlinSettings; increment UBL_VERSION
 - Begin to lay out MAT structure, prototype functions, etc.
 - Rename ubl.state.eeprom_storage_slot to .storage_slot
 - Misc. optimization
 - Cleanup/standardize/improve some messages

This is a work in progress!
This commit is contained in:
Brian
2017-05-06 21:00:56 -04:00
committed by Scott Lahteine
parent 00d358d92d
commit 7852369987
8 changed files with 299 additions and 194 deletions

View File

@ -63,9 +63,6 @@
bool unified_bed_leveling::g26_debug_flag = false,
unified_bed_leveling::has_control_of_lcd_panel = false;
int16_t unified_bed_leveling::eeprom_start = -1; // Please stop changing this to 8 bits in size
// It needs to hold values bigger than this.
volatile int unified_bed_leveling::encoder_diff;
unified_bed_leveling::unified_bed_leveling() {
@ -73,53 +70,10 @@
reset();
}
void unified_bed_leveling::load_mesh(const int16_t slot) {
int16_t j = (UBL_LAST_EEPROM_INDEX - eeprom_start) / sizeof(z_values);
if (slot == -1) {
SERIAL_PROTOCOLLNPGM("?No mesh saved in EEPROM. Zeroing mesh in memory.\n");
reset();
return;
}
if (!WITHIN(slot, 0, j - 1) || eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
return;
}
j = UBL_LAST_EEPROM_INDEX - (slot + 1) * sizeof(z_values);
eeprom_read_block((void *)&z_values, (void *)j, sizeof(z_values));
SERIAL_PROTOCOLPAIR("Mesh loaded from slot ", slot);
SERIAL_PROTOCOLLNPAIR(" at offset ", hex_address((void*)j));
}
void unified_bed_leveling::store_mesh(const int16_t slot) {
int16_t j = (UBL_LAST_EEPROM_INDEX - eeprom_start) / sizeof(z_values);
if (!WITHIN(slot, 0, j - 1) || eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
SERIAL_PROTOCOL(slot);
SERIAL_PROTOCOLLNPGM(" mesh slots available.\n");
SERIAL_PROTOCOLLNPAIR("E2END : ", E2END);
SERIAL_PROTOCOLLNPAIR("k : ", (int)UBL_LAST_EEPROM_INDEX);
SERIAL_PROTOCOLLNPAIR("j : ", j);
SERIAL_PROTOCOLLNPAIR("m : ", slot);
SERIAL_EOL;
return;
}
j = UBL_LAST_EEPROM_INDEX - (slot + 1) * sizeof(z_values);
eeprom_write_block((const void *)&z_values, (void *)j, sizeof(z_values));
SERIAL_PROTOCOLPAIR("Mesh saved in slot ", slot);
SERIAL_PROTOCOLLNPAIR(" at offset ", hex_address((void*)j));
}
void unified_bed_leveling::reset() {
state.active = false;
state.z_offset = 0;
state.eeprom_storage_slot = -1;
state.storage_slot = -1;
ZERO(z_values);
@ -203,9 +157,9 @@
bool unified_bed_leveling::sanity_check() {
uint8_t error_flag = 0;
const int j = (UBL_LAST_EEPROM_INDEX - eeprom_start) / sizeof(z_values);
if (j < 1) {
SERIAL_PROTOCOLLNPGM("?No EEPROM storage available for a mesh of this size.\n");
const int a = settings.calc_num_meshes();
if (a < 1) {
SERIAL_PROTOCOLLNPGM("?Insufficient EEPROM storage for a mesh of this size.");
error_flag++;
}