UBL Map Cleanup

This commit is contained in:
Tannoo 2017-06-21 14:26:59 -06:00 committed by Scott Lahteine
parent ada836db29
commit e90cbf5c16
3 changed files with 155 additions and 97 deletions

View File

@ -108,7 +108,6 @@ uint16_t max_display_update_time = 0;
extern bool powersupply_on;
#endif
////////////////////////////////////////////
///////////////// Menu Tree ////////////////
////////////////////////////////////////////
@ -2163,97 +2162,6 @@ void kill_screen(const char* lcd_msg) {
enqueue_and_echo_command(ubl_lcd_gcode);
}
#if ENABLED(DOGLCD)
/**
* UBL LCD "radar" map data
*/
#define MAP_UPPER_LEFT_CORNER_X 35 // These probably should be moved to the .h file But for now,
#define MAP_UPPER_LEFT_CORNER_Y 8 // it is easier to play with things having them here
#define MAP_MAX_PIXELS_X 53
#define MAP_MAX_PIXELS_Y 49
void _lcd_ubl_plot_drawing_prep() {
uint8_t i, j, x_offset, y_offset, x_map_pixels, y_map_pixels,
pixels_per_X_mesh_pnt, pixels_per_Y_mesh_pnt, inverted_y;
/*********************************************************/
/************ Scale the box pixels appropriately *********/
/*********************************************************/
x_map_pixels = ((MAP_MAX_PIXELS_X - 4) / (GRID_MAX_POINTS_X)) * (GRID_MAX_POINTS_X);
y_map_pixels = ((MAP_MAX_PIXELS_Y - 4) / (GRID_MAX_POINTS_Y)) * (GRID_MAX_POINTS_Y);
pixels_per_X_mesh_pnt = x_map_pixels / (GRID_MAX_POINTS_X);
pixels_per_Y_mesh_pnt = y_map_pixels / (GRID_MAX_POINTS_Y);
x_offset = MAP_UPPER_LEFT_CORNER_X + 1 + (MAP_MAX_PIXELS_X - x_map_pixels - 2) / 2;
y_offset = MAP_UPPER_LEFT_CORNER_Y + 1 + (MAP_MAX_PIXELS_Y - y_map_pixels - 2) / 2;
/*********************************************************/
/************ Clear the Mesh Map Box**********************/
/*********************************************************/
u8g.setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box
u8g.drawBox(x_offset - 2, y_offset - 2, x_map_pixels + 4, y_map_pixels + 4);
u8g.setColorIndex(0); // Now actually clear the mesh map box
u8g.drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels);
/*********************************************************/
/************ Display Mesh Point Locations ***************/
/*********************************************************/
u8g.setColorIndex(1);
for (i = 0; i < GRID_MAX_POINTS_X; i++) {
for (j = 0; j < GRID_MAX_POINTS_Y; j++) {
u8g.drawBox(x_offset + i * pixels_per_X_mesh_pnt + pixels_per_X_mesh_pnt / 2,
y_offset + j * pixels_per_Y_mesh_pnt + pixels_per_Y_mesh_pnt / 2, 1, 1);
}
}
/*********************************************************/
/************ Fill in the Specified Mesh Point ***********/
/*********************************************************/
inverted_y = GRID_MAX_POINTS_Y - y_plot - 1; // The origin is typically in the lower right corner. We need to
// invert the Y to get it to plot in the right location.
u8g.drawBox(x_offset + x_plot * pixels_per_X_mesh_pnt, y_offset + inverted_y * pixels_per_Y_mesh_pnt,
pixels_per_X_mesh_pnt, pixels_per_Y_mesh_pnt);
/*********************************************************/
/************** Put Relevent Text on Display *************/
/*********************************************************/
// Show X and Y positions at top of screen
u8g.setColorIndex(1);
u8g.setPrintPos(5, 7);
lcd_print("X:");
lcd_print(ftostr32(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
u8g.setPrintPos(74, 7);
lcd_print("Y:");
lcd_print(ftostr32(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
// Print plot position
u8g.setPrintPos(5, 64);
lcd_print('(');
u8g.print(x_plot);
lcd_print(',');
u8g.print(y_plot);
lcd_print(')');
// Show the location value
u8g.setPrintPos(74, 64);
lcd_print("Z:");
if (!isnan(ubl.z_values[x_plot][y_plot])) {
lcd_print(ftostr43sign(ubl.z_values[x_plot][y_plot]));
}
else {
lcd_print(" -----");
}
}
#endif // DOGLCD
/**
* UBL LCD Map Movement
*/
@ -2318,9 +2226,9 @@ void kill_screen(const char* lcd_msg) {
if (lcdDrawUpdate) {
#if ENABLED(DOGLCD)
_lcd_ubl_plot_drawing_prep();
_lcd_ubl_plot_DOGLCD(x_plot, y_plot);
#else
_lcd_ubl_output_char_lcd();
_lcd_ubl_plot_HD44780(x_plot, y_plot);
#endif
ubl_map_move_to_xy(); // Move to current location

View File

@ -939,6 +939,96 @@ static void lcd_implementation_status_screen() {
#endif // SDSUPPORT
#if ENABLED(AUTO_BED_LEVELING_UBL)
/**
* UBL LCD "radar" map data
*/
#define MAP_UPPER_LEFT_CORNER_X 35 // These probably should be moved to the .h file But for now,
#define MAP_UPPER_LEFT_CORNER_Y 8 // it is easier to play with things having them here
#define MAP_MAX_PIXELS_X 53
#define MAP_MAX_PIXELS_Y 49
void _lcd_ubl_plot_DOGLCD(uint8_t x_plot, uint8_t y_plot) {
uint8_t i, j, x_offset, y_offset, x_map_pixels, y_map_pixels;
uint8_t pixels_per_X_mesh_pnt, pixels_per_Y_mesh_pnt, inverted_y;
/*********************************************************/
/************ Scale the box pixels appropriately *********/
/*********************************************************/
x_map_pixels = ((MAP_MAX_PIXELS_X - 4) / GRID_MAX_POINTS_X) * GRID_MAX_POINTS_X;
y_map_pixels = ((MAP_MAX_PIXELS_Y - 4) / GRID_MAX_POINTS_Y) * GRID_MAX_POINTS_Y;
pixels_per_X_mesh_pnt = x_map_pixels / GRID_MAX_POINTS_X;
pixels_per_Y_mesh_pnt = y_map_pixels / GRID_MAX_POINTS_Y;
x_offset = MAP_UPPER_LEFT_CORNER_X + 1 + (MAP_MAX_PIXELS_X-x_map_pixels-2)/2;
y_offset = MAP_UPPER_LEFT_CORNER_Y + 1 + (MAP_MAX_PIXELS_Y-y_map_pixels-2)/2;
/*********************************************************/
/************ Clear the Mesh Map Box**********************/
/*********************************************************/
u8g.setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box
u8g.drawBox(x_offset-2, y_offset-2, x_map_pixels+4, y_map_pixels+4);
u8g.setColorIndex(0); // Now actually clear the mesh map box
u8g.drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels);
/*********************************************************/
/************ Display Mesh Point Locations ***************/
/*********************************************************/
u8g.setColorIndex(1);
for (i = 0; i < GRID_MAX_POINTS_X; i++) {
for (j = 0; j < GRID_MAX_POINTS_Y; j++) {
u8g.drawBox(x_offset+i*pixels_per_X_mesh_pnt+pixels_per_X_mesh_pnt/2,
y_offset+j*pixels_per_Y_mesh_pnt+pixels_per_Y_mesh_pnt/2, 1, 1);
}
}
/*********************************************************/
/************ Fill in the Specified Mesh Point ***********/
/*********************************************************/
inverted_y = GRID_MAX_POINTS_Y - y_plot - 1; // The origin is typically in the lower right corner. We need to
// invert the Y to get it to plot in the right location.
u8g.drawBox(x_offset+x_plot*pixels_per_X_mesh_pnt, y_offset+inverted_y*pixels_per_Y_mesh_pnt,
pixels_per_X_mesh_pnt, pixels_per_Y_mesh_pnt);
/*********************************************************/
/************** Put Relevent Text on Display *************/
/*********************************************************/
// Show X and Y positions at top of screen
u8g.setColorIndex(1);
u8g.setPrintPos(5, 7);
lcd_print("X:");
lcd_print(ftostr32(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
u8g.setPrintPos(74, 7);
lcd_print("Y:");
lcd_print(ftostr32(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
// Print plot position
u8g.setPrintPos(5, 64);
lcd_print("(");
u8g.print(x_plot);
lcd_print(",");
u8g.print(y_plot);
lcd_print(")");
// Show the location value
u8g.setPrintPos(74, 64);
lcd_print("Z:");
if (!isnan(ubl.z_values[x_plot][y_plot])) {
lcd_print(ftostr43sign(ubl.z_values[x_plot][y_plot]));
}
else {
lcd_print(" -----");
}
}
#endif // AUTO_BED_LEVELING_UBL
#endif // ULTIPANEL
#endif // __ULTRALCD_IMPL_DOGM_H

View File

@ -31,6 +31,10 @@
#include "utility.h"
#include "duration_t.h"
#if ENABLED(AUTO_BED_LEVELING_UBL)
#include "ubl.h"
#endif
extern volatile uint8_t buttons; //an extended version of the last checked buttons in a bit array.
////////////////////////////////////
@ -1080,9 +1084,65 @@ static void lcd_implementation_status_screen() {
#endif // LCD_HAS_STATUS_INDICATORS
#ifdef AUTO_BED_LEVELING_UBL
void lcd_return_to_status(); // These are just place holders for the 20x4 LCD work that
void _lcd_ubl_output_char_lcd() { // is coming up very soon. Soon this will morph into the
lcd_return_to_status(); // real code.
// These are just basic data for the 20x4 LCD work that
// is coming up very soon.
// Soon this will morph into a map code.
void _lcd_ubl_plot_HD44780(uint8_t x_plot, uint8_t y_plot) {
uint8_t lcd_w_pos = 8, lcd_h_pos = 1;
#if LCD_WIDTH < 20
lcd_w_pos = 8;
#else
lcd_w_pos = 12;
#endif
#if LCD_HEIGHT > 3
lcd_h_pos = 3;
#elif LCD_HEIGHT > 2
lcd_h_pos = 2;
#else
lcd_h_pos = 1;
#endif
// Show X and Y positions at top of screen
lcd.setCursor(0, 0);
#if LCD_WIDTH < 20
lcd.print("X");
#else
lcd.print("X:");
#endif
lcd.print(ftostr32(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
lcd.setCursor(lcd_w_pos, 0);
#if LCD_WIDTH < 20
lcd.print("Y");
#else
lcd.print("Y:");
#endif
lcd.print(ftostr32(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
// Print plot position
lcd.setCursor(0, lcd_h_pos);
lcd.print("(");
lcd.print(x_plot);
lcd.print(",");
lcd.print(y_plot);
lcd.print(")");
// Show the location value
lcd.setCursor(lcd_w_pos, lcd_h_pos);
#if LCD_WIDTH < 20
lcd.print("Z");
#else
lcd.print("Z:");
#endif
if (!isnan(ubl.z_values[x_plot][y_plot])) {
lcd.print(ftostr43sign(ubl.z_values[x_plot][y_plot]));
}
else {
lcd.print(" -----");
}
}
#endif // AUTO_BED_LEVELING_UBL