Explorar el Código

Apply coding standards to recent merges

Scott Lahteine hace 7 años
padre
commit
0873c667fa

+ 36
- 36
Marlin/G26_Mesh_Validation_Tool.cpp Ver fichero

@@ -58,67 +58,67 @@
58 58
    *
59 59
    *   G26 is a Mesh Validation Tool intended to provide support for the Marlin Unified Bed Leveling System.
60 60
    *   In order to fully utilize and benefit from the Marlin Unified Bed Leveling System an accurate Mesh must
61
-   *   be defined.  G29 is designed to allow the user to quickly validate the correctness of her Mesh.  It will
61
+   *   be defined. G29 is designed to allow the user to quickly validate the correctness of her Mesh. It will
62 62
    *   first heat the bed and nozzle. It will then print lines and circles along the Mesh Cell boundaries and
63 63
    *   the intersections of those lines (respectively).
64 64
    *
65 65
    *   This action allows the user to immediately see where the Mesh is properly defined and where it needs to
66
-   *   be edited.  The command will generate the Mesh lines closest to the nozzle's starting position.  Alternatively
67
-   *   the user can specify the X and Y position of interest with command parameters.  This allows the user to
66
+   *   be edited. The command will generate the Mesh lines closest to the nozzle's starting position. Alternatively
67
+   *   the user can specify the X and Y position of interest with command parameters. This allows the user to
68 68
    *   focus on a particular area of the Mesh where attention is needed.
69 69
    *
70
-   *   B #  Bed         Set the Bed Temperature.  If not specified, a default of 60 C. will be assumed.
70
+   *   B #  Bed         Set the Bed Temperature. If not specified, a default of 60 C. will be assumed.
71 71
    *
72 72
    *   C    Current     When searching for Mesh Intersection points to draw, use the current nozzle location
73 73
    *                    as the base for any distance comparison.
74 74
    *
75
-   *   D    Disable     Disable the Unified Bed Leveling System.  In the normal case the user is invoking this
76
-   *                    command to see how well a Mesh as been adjusted to match a print surface.  In order to do
77
-   *                    this the Unified Bed Leveling System is turned on by the G26 command.  The D parameter
75
+   *   D    Disable     Disable the Unified Bed Leveling System. In the normal case the user is invoking this
76
+   *                    command to see how well a Mesh as been adjusted to match a print surface. In order to do
77
+   *                    this the Unified Bed Leveling System is turned on by the G26 command. The D parameter
78 78
    *                    alters the command's normal behaviour and disables the Unified Bed Leveling System even if
79 79
    *                    it is on.
80 80
    *
81
-   *   H #  Hotend      Set the Nozzle Temperature.  If not specified, a default of 205 C. will be assumed.
81
+   *   H #  Hotend      Set the Nozzle Temperature. If not specified, a default of 205 C. will be assumed.
82 82
    *
83
-   *   F #  Filament    Used to specify the diameter of the filament being used.  If not specified
84
-   *                    1.75mm filament is assumed.  If you are not getting acceptable results by using the
83
+   *   F #  Filament    Used to specify the diameter of the filament being used. If not specified
84
+   *                    1.75mm filament is assumed. If you are not getting acceptable results by using the
85 85
    *                    'correct' numbers, you can scale this number up or down a little bit to change the amount
86 86
    *                    of filament that is being extruded during the printing of the various lines on the bed.
87 87
    *
88 88
    *   K    Keep-On     Keep the heaters turned on at the end of the command.
89 89
    *
90
-   *   L #  Layer       Layer height.  (Height of nozzle above bed)  If not specified .20mm will be used.
90
+   *   L #  Layer       Layer height. (Height of nozzle above bed)  If not specified .20mm will be used.
91 91
    *
92
-   *   O #  Ooooze      How much your nozzle will Ooooze filament while getting in position to print.  This
92
+   *   O #  Ooooze      How much your nozzle will Ooooze filament while getting in position to print. This
93 93
    *                    is over kill, but using this parameter will let you get the very first 'circle' perfect
94 94
    *                    so you have a trophy to peel off of the bed and hang up to show how perfectly you have your
95
-   *                    Mesh calibrated.  If not specified, a filament length of .3mm is assumed.
95
+   *                    Mesh calibrated. If not specified, a filament length of .3mm is assumed.
96 96
    *
97
-   *   P #  Prime       Prime the nozzle with specified length of filament.  If this parameter is not
98
-   *                    given, no prime action will take place.  If the parameter specifies an amount, that much
99
-   *                    will be purged before continuing.  If no amount is specified the command will start
97
+   *   P #  Prime       Prime the nozzle with specified length of filament. If this parameter is not
98
+   *                    given, no prime action will take place. If the parameter specifies an amount, that much
99
+   *                    will be purged before continuing. If no amount is specified the command will start
100 100
    *                    purging filament until the user provides an LCD Click and then it will continue with
101
-   *                    printing the Mesh.  You can carefully remove the spent filament with a needle nose
102
-   *                    pliers while holding the LCD Click wheel in a depressed state.  If you do not have
101
+   *                    printing the Mesh. You can carefully remove the spent filament with a needle nose
102
+   *                    pliers while holding the LCD Click wheel in a depressed state. If you do not have
103 103
    *                    an LCD, you must specify a value if you use P.
104 104
    *
105
-   *   Q #  Multiplier  Retraction Multiplier.  Normally not needed.  Retraction defaults to 1.0mm and
105
+   *   Q #  Multiplier  Retraction Multiplier. Normally not needed. Retraction defaults to 1.0mm and
106 106
    *                    un-retraction is at 1.2mm   These numbers will be scaled by the specified amount
107 107
    *
108 108
    *   R #  Repeat      Prints the number of patterns given as a parameter, starting at the current location.
109 109
    *                    If a parameter isn't given, every point will be printed unless G26 is interrupted.
110 110
    *                    This works the same way that the UBL G29 P4 R parameter works.
111 111
    *
112
-   *                    NOTE:  If you do not have an LCD, you -must- specify R.  This is to ensure that you are
112
+   *                    NOTE:  If you do not have an LCD, you -must- specify R. This is to ensure that you are
113 113
    *                    aware that there's some risk associated with printing without the ability to abort in
114
-   *                    cases where mesh point Z value may be inaccurate.  As above, if you do not include a
114
+   *                    cases where mesh point Z value may be inaccurate. As above, if you do not include a
115 115
    *                    parameter, every point will be printed.
116 116
    *
117
-   *   S #  Nozzle      Used to control the size of nozzle diameter.  If not specified, a .4mm nozzle is assumed.
117
+   *   S #  Nozzle      Used to control the size of nozzle diameter. If not specified, a .4mm nozzle is assumed.
118 118
    *
119
-   *   U #  Random      Randomize the order that the circles are drawn on the bed.  The search for the closest
120
-   *                    undrawn cicle is still done.  But the distance to the location for each circle has a
121
-   *                    random number of the size specified added to it.  Specifying S50 will give an interesting
119
+   *   U #  Random      Randomize the order that the circles are drawn on the bed. The search for the closest
120
+   *                    undrawn cicle is still done. But the distance to the location for each circle has a
121
+   *                    random number of the size specified added to it. Specifying S50 will give an interesting
122 122
    *                    deviation from the normal behaviour on a 10 x 10 Mesh.
123 123
    *
124 124
    *   X #  X Coord.    Specify the starting location of the drawing activity.
@@ -218,7 +218,7 @@
218 218
    * nozzle in a problem area and doing a G29 P4 R command.
219 219
    */
220 220
   void unified_bed_leveling::G26() {
221
-    SERIAL_ECHOLNPGM("G26 command started.  Waiting for heater(s).");
221
+    SERIAL_ECHOLNPGM("G26 command started. Waiting for heater(s).");
222 222
     float tmp, start_angle, end_angle;
223 223
     int   i, xi, yi;
224 224
     mesh_index_pair location;
@@ -264,7 +264,7 @@
264 264
     //debug_current_and_destination(PSTR("Starting G26 Mesh Validation Pattern."));
265 265
 
266 266
     /**
267
-     * Declare and generate a sin() & cos() table to be used during the circle drawing.  This will lighten
267
+     * Declare and generate a sin() & cos() table to be used during the circle drawing. This will lighten
268 268
      * the CPU load and make the arc drawing faster and more smooth
269 269
      */
270 270
     float sin_table[360 / 30 + 1], cos_table[360 / 30 + 1];
@@ -575,17 +575,17 @@
575 575
 
576 576
   /**
577 577
    * print_line_from_here_to_there() takes two cartesian coordinates and draws a line from one
578
-   * to the other.  But there are really three sets of coordinates involved.  The first coordinate
579
-   * is the present location of the nozzle.  We don't necessarily want to print from this location.
580
-   * We first need to move the nozzle to the start of line segment where we want to print.  Once
578
+   * to the other. But there are really three sets of coordinates involved. The first coordinate
579
+   * is the present location of the nozzle. We don't necessarily want to print from this location.
580
+   * We first need to move the nozzle to the start of line segment where we want to print. Once
581 581
    * there, we can use the two coordinates supplied to draw the line.
582 582
    *
583 583
    * Note:  Although we assume the first set of coordinates is the start of the line and the second
584
-   * set of coordinates is the end of the line, it does not always work out that way.  This function
585
-   * optimizes the movement to minimize the travel distance before it can start printing.  This saves
586
-   * a lot of time and eleminates a lot of non-sensical movement of the nozzle.   However, it does
584
+   * set of coordinates is the end of the line, it does not always work out that way. This function
585
+   * optimizes the movement to minimize the travel distance before it can start printing. This saves
586
+   * a lot of time and eliminates a lot of nonsensical movement of the nozzle. However, it does
587 587
    * cause a lot of very little short retracement of th nozzle when it draws the very first line
588
-   * segment of a 'circle'.   The time this requires is very short and is easily saved by the other
588
+   * segment of a 'circle'. The time this requires is very short and is easily saved by the other
589 589
    * cases where the optimization comes into play.
590 590
    */
591 591
   void unified_bed_leveling::print_line_from_here_to_there(const float &sx, const float &sy, const float &sz, const float &ex, const float &ey, const float &ez) {
@@ -850,7 +850,7 @@
850 850
 
851 851
           stepper.synchronize();    // Without this synchronize, the purge is more consistent,
852 852
                                     // but because the planner has a buffer, we won't be able
853
-                                    // to stop as quickly.  So we put up with the less smooth
853
+                                    // to stop as quickly. So we put up with the less smooth
854 854
                                     // action to give the user a more responsive 'Stop'.
855 855
           set_destination_to_current();
856 856
           idle();
@@ -860,7 +860,7 @@
860 860
 
861 861
         #if ENABLED(ULTRA_LCD)
862 862
           strcpy_P(lcd_status_message, PSTR("Done Priming")); // We can't do lcd_setstatusPGM() without having it continue;
863
-                                                              // So...  We cheat to get a message up.
863
+                                                              // So... We cheat to get a message up.
864 864
           lcd_setstatusPGM(PSTR("Done Priming"), 99);
865 865
           lcd_quick_feedback();
866 866
         #endif

+ 1
- 1
Marlin/Marlin_main.cpp Ver fichero

@@ -3242,7 +3242,7 @@ inline void gcode_G0_G1(
3242 3242
       if (autoretract_enabled && !(parser.seen('X') || parser.seen('Y') || parser.seen('Z')) && parser.seen('E')) {
3243 3243
         const float echange = destination[E_AXIS] - current_position[E_AXIS];
3244 3244
         // Is this move an attempt to retract or recover?
3245
-        if ((echange < -MIN_RETRACT && !retracted[active_extruder]) || (echange > MIN_RETRACT && retracted[active_extruder])) {
3245
+        if ((echange < -(MIN_RETRACT) && !retracted[active_extruder]) || (echange > MIN_RETRACT && retracted[active_extruder])) {
3246 3246
           current_position[E_AXIS] = destination[E_AXIS]; // hide the slicer-generated retract/recover from calculations
3247 3247
           sync_plan_position_e();  // AND from the planner
3248 3248
           retract(!retracted[active_extruder]);

+ 1
- 1
Marlin/least_squares_fit.cpp Ver fichero

@@ -68,4 +68,4 @@ int finish_incremental_LSF(struct linear_fit_data *lsf) {
68 68
   return 0;
69 69
 }
70 70
 
71
-#endif // AUTO_BED_LEVELING_UBL || ENABLED(AUTO_BED_LEVELING_LINEAR)  
71
+#endif // AUTO_BED_LEVELING_UBL || ENABLED(AUTO_BED_LEVELING_LINEAR)

+ 1
- 1
Marlin/least_squares_fit.h Ver fichero

@@ -34,7 +34,7 @@
34 34
 
35 35
 #include "MarlinConfig.h"
36 36
 
37
-#if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(AUTO_BED_LEVELING_LINEAR)    
37
+#if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(AUTO_BED_LEVELING_LINEAR)
38 38
 
39 39
 #include "Marlin.h"
40 40
 #include "macros.h"

+ 10
- 10
Marlin/ultralcd_impl_DOGM.h Ver fichero

@@ -976,8 +976,8 @@ static void lcd_implementation_status_screen() {
976 976
       uint8_t x_map_pixels = ((MAP_MAX_PIXELS_X - 4) / (GRID_MAX_POINTS_X)) * (GRID_MAX_POINTS_X),
977 977
               y_map_pixels = ((MAP_MAX_PIXELS_Y - 4) / (GRID_MAX_POINTS_Y)) * (GRID_MAX_POINTS_Y),
978 978
 
979
-              pixels_per_X_mesh_pnt = x_map_pixels / (GRID_MAX_POINTS_X),
980
-              pixels_per_Y_mesh_pnt = y_map_pixels / (GRID_MAX_POINTS_Y),
979
+              pixels_per_x_mesh_pnt = x_map_pixels / (GRID_MAX_POINTS_X),
980
+              pixels_per_y_mesh_pnt = y_map_pixels / (GRID_MAX_POINTS_Y),
981 981
 
982 982
               x_offset = MAP_UPPER_LEFT_CORNER_X + 1 + (MAP_MAX_PIXELS_X - x_map_pixels - 2) / 2,
983 983
               y_offset = MAP_UPPER_LEFT_CORNER_Y + 1 + (MAP_MAX_PIXELS_Y - y_map_pixels - 2) / 2;
@@ -996,11 +996,11 @@ static void lcd_implementation_status_screen() {
996 996
       // Display Mesh Point Locations
997 997
 
998 998
       u8g.setColorIndex(1);
999
-      const uint8_t sx = x_offset + pixels_per_X_mesh_pnt / 2;
1000
-            uint8_t  y = y_offset + pixels_per_Y_mesh_pnt / 2;
1001
-      for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_Y_mesh_pnt)
999
+      const uint8_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
1000
+            uint8_t  y = y_offset + pixels_per_y_mesh_pnt / 2;
1001
+      for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt)
1002 1002
         if (PAGE_CONTAINS(y, y))
1003
-          for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_X_mesh_pnt)
1003
+          for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt)
1004 1004
             u8g.drawBox(sx, y, 1, 1);
1005 1005
 
1006 1006
       // Fill in the Specified Mesh Point
@@ -1008,11 +1008,11 @@ static void lcd_implementation_status_screen() {
1008 1008
       uint8_t inverted_y = GRID_MAX_POINTS_Y - y_plot - 1;  // The origin is typically in the lower right corner.  We need to
1009 1009
                                                             // invert the Y to get it to plot in the right location.
1010 1010
 
1011
-      const uint8_t by = y_offset + inverted_y * pixels_per_Y_mesh_pnt;
1012
-      if (PAGE_CONTAINS(by, by + pixels_per_Y_mesh_pnt))
1011
+      const uint8_t by = y_offset + inverted_y * pixels_per_y_mesh_pnt;
1012
+      if (PAGE_CONTAINS(by, by + pixels_per_y_mesh_pnt))
1013 1013
         u8g.drawBox(
1014
-          x_offset + x_plot * pixels_per_X_mesh_pnt, by,
1015
-          pixels_per_X_mesh_pnt, pixels_per_Y_mesh_pnt
1014
+          x_offset + x_plot * pixels_per_x_mesh_pnt, by,
1015
+          pixels_per_x_mesh_pnt, pixels_per_y_mesh_pnt
1016 1016
         );
1017 1017
 
1018 1018
       // Put Relevant Text on Display

+ 389
- 469
Marlin/ultralcd_impl_HD44780.h Ver fichero

@@ -42,10 +42,10 @@
42 42
 
43 43
     #define N_USER_CHARS    8
44 44
 
45
-    #define TOP_LEFT      0x01
46
-    #define TOP_RIGHT     0x02
47
-    #define LOWER_LEFT    0x04
48
-    #define LOWER_RIGHT   0x08
45
+    #define TOP_LEFT      _BV(0)
46
+    #define TOP_RIGHT     _BV(1)
47
+    #define LOWER_LEFT    _BV(2)
48
+    #define LOWER_RIGHT   _BV(3)
49 49
   #endif
50 50
 #endif
51 51
 
@@ -1057,345 +1057,351 @@ static void lcd_implementation_status_screen() {
1057 1057
 
1058 1058
   #endif // LCD_HAS_SLOW_BUTTONS
1059 1059
 
1060
-#endif // ULTIPANEL
1061
-
1062
-#if ENABLED(LCD_HAS_STATUS_INDICATORS)
1060
+  #if ENABLED(LCD_HAS_STATUS_INDICATORS)
1063 1061
 
1064
-  static void lcd_implementation_update_indicators() {
1065
-    // Set the LEDS - referred to as backlights by the LiquidTWI2 library
1066
-    static uint8_t ledsprev = 0;
1067
-    uint8_t leds = 0;
1062
+    static void lcd_implementation_update_indicators() {
1063
+      // Set the LEDS - referred to as backlights by the LiquidTWI2 library
1064
+      static uint8_t ledsprev = 0;
1065
+      uint8_t leds = 0;
1068 1066
 
1069
-    if (thermalManager.degTargetBed() > 0) leds |= LED_A;
1067
+      if (thermalManager.degTargetBed() > 0) leds |= LED_A;
1070 1068
 
1071
-    if (thermalManager.degTargetHotend(0) > 0) leds |= LED_B;
1069
+      if (thermalManager.degTargetHotend(0) > 0) leds |= LED_B;
1072 1070
 
1073
-    #if FAN_COUNT > 0
1074
-      if (0
1075
-        #if HAS_FAN0
1076
-          || fanSpeeds[0]
1077
-        #endif
1078
-        #if HAS_FAN1
1079
-          || fanSpeeds[1]
1080
-        #endif
1081
-        #if HAS_FAN2
1082
-          || fanSpeeds[2]
1083
-        #endif
1084
-      ) leds |= LED_C;
1085
-    #endif // FAN_COUNT > 0
1071
+      #if FAN_COUNT > 0
1072
+        if (0
1073
+          #if HAS_FAN0
1074
+            || fanSpeeds[0]
1075
+          #endif
1076
+          #if HAS_FAN1
1077
+            || fanSpeeds[1]
1078
+          #endif
1079
+          #if HAS_FAN2
1080
+            || fanSpeeds[2]
1081
+          #endif
1082
+        ) leds |= LED_C;
1083
+      #endif // FAN_COUNT > 0
1086 1084
 
1087
-    #if HOTENDS > 1
1088
-      if (thermalManager.degTargetHotend(1) > 0) leds |= LED_C;
1089
-    #endif
1085
+      #if HOTENDS > 1
1086
+        if (thermalManager.degTargetHotend(1) > 0) leds |= LED_C;
1087
+      #endif
1090 1088
 
1091
-    if (leds != ledsprev) {
1092
-      lcd.setBacklight(leds);
1093
-      ledsprev = leds;
1089
+      if (leds != ledsprev) {
1090
+        lcd.setBacklight(leds);
1091
+        ledsprev = leds;
1092
+      }
1094 1093
     }
1095
-  }
1096 1094
 
1097
-#endif // LCD_HAS_STATUS_INDICATORS
1095
+  #endif // LCD_HAS_STATUS_INDICATORS
1098 1096
 
1099
-#if ENABLED(AUTO_BED_LEVELING_UBL)
1097
+  #if ENABLED(AUTO_BED_LEVELING_UBL)
1100 1098
 
1101
-   /**
1102
-    Possible map screens:
1099
+    /**
1100
+      Possible map screens:
1103 1101
 
1104
-    16x2   |X000.00  Y000.00|
1105
-           |(00,00)  Z00.000|
1102
+      16x2   |X000.00  Y000.00|
1103
+             |(00,00)  Z00.000|
1106 1104
 
1107
-    20x2   | X:000.00  Y:000.00 |
1108
-           | (00,00)   Z:00.000 |
1105
+      20x2   | X:000.00  Y:000.00 |
1106
+             | (00,00)   Z:00.000 |
1109 1107
 
1110
-    16x4   |+-------+(00,00)|
1111
-           ||       |X000.00|
1112
-           ||       |Y000.00|
1113
-           |+-------+Z00.000|
1108
+      16x4   |+-------+(00,00)|
1109
+             ||       |X000.00|
1110
+             ||       |Y000.00|
1111
+             |+-------+Z00.000|
1114 1112
 
1115
-    20x4   | +-------+  (00,00) |
1116
-           | |       |  X:000.00|
1117
-           | |       |  Y:000.00|
1118
-           | +-------+  Z:00.000|
1113
+      20x4   | +-------+  (00,00) |
1114
+             | |       |  X:000.00|
1115
+             | |       |  Y:000.00|
1116
+             | +-------+  Z:00.000|
1119 1117
     */
1120 1118
 
1121
-  struct custom_char {
1122
-    uint8_t custom_char_bits[ULTRA_Y_PIXELS_PER_CHAR];
1123
-  };
1119
+    typedef struct {
1120
+      uint8_t custom_char_bits[ULTRA_Y_PIXELS_PER_CHAR];
1121
+    } custom_char;
1122
+
1123
+    typedef struct {
1124
+      uint8_t column, row;
1125
+      uint8_t y_pixel_offset, x_pixel_offset;
1126
+      uint8_t x_pixel_mask;
1127
+    } coordinate;
1128
+
1129
+    void add_edges_to_custom_char(custom_char * const custom, coordinate * const ul, coordinate * const lr, coordinate * const brc, const uint8_t cell_location);
1130
+    FORCE_INLINE static void clear_custom_char(custom_char * const cc) { ZERO(cc->custom_char_bits); }
1131
+
1132
+    /*
1133
+    // This debug routine should be deleted by anybody that sees it.  It doesn't belong here
1134
+    // But I'm leaving it for now until we know the 20x4 Radar Map is working right.
1135
+    // We may need it again if any funny lines show up on the mesh points.
1136
+    void dump_custom_char(char *title, custom_char *c) {
1137
+      SERIAL_PROTOCOLLN(title);
1138
+      for (uint8_t j = 0; j < 8; j++) {
1139
+        for (uint8_t i = 7; i >= 0; i--)
1140
+          SERIAL_PROTOCOLCHAR(TEST(c->custom_char_bits[j], i) ? '1' : '0');
1141
+        SERIAL_EOL();
1142
+      }
1143
+      SERIAL_EOL();
1144
+    }
1145
+    //*/
1124 1146
 
1125
-  struct coordinate pixel_location(uint8_t x, uint8_t y);
1147
+    coordinate pixel_location(int16_t x, int16_t y) {
1148
+      coordinate ret_val;
1149
+      int16_t xp, yp, r, c;
1126 1150
 
1127
-  struct coordinate {
1128
-          uint8_t column;
1129
-          uint8_t row;
1130
-          uint8_t y_pixel_offset;
1131
-          uint8_t x_pixel_offset;
1132
-          uint8_t x_pixel_mask;
1133
-  };
1151
+      x++; y++; // +1 because lines on the left and top
1134 1152
 
1135
-  void add_edges_to_custom_char(struct custom_char *custom, struct coordinate *ul, struct coordinate *lr, struct coordinate *brc, uint8_t cell_location);
1136
-  extern custom_char user_defined_chars[N_USER_CHARS];
1137
-  inline static void CLEAR_CUSTOM_CHAR(struct custom_char *cc) { uint8_t j; for (j = 0; j < ULTRA_Y_PIXELS_PER_CHAR; j++) cc->custom_char_bits[j] = 0; }
1138
-
1139
-  /*
1140
-  void dump_custom_char(char *title, struct custom_char *c) {   // This debug routine should be deleted by anybody that sees it.  It doesn't belong here
1141
-    int i, j;                                                     // But I'm leaving it for now until we know the 20x4 Radar Map is working right.
1142
-    SERIAL_PROTOCOLLN(title);                                   // We will need it again if any funny lines show up on the mesh points.
1143
-    for(j=0; j<8; j++) {
1144
-      for(i=7; i>=0; i--) {
1145
-        if (c->custom_char_bits[j] & (0x01 << i))
1146
-          SERIAL_PROTOCOL("1");
1147
-        else
1148
-          SERIAL_PROTOCOL("0");
1149
-      }
1150
-      SERIAL_PROTOCOL("\n");
1151
-    }
1152
-    SERIAL_PROTOCOL("\n");
1153
-  }
1154
-  */
1155
-
1156
-  void lcd_implementation_ubl_plot(uint8_t x, uint8_t inverted_y) {
1157
-
1158
-    #if LCD_WIDTH >= 20
1159
-      #define _LCD_W_POS 12
1160
-      #define _PLOT_X 1
1161
-      #define _MAP_X 3
1162
-      #define _LABEL(C,X,Y) lcd.setCursor(X, Y); lcd.print(C)
1163
-      #define _XLABEL(X,Y) _LABEL("X:",X,Y)
1164
-      #define _YLABEL(X,Y) _LABEL("Y:",X,Y)
1165
-      #define _ZLABEL(X,Y) _LABEL("Z:",X,Y)
1166
-    #else
1167
-      #define _LCD_W_POS 8
1168
-      #define _PLOT_X 0
1169
-      #define _MAP_X 1
1170
-      #define _LABEL(X,Y,C) lcd.setCursor(X, Y); lcd.write(C)
1171
-      #define _XLABEL(X,Y) _LABEL('X',X,Y)
1172
-      #define _YLABEL(X,Y) _LABEL('Y',X,Y)
1173
-      #define _ZLABEL(X,Y) _LABEL('Z',X,Y)
1174
-    #endif
1153
+      c = x / (ULTRA_X_PIXELS_PER_CHAR);
1154
+      r = y / (ULTRA_Y_PIXELS_PER_CHAR);
1175 1155
 
1176
-    #if LCD_HEIGHT <= 3   // 16x2 or 20x2 display
1156
+      ret_val.column = c;
1157
+      ret_val.row    = r;
1177 1158
 
1178
-      /**
1179
-       * Show X and Y positions
1180
-       */
1181
-      _XLABEL(_PLOT_X, 0);
1182
-      lcd.print(ftostr32(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x]))));
1159
+      xp = x - c * (ULTRA_X_PIXELS_PER_CHAR);   // get the pixel offsets into the character cell
1160
+      xp = ULTRA_X_PIXELS_PER_CHAR - 1 - xp;    // column within relevant character cell (0 on the right)
1161
+      yp = y - r * (ULTRA_Y_PIXELS_PER_CHAR);
1183 1162
 
1184
-      _YLABEL(_LCD_W_POS, 0);
1185
-      lcd.print(ftostr32(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[inverted_y]))));
1163
+      ret_val.x_pixel_mask   = _BV(xp);
1164
+      ret_val.x_pixel_offset = xp;
1165
+      ret_val.y_pixel_offset = yp;
1166
+      return ret_val;
1167
+    }
1186 1168
 
1187
-      lcd.setCursor(_PLOT_X, 0);
1169
+    coordinate pixel_location(uint8_t x, uint8_t y) { return pixel_location((int16_t)x, (int16_t)y); }
1188 1170
 
1189
-    #else // 16x4 or 20x4 display
1171
+    void lcd_implementation_ubl_plot(uint8_t x, uint8_t inverted_y) {
1190 1172
 
1191
-      struct coordinate upper_left, lower_right, bottom_right_corner;
1192
-      struct custom_char new_char;
1193
-      uint8_t i, j, k, l, m, n, n_rows, n_cols, y;
1194
-      uint8_t bottom_line, right_edge;
1195
-      uint8_t x_map_pixels, y_map_pixels;
1196
-      uint8_t pixels_per_X_mesh_pnt, pixels_per_Y_mesh_pnt;
1197
-      uint8_t suppress_x_offset=0, suppress_y_offset=0;
1173
+      #if LCD_WIDTH >= 20
1174
+        #define _LCD_W_POS 12
1175
+        #define _PLOT_X 1
1176
+        #define _MAP_X 3
1177
+        #define _LABEL(C,X,Y) lcd.setCursor(X, Y); lcd.print(C)
1178
+        #define _XLABEL(X,Y) _LABEL("X:",X,Y)
1179
+        #define _YLABEL(X,Y) _LABEL("Y:",X,Y)
1180
+        #define _ZLABEL(X,Y) _LABEL("Z:",X,Y)
1181
+      #else
1182
+        #define _LCD_W_POS 8
1183
+        #define _PLOT_X 0
1184
+        #define _MAP_X 1
1185
+        #define _LABEL(X,Y,C) lcd.setCursor(X, Y); lcd.write(C)
1186
+        #define _XLABEL(X,Y) _LABEL('X',X,Y)
1187
+        #define _YLABEL(X,Y) _LABEL('Y',X,Y)
1188
+        #define _ZLABEL(X,Y) _LABEL('Z',X,Y)
1189
+      #endif
1198 1190
 
1199
-      //  ********************************************************
1200
-      //  ************ Clear and setup everything        *********
1201
-      //  ********************************************************
1191
+      #if LCD_HEIGHT <= 3   // 16x2 or 20x2 display
1202 1192
 
1203
-      y = GRID_MAX_POINTS_Y - inverted_y - 1;
1193
+        /**
1194
+         * Show X and Y positions
1195
+         */
1196
+        _XLABEL(_PLOT_X, 0);
1197
+        lcd.print(ftostr32(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x]))));
1204 1198
 
1205
-      upper_left.column  = 0;
1206
-      upper_left.row     = 0;
1207
-      lower_right.column = 0;
1208
-      lower_right.row    = 0;
1199
+        _YLABEL(_LCD_W_POS, 0);
1200
+        lcd.print(ftostr32(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[inverted_y]))));
1209 1201
 
1210
-      lcd_implementation_clear();
1202
+        lcd.setCursor(_PLOT_X, 0);
1211 1203
 
1212
-      x_map_pixels = ULTRA_X_PIXELS_PER_CHAR * ULTRA_COLUMNS_FOR_MESH_MAP - 2;  // minus 2 because we are drawing a box around the map
1213
-      y_map_pixels = ULTRA_Y_PIXELS_PER_CHAR * ULTRA_ROWS_FOR_MESH_MAP - 2;
1204
+      #else // 16x4 or 20x4 display
1214 1205
 
1215
-      pixels_per_X_mesh_pnt = x_map_pixels / GRID_MAX_POINTS_X;
1216
-      pixels_per_Y_mesh_pnt = y_map_pixels / GRID_MAX_POINTS_Y;
1206
+        coordinate upper_left, lower_right, bottom_right_corner;
1207
+        custom_char new_char;
1208
+        uint8_t i, j, k, l, m, n, n_rows, n_cols, y,
1209
+                bottom_line, right_edge,
1210
+                x_map_pixels, y_map_pixels,
1211
+                pixels_per_x_mesh_pnt, pixels_per_y_mesh_pnt,
1212
+                suppress_x_offset = 0, suppress_y_offset = 0;
1217 1213
 
1218
-      if (pixels_per_X_mesh_pnt >= ULTRA_X_PIXELS_PER_CHAR)  {                  // There are only 2 custom characters available, so the X
1219
-        pixels_per_X_mesh_pnt = ULTRA_X_PIXELS_PER_CHAR;                        // size of the mesh point needs to fit within them independent
1220
-        suppress_x_offset = 1;                                                  // of where the starting pixel is located.
1221
-      }
1214
+        y = GRID_MAX_POINTS_Y - inverted_y - 1;
1222 1215
 
1223
-      if (pixels_per_Y_mesh_pnt >= ULTRA_Y_PIXELS_PER_CHAR) {                   // There are only 2 custom characters available, so the Y
1224
-        pixels_per_Y_mesh_pnt = ULTRA_Y_PIXELS_PER_CHAR;                        // size of the mesh point needs to fit within them independent
1225
-        suppress_y_offset = 1;                                                  // of where the starting pixel is located.
1226
-      }
1216
+        upper_left.column  = 0;
1217
+        upper_left.row     = 0;
1218
+        lower_right.column = 0;
1219
+        lower_right.row    = 0;
1227 1220
 
1228
-      x_map_pixels = pixels_per_X_mesh_pnt * GRID_MAX_POINTS_X;                 // now we have the right number of pixels to make both
1229
-      y_map_pixels = pixels_per_Y_mesh_pnt * GRID_MAX_POINTS_Y;                 // directions fit nicely
1221
+        lcd_implementation_clear();
1230 1222
 
1231
-      right_edge = pixels_per_X_mesh_pnt * GRID_MAX_POINTS_X + 1;               // find location of right edge within the character cell
1232
-      bottom_line= pixels_per_Y_mesh_pnt * GRID_MAX_POINTS_Y + 1;               // find location of bottome line within the character cell
1223
+        x_map_pixels = (ULTRA_X_PIXELS_PER_CHAR) * (ULTRA_COLUMNS_FOR_MESH_MAP) - 2;  // minus 2 because we are drawing a box around the map
1224
+        y_map_pixels = (ULTRA_Y_PIXELS_PER_CHAR) * (ULTRA_ROWS_FOR_MESH_MAP) - 2;
1233 1225
 
1234
-      n_rows = (bottom_line / ULTRA_Y_PIXELS_PER_CHAR) + 1;
1235
-      n_cols = (right_edge / ULTRA_X_PIXELS_PER_CHAR) + 1;
1226
+        pixels_per_x_mesh_pnt = x_map_pixels / (GRID_MAX_POINTS_X);
1227
+        pixels_per_y_mesh_pnt = y_map_pixels / (GRID_MAX_POINTS_Y);
1236 1228
 
1237
-      for (i = 0; i < n_cols; i++) {
1238
-        lcd.setCursor(i, 0);
1239
-        lcd.print((char) 0x00);                    // top line of the box
1229
+        if (pixels_per_x_mesh_pnt >= ULTRA_X_PIXELS_PER_CHAR) {         // There are only 2 custom characters available, so the X
1230
+          pixels_per_x_mesh_pnt = ULTRA_X_PIXELS_PER_CHAR;              // size of the mesh point needs to fit within them independent
1231
+          suppress_x_offset = 1;                                        // of where the starting pixel is located.
1232
+        }
1240 1233
 
1241
-        lcd.setCursor(i, n_rows-1);
1242
-        lcd.write(0x01);                           // bottom line of the box
1243
-      }
1234
+        if (pixels_per_y_mesh_pnt >= ULTRA_Y_PIXELS_PER_CHAR) {         // There are only 2 custom characters available, so the Y
1235
+          pixels_per_y_mesh_pnt = ULTRA_Y_PIXELS_PER_CHAR;              // size of the mesh point needs to fit within them independent
1236
+          suppress_y_offset = 1;                                        // of where the starting pixel is located.
1237
+        }
1244 1238
 
1245
-      for (j = 0; j < n_rows; j++) {
1246
-        lcd.setCursor(0, j);
1247
-        lcd.write(0x02);                           // Left edge of the box
1248
-        lcd.setCursor(n_cols-1, j);
1249
-        lcd.write(0x03);                           // right edge of the box
1250
-      }
1239
+        x_map_pixels = pixels_per_x_mesh_pnt * (GRID_MAX_POINTS_X);     // now we have the right number of pixels to make both
1240
+        y_map_pixels = pixels_per_y_mesh_pnt * (GRID_MAX_POINTS_Y);     // directions fit nicely
1251 1241
 
1252
-      //
1253
-      /* if the entire 4th row is not in use, do not put vertical bars all the way down to the bottom of the display */
1254
-      //
1242
+        right_edge = pixels_per_x_mesh_pnt * (GRID_MAX_POINTS_X) + 1;   // find location of right edge within the character cell
1243
+        bottom_line= pixels_per_y_mesh_pnt * (GRID_MAX_POINTS_Y) + 1;   // find location of bottome line within the character cell
1255 1244
 
1256
-      k = pixels_per_Y_mesh_pnt * GRID_MAX_POINTS_Y + 2;
1257
-      l = ULTRA_Y_PIXELS_PER_CHAR * n_rows;
1258
-      if ((k != l) && ((l-k)>=ULTRA_Y_PIXELS_PER_CHAR/2)) {
1259
-        lcd.setCursor(0, n_rows-1);            // left edge of the box
1260
-        lcd.write(' ');
1261
-        lcd.setCursor(n_cols-1, n_rows-1);     // right edge of the box
1262
-        lcd.write(' ');
1263
-      }
1245
+        n_rows = bottom_line / (ULTRA_Y_PIXELS_PER_CHAR) + 1;
1246
+        n_cols = right_edge / (ULTRA_X_PIXELS_PER_CHAR) + 1;
1264 1247
 
1265
-      CLEAR_CUSTOM_CHAR(&new_char);
1266
-      new_char.custom_char_bits[0] = (unsigned char) 0B11111;                // char #0 is used for the top line of the box
1267
-      lcd.createChar(0, (uint8_t *) &new_char);
1268
-
1269
-      CLEAR_CUSTOM_CHAR(&new_char);
1270
-      k = GRID_MAX_POINTS_Y * pixels_per_Y_mesh_pnt + 1;                     // row of pixels for the bottom box line
1271
-      l = k % ULTRA_Y_PIXELS_PER_CHAR;                                       // row within relivant character cell
1272
-      new_char.custom_char_bits[l] = (unsigned char) 0B11111;                // char #1 is used for the bottom line of the box
1273
-      lcd.createChar(1, (uint8_t *) &new_char);
1274
-
1275
-      CLEAR_CUSTOM_CHAR(&new_char);
1276
-      for (j = 0; j < ULTRA_Y_PIXELS_PER_CHAR; j++)
1277
-        new_char.custom_char_bits[j] = (unsigned char) 0B10000;              // char #2 is used for the left edge of the box
1278
-      lcd.createChar(2, (uint8_t *) &new_char);
1279
-
1280
-      CLEAR_CUSTOM_CHAR(&new_char);
1281
-      m = GRID_MAX_POINTS_X * pixels_per_X_mesh_pnt + 1;                     // column of pixels for the right box line
1282
-      n = m % ULTRA_X_PIXELS_PER_CHAR;                                       // column within relivant character cell
1283
-      i = ULTRA_X_PIXELS_PER_CHAR - 1 - n;                                   // column within relivant character cell (0 on the right)
1284
-      for (j = 0; j < ULTRA_Y_PIXELS_PER_CHAR; j++)
1285
-        new_char.custom_char_bits[j] = (unsigned char) 0B00001 << i;         // char #3 is used for the right edge of the box
1286
-      lcd.createChar(3, (uint8_t *) &new_char);
1287
-
1288
-      i = x*pixels_per_X_mesh_pnt - suppress_x_offset;
1289
-      j = y*pixels_per_Y_mesh_pnt - suppress_y_offset;
1290
-      upper_left = pixel_location(i, j);
1291
-
1292
-      k = (x+1)*pixels_per_X_mesh_pnt-1-suppress_x_offset;
1293
-      l = (y+1)*pixels_per_Y_mesh_pnt-1-suppress_y_offset;
1294
-      lower_right = pixel_location(k, l);
1295
-
1296
-      bottom_right_corner = pixel_location(x_map_pixels, y_map_pixels);
1297
-
1298
-      /*
1299
-       * First, handle the simple case where everything is within a single character cell.
1300
-       * If part of the Mesh Plot is outside of this character cell, we will follow up
1301
-       * and deal with that next.
1302
-       */
1248
+        for (i = 0; i < n_cols; i++) {
1249
+          lcd.setCursor(i, 0);
1250
+          lcd.print((char)0x00);                     // top line of the box
1303 1251
 
1304
-  //dump_custom_char("at entry:", &new_char);
1252
+          lcd.setCursor(i, n_rows - 1);
1253
+          lcd.write(0x01);                           // bottom line of the box
1254
+        }
1305 1255
 
1306
-      CLEAR_CUSTOM_CHAR(&new_char);
1307
-      for(j=upper_left.y_pixel_offset; j<upper_left.y_pixel_offset+pixels_per_Y_mesh_pnt; j++) {
1308
-        if (j >= ULTRA_Y_PIXELS_PER_CHAR)
1309
-          break;
1310
-        i=upper_left.x_pixel_mask;
1311
-        for(k=0; k<pixels_per_X_mesh_pnt; k++)  {
1312
-          new_char.custom_char_bits[j] |= i;
1313
-          i = i >> 1;
1256
+        for (j = 0; j < n_rows; j++) {
1257
+          lcd.setCursor(0, j);
1258
+          lcd.write(0x02);                           // Left edge of the box
1259
+          lcd.setCursor(n_cols - 1, j);
1260
+          lcd.write(0x03);                           // right edge of the box
1314 1261
         }
1315
-      }
1316
-  //dump_custom_char("after loops:", &new_char);
1317 1262
 
1318
-      add_edges_to_custom_char(&new_char, &upper_left, &lower_right, &bottom_right_corner, TOP_LEFT);
1319
-  //dump_custom_char("after add edges", &new_char);
1320
-      lcd.createChar(4, (uint8_t *) &new_char);
1263
+        /**
1264
+         * If the entire 4th row is not in use, do not put vertical bars all the way down to the bottom of the display
1265
+         */
1321 1266
 
1322
-      lcd.setCursor(upper_left.column, upper_left.row);
1323
-      lcd.write(0x04);
1324
-  //dump_custom_char("after lcd update:", &new_char);
1267
+        k = pixels_per_y_mesh_pnt * (GRID_MAX_POINTS_Y) + 2;
1268
+        l = (ULTRA_Y_PIXELS_PER_CHAR) * n_rows;
1269
+        if (l > k && l - k >= (ULTRA_Y_PIXELS_PER_CHAR) / 2) {
1270
+          lcd.setCursor(0, n_rows - 1);            // left edge of the box
1271
+          lcd.write(' ');
1272
+          lcd.setCursor(n_cols - 1, n_rows - 1);   // right edge of the box
1273
+          lcd.write(' ');
1274
+        }
1325 1275
 
1326
-      /*
1327
-       * Next, check for two side by side character cells being used to display the Mesh Point
1328
-       * If found...  do the right hand character cell next.
1329
-       */
1330
-      if (upper_left.column+1 == lower_right.column) {
1331
-        l = upper_left.x_pixel_offset;
1332
-        CLEAR_CUSTOM_CHAR(&new_char);
1333
-        for (j = upper_left.y_pixel_offset; j < upper_left.y_pixel_offset + pixels_per_Y_mesh_pnt; j++) {
1334
-          if (j >= ULTRA_Y_PIXELS_PER_CHAR)
1335
-            break;
1336
-          i=0x01 << (ULTRA_X_PIXELS_PER_CHAR-1);                  // fill in the left side of the right character cell
1337
-          for(k=0; k<pixels_per_X_mesh_pnt-1-l; k++)  {
1276
+        clear_custom_char(&new_char);
1277
+        new_char.custom_char_bits[0] = 0B11111U;              // char #0 is used for the top line of the box
1278
+        lcd.createChar(0, (uint8_t*)&new_char);
1279
+
1280
+        clear_custom_char(&new_char);
1281
+        k = (GRID_MAX_POINTS_Y) * pixels_per_y_mesh_pnt + 1;  // row of pixels for the bottom box line
1282
+        l = k % (ULTRA_Y_PIXELS_PER_CHAR);                    // row within relevant character cell
1283
+        new_char.custom_char_bits[l] = 0B11111U;              // char #1 is used for the bottom line of the box
1284
+        lcd.createChar(1, (uint8_t*)&new_char);
1285
+
1286
+        clear_custom_char(&new_char);
1287
+        for (j = 0; j < ULTRA_Y_PIXELS_PER_CHAR; j++)
1288
+          new_char.custom_char_bits[j] = 0B10000U;            // char #2 is used for the left edge of the box
1289
+        lcd.createChar(2, (uint8_t*)&new_char);
1290
+
1291
+        clear_custom_char(&new_char);
1292
+        m = (GRID_MAX_POINTS_X) * pixels_per_x_mesh_pnt + 1;  // Column of pixels for the right box line
1293
+        n = m % (ULTRA_X_PIXELS_PER_CHAR);                    // Column within relevant character cell
1294
+        i = ULTRA_X_PIXELS_PER_CHAR - 1 - n;                  // Column within relevant character cell (0 on the right)
1295
+        for (j = 0; j < ULTRA_Y_PIXELS_PER_CHAR; j++)
1296
+          new_char.custom_char_bits[j] = (uint8_t)_BV(i);     // Char #3 is used for the right edge of the box
1297
+        lcd.createChar(3, (uint8_t*)&new_char);
1298
+
1299
+        i = x * pixels_per_x_mesh_pnt - suppress_x_offset;
1300
+        j = y * pixels_per_y_mesh_pnt - suppress_y_offset;
1301
+        upper_left = pixel_location(i, j);
1302
+
1303
+        k = (x + 1) * pixels_per_x_mesh_pnt - 1 - suppress_x_offset;
1304
+        l = (y + 1) * pixels_per_y_mesh_pnt - 1 - suppress_y_offset;
1305
+        lower_right = pixel_location(k, l);
1306
+
1307
+        bottom_right_corner = pixel_location(x_map_pixels, y_map_pixels);
1308
+
1309
+        /**
1310
+         * First, handle the simple case where everything is within a single character cell.
1311
+         * If part of the Mesh Plot is outside of this character cell, we will follow up
1312
+         * and deal with that next.
1313
+         */
1314
+
1315
+        //dump_custom_char("at entry:", &new_char);
1316
+
1317
+        clear_custom_char(&new_char);
1318
+        const uint8_t ypix = min(upper_left.y_pixel_offset + pixels_per_y_mesh_pnt, ULTRA_Y_PIXELS_PER_CHAR);
1319
+        for (j = upper_left.y_pixel_offset; j < ypix; j++) {
1320
+          i = upper_left.x_pixel_mask;
1321
+          for (k = 0; k < pixels_per_x_mesh_pnt; k++) {
1338 1322
             new_char.custom_char_bits[j] |= i;
1339
-            i = i >> 1;
1323
+            i >>= 1;
1340 1324
           }
1341 1325
         }
1342
-        add_edges_to_custom_char(&new_char, &upper_left, &lower_right, &bottom_right_corner, TOP_RIGHT);
1326
+        //dump_custom_char("after loops:", &new_char);
1343 1327
 
1344
-        lcd.createChar(5, (uint8_t *) &new_char);
1328
+        add_edges_to_custom_char(&new_char, &upper_left, &lower_right, &bottom_right_corner, TOP_LEFT);
1329
+        //dump_custom_char("after add edges", &new_char);
1330
+        lcd.createChar(4, (uint8_t*)&new_char);
1345 1331
 
1346
-        lcd.setCursor(lower_right.column, upper_left.row);
1347
-        lcd.write(0x05);
1348
-      }
1332
+        lcd.setCursor(upper_left.column, upper_left.row);
1333
+        lcd.write(0x04);
1334
+        //dump_custom_char("after lcd update:", &new_char);
1349 1335
 
1350
-      /*
1351
-       * Next, check for two character cells stacked on top of each other being used to display the Mesh Point
1352
-       */
1353
-      if (upper_left.row+1 == lower_right.row) {
1354
-        l = ULTRA_Y_PIXELS_PER_CHAR - upper_left.y_pixel_offset;        // number of pixel rows in top character cell
1355
-        k = pixels_per_Y_mesh_pnt - l;                                  // number of pixel rows in bottom character cell
1356
-        CLEAR_CUSTOM_CHAR(&new_char);
1357
-        for(j=0; j<k; j++) {
1358
-          i=upper_left.x_pixel_mask;
1359
-          for(m=0; m<pixels_per_X_mesh_pnt; m++)  {                     // fill in the top side of the bottom character cell
1360
-            new_char.custom_char_bits[j] |= i;
1361
-            i = i >> 1;
1362
-            if (!i)
1363
-              break;
1336
+        /**
1337
+         * Next, check for two side by side character cells being used to display the Mesh Point
1338
+         * If found...  do the right hand character cell next.
1339
+         */
1340
+        if (upper_left.column == lower_right.column - 1) {
1341
+          l = upper_left.x_pixel_offset;
1342
+          clear_custom_char(&new_char);
1343
+          for (j = upper_left.y_pixel_offset; j < ypix; j++) {
1344
+            i = _BV(ULTRA_X_PIXELS_PER_CHAR - 1);                  // Fill in the left side of the right character cell
1345
+            for (k = 0; k < pixels_per_x_mesh_pnt - 1 - l; k++) {
1346
+              new_char.custom_char_bits[j] |= i;
1347
+              i >>= 1;
1348
+            }
1364 1349
           }
1365
-        }
1366
-        add_edges_to_custom_char(&new_char, &upper_left, &lower_right, &bottom_right_corner, LOWER_LEFT);
1367
-        lcd.createChar(6, (uint8_t *) &new_char);
1350
+          add_edges_to_custom_char(&new_char, &upper_left, &lower_right, &bottom_right_corner, TOP_RIGHT);
1368 1351
 
1369
-        lcd.setCursor(upper_left.column, lower_right.row);
1370
-        lcd.write(0x06);
1371
-      }
1352
+          lcd.createChar(5, (uint8_t *) &new_char);
1372 1353
 
1373
-      /*
1374
-       * Next, check for four character cells being used to display the Mesh Point.  If that is
1375
-       * what is here, we work to fill in the character cell that is down one and to the right one
1376
-       * from the upper_left character cell.
1377
-       */
1354
+          lcd.setCursor(lower_right.column, upper_left.row);
1355
+          lcd.write(0x05);
1356
+        }
1378 1357
 
1379
-      if (upper_left.column+1 == lower_right.column && upper_left.row+1 == lower_right.row) {
1380
-        l = ULTRA_Y_PIXELS_PER_CHAR - upper_left.y_pixel_offset;        // number of pixel rows in top character cell
1381
-        k = pixels_per_Y_mesh_pnt - l;                                  // number of pixel rows in bottom character cell
1382
-        CLEAR_CUSTOM_CHAR(&new_char);
1383
-        for (j = 0; j<k; j++) {
1384
-          l = upper_left.x_pixel_offset;
1385
-          i = 0x01 << (ULTRA_X_PIXELS_PER_CHAR - 1);                    // fill in the left side of the right character cell
1386
-          for (m = 0; m<pixels_per_X_mesh_pnt - 1 - l; m++) {           // fill in the top side of the bottom character cell
1387
-            new_char.custom_char_bits[j] |= i;
1388
-            i = i >> 1;
1358
+        /**
1359
+         * Next, check for two character cells stacked on top of each other being used to display the Mesh Point
1360
+         */
1361
+        if (upper_left.row == lower_right.row - 1) {
1362
+          l = ULTRA_Y_PIXELS_PER_CHAR - upper_left.y_pixel_offset;  // Number of pixel rows in top character cell
1363
+          k = pixels_per_y_mesh_pnt - l;                            // Number of pixel rows in bottom character cell
1364
+          clear_custom_char(&new_char);
1365
+          for (j = 0; j < k; j++) {
1366
+            i = upper_left.x_pixel_mask;
1367
+            for (m = 0; m < pixels_per_x_mesh_pnt; m++) {           // Fill in the top side of the bottom character cell
1368
+              new_char.custom_char_bits[j] |= i;
1369
+              if (!(i >>= 1)) break;
1370
+            }
1389 1371
           }
1372
+          add_edges_to_custom_char(&new_char, &upper_left, &lower_right, &bottom_right_corner, LOWER_LEFT);
1373
+          lcd.createChar(6, (uint8_t *) &new_char);
1374
+
1375
+          lcd.setCursor(upper_left.column, lower_right.row);
1376
+          lcd.write(0x06);
1390 1377
         }
1391
-        add_edges_to_custom_char(&new_char, &upper_left, &lower_right, &bottom_right_corner, LOWER_RIGHT);
1392
-        lcd.createChar(7, (uint8_t *) &new_char);
1393 1378
 
1394
-        lcd.setCursor(lower_right.column, lower_right.row);
1395
-        lcd.write(0x07);
1396
-      }
1379
+        /**
1380
+         * Next, check for four character cells being used to display the Mesh Point.  If that is
1381
+         * what is here, we work to fill in the character cell that is down one and to the right one
1382
+         * from the upper_left character cell.
1383
+         */
1384
+
1385
+        if (upper_left.column == lower_right.column - 1 && upper_left.row == lower_right.row - 1) {
1386
+          l = ULTRA_Y_PIXELS_PER_CHAR - upper_left.y_pixel_offset;   // Number of pixel rows in top character cell
1387
+          k = pixels_per_y_mesh_pnt - l;                             // Number of pixel rows in bottom character cell
1388
+          clear_custom_char(&new_char);
1389
+          for (j = 0; j < k; j++) {
1390
+            l = upper_left.x_pixel_offset;
1391
+            i = _BV(ULTRA_X_PIXELS_PER_CHAR - 1);                    // Fill in the left side of the right character cell
1392
+            for (m = 0; m < pixels_per_x_mesh_pnt - 1 - l; m++) {    // Fill in the top side of the bottom character cell
1393
+              new_char.custom_char_bits[j] |= i;
1394
+              i >>= 1;
1395
+            }
1396
+          }
1397
+          add_edges_to_custom_char(&new_char, &upper_left, &lower_right, &bottom_right_corner, LOWER_RIGHT);
1398
+          lcd.createChar(7, (uint8_t*)&new_char);
1397 1399
 
1398
-    #endif
1400
+          lcd.setCursor(lower_right.column, lower_right.row);
1401
+          lcd.write(0x07);
1402
+        }
1403
+
1404
+      #endif
1399 1405
 
1400 1406
       /**
1401 1407
        * Print plot position
@@ -1407,209 +1413,123 @@ static void lcd_implementation_status_screen() {
1407 1413
       lcd.print(inverted_y);
1408 1414
       lcd.write(')');
1409 1415
 
1410
-    #if LCD_HEIGHT <= 3   // 16x2 or 20x2 display
1416
+      #if LCD_HEIGHT <= 3   // 16x2 or 20x2 display
1411 1417
 
1412
-      /**
1413
-       * Print Z values
1414
-       */
1415
-      _ZLABEL(_LCD_W_POS, 1);
1416
-      if (!isnan(ubl.z_values[x][inverted_y]))
1417
-        lcd.print(ftostr43sign(ubl.z_values[x][inverted_y]));
1418
-      else
1419
-        lcd_printPGM(PSTR(" -----"));
1418
+        /**
1419
+         * Print Z values
1420
+         */
1421
+        _ZLABEL(_LCD_W_POS, 1);
1422
+        if (!isnan(ubl.z_values[x][inverted_y]))
1423
+          lcd.print(ftostr43sign(ubl.z_values[x][inverted_y]));
1424
+        else
1425
+          lcd_printPGM(PSTR(" -----"));
1426
+
1427
+      #else                 // 16x4 or 20x4 display
1428
+
1429
+        /**
1430
+         * Show all values at right of screen
1431
+         */
1432
+        _XLABEL(_LCD_W_POS, 1);
1433
+        lcd.print(ftostr32(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x]))));
1434
+        _YLABEL(_LCD_W_POS, 2);
1435
+        lcd.print(ftostr32(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[inverted_y]))));
1436
+
1437
+        /**
1438
+         * Show the location value
1439
+         */
1440
+        _ZLABEL(_LCD_W_POS, 3);
1441
+        if (!isnan(ubl.z_values[x][inverted_y]))
1442
+          lcd.print(ftostr43sign(ubl.z_values[x][inverted_y]));
1443
+        else
1444
+          lcd_printPGM(PSTR(" -----"));
1445
+
1446
+      #endif // LCD_HEIGHT > 3
1447
+    }
1420 1448
 
1421
-    #else                 // 16x4 or 20x4 display
1449
+    void add_edges_to_custom_char(custom_char * const custom, coordinate * const ul, coordinate * const lr, coordinate * const brc, uint8_t cell_location) {
1450
+      uint8_t i, k;
1451
+      int16_t n_rows = lr->row    - ul->row    + 1,
1452
+              n_cols = lr->column - ul->column + 1;
1422 1453
 
1423 1454
       /**
1424
-       * Show all values at right of screen
1455
+       * Check if Top line of box needs to be filled in
1425 1456
        */
1426
-      _XLABEL(_LCD_W_POS, 1);
1427
-      lcd.print(ftostr32(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x]))));
1428
-      _YLABEL(_LCD_W_POS, 2);
1429
-      lcd.print(ftostr32(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[inverted_y]))));
1457
+      if (ul->row == 0 && ((cell_location & TOP_LEFT) || (cell_location & TOP_RIGHT))) {   // Only fill in the top line for the top character cells
1458
+
1459
+        if (n_cols == 1) {
1460
+          if (ul->column != brc->column)
1461
+            custom->custom_char_bits[0] = 0xFF;                             // Single column in middle
1462
+          else
1463
+            for (i = brc->x_pixel_offset; i < ULTRA_X_PIXELS_PER_CHAR; i++) // Single column on right side
1464
+              SBI(custom->custom_char_bits[0], i);
1465
+        }
1466
+        else if ((cell_location & TOP_LEFT) || lr->column != brc->column)   // Multiple column in the middle or with right cell in middle
1467
+          custom->custom_char_bits[0] = 0xFF;
1468
+        else
1469
+          for (i = brc->x_pixel_offset; i < ULTRA_X_PIXELS_PER_CHAR; i++)
1470
+            SBI(custom->custom_char_bits[0], i);
1471
+      }
1430 1472
 
1431 1473
       /**
1432
-       * Show the location value
1474
+       * Check if left line of box needs to be filled in
1433 1475
        */
1434
-      _ZLABEL(_LCD_W_POS, 3);
1435
-      if (!isnan(ubl.z_values[x][inverted_y]))
1436
-        lcd.print(ftostr43sign(ubl.z_values[x][inverted_y]));
1437
-      else
1438
-        lcd_printPGM(PSTR(" -----"));
1439
-
1440
-    #endif // LCD_HEIGHT > 3
1441
-
1442
-    return;
1443
-  }
1444
-void add_edges_to_custom_char(struct custom_char *custom, struct coordinate *ul, struct coordinate *lr, struct coordinate *brc, unsigned char cell_location) {
1445
-  unsigned char i, k;
1446
-  int n_rows, n_cols;
1447
-
1448
-  n_rows = lr->row    - ul->row    + 1;
1449
-  n_cols = lr->column - ul->column + 1;
1476
+      if ((cell_location & TOP_LEFT) || (cell_location & LOWER_LEFT)) {
1477
+        if (ul->column == 0) {                                              // Left column of characters on LCD Display
1478
+          k = ul->row == brc->row ? brc->y_pixel_offset : ULTRA_Y_PIXELS_PER_CHAR; // If it isn't the last row... do the full character cell
1479
+          for (i = 0; i < k; i++)
1480
+            SBI(custom->custom_char_bits[i], ULTRA_X_PIXELS_PER_CHAR - 1);
1481
+        }
1482
+      }
1450 1483
 
1451
-  /*
1452
-   * Check if Top line of box needs to be filled in
1453
-   */
1454
-  if ((ul->row == 0) && ((cell_location&TOP_LEFT) || (cell_location&TOP_RIGHT))) {   // Only fill in the top line for the top character cells
1484
+      /**
1485
+       * Check if bottom line of box needs to be filled in
1486
+       */
1455 1487
 
1456
-    if (n_cols == 1)  {
1457
-      if (ul->column != brc->column)
1458
-        custom->custom_char_bits[0] = 0xff;                              // single column in middle
1459
-      else {
1460
-        for (i = brc->x_pixel_offset; i<ULTRA_X_PIXELS_PER_CHAR; i++)    // single column on right side
1461
-          custom->custom_char_bits[0] |= 0x01 << i;
1462
-      }
1463
-    } 
1464
-    else {                                                            
1465
-      if (cell_location & TOP_LEFT)
1466
-        custom->custom_char_bits[0] = 0xff;                              // multiple column in the middle
1467
-      else
1468
-        if (lr->column != brc->column)                                     
1469
-          custom->custom_char_bits[0] = 0xff;                            // multiple column with right cell in middle
1470
-        else {
1471
-          for (i = brc->x_pixel_offset; i<ULTRA_X_PIXELS_PER_CHAR; i++)
1472
-            custom->custom_char_bits[0] |= 0x01 << i;
1488
+      // Single row of mesh plot cells
1489
+      if (n_rows == 1 /* && (cell_location == TOP_LEFT || cell_location == TOP_RIGHT) */ && ul->row == brc->row) {
1490
+        if (n_cols == 1)                                                    // Single row, single column case
1491
+          k = ul->column == brc->column ? brc->x_pixel_mask : 0x01;
1492
+        else if (cell_location & TOP_RIGHT)                                 // Single row, multiple column case
1493
+          k = lr->column == brc->column ? brc->x_pixel_mask : 0x01;
1494
+        else                                                                // Single row, left of multiple columns
1495
+          k = 0x01;
1496
+        while (k < _BV(ULTRA_X_PIXELS_PER_CHAR)) {
1497
+          custom->custom_char_bits[brc->y_pixel_offset] |= k;
1498
+          k <<= 1;
1473 1499
         }
1474
-    }
1475
-  }
1500
+      }
1476 1501
 
1477
-  /*
1478
-   * Check if left line of box needs to be filled in
1479
-   */
1480
-  if ((cell_location & TOP_LEFT) || (cell_location & LOWER_LEFT)) {
1481
-    if (ul->column == 0) {                          // Left column of characters on LCD Display
1482
-      if (ul->row != brc->row)
1483
-        k = ULTRA_Y_PIXELS_PER_CHAR;      // if it isn't the last row... do the full character cell
1484
-      else
1485
-        k = brc->y_pixel_offset;
1502
+      // Double row of characters on LCD Display
1503
+      // And this is a bottom custom character
1504
+      if (n_rows == 2 && (cell_location == LOWER_LEFT || cell_location == LOWER_RIGHT) && lr->row == brc->row) {
1505
+        if (n_cols == 1)                                                  // Double row, single column case
1506
+          k = ul->column == brc->column ? brc->x_pixel_mask : 0x01;
1507
+        else if (cell_location & LOWER_RIGHT)                             // Double row, multiple column case
1508
+          k = lr->column == brc->column ? brc->x_pixel_mask : 0x01;
1509
+        else                                                              // Double row, left of multiple columns
1510
+          k = 0x01;
1511
+        while (k < _BV(ULTRA_X_PIXELS_PER_CHAR)) {
1512
+          custom->custom_char_bits[brc->y_pixel_offset] |= k;
1513
+          k <<= 1;
1514
+        }
1515
+      }
1486 1516
 
1487
-      for (i = 0; i < k; i++)
1488
-        custom->custom_char_bits[i] |= 0x01 << (ULTRA_X_PIXELS_PER_CHAR - 1);
1517
+      /**
1518
+       * Check if right line of box needs to be filled in
1519
+       */
1520
+      // Nothing to do if the lower right part of the mesh pnt isn't in the same column as the box line
1521
+      if (lr->column == brc->column) {
1522
+        // This mesh point is in the same character cell as the right box line
1523
+        if (ul->column == brc->column || (cell_location & TOP_RIGHT) || (cell_location & LOWER_RIGHT)) {
1524
+          // If not the last row... do the full character cell
1525
+          k = ul->row == brc->row ? brc->y_pixel_offset : ULTRA_Y_PIXELS_PER_CHAR;
1526
+          for (i = 0; i < k; i++) custom->custom_char_bits[i] |= brc->x_pixel_mask;
1527
+        }
1528
+      }
1489 1529
     }
1490
-  }
1491
-
1492
-  /*
1493
-   * Check if bottom line of box needs to be filled in
1494
-   */
1495
-
1496
-   // Single row of mesh plot cells
1497
-   if ((n_rows==1) /* && ((cell_location == TOP_LEFT) || (cell_location==TOP_RIGHT)) */) {
1498
-     if (ul->row == brc->row)  {
1499
-       if (n_cols == 1) {                 // single row, single column case
1500
-          if (ul->column != brc->column) 
1501
-            k = 0x01;
1502
-          else 
1503
-            k = brc->x_pixel_mask;
1504
-       } else {
1505
-          if (cell_location & TOP_RIGHT) {  // single row, multiple column case
1506
-            if(lr->column != brc->column)   
1507
-              k = 0x01;
1508
-            else 
1509
-              k = brc->x_pixel_mask;
1510
-          } else                            // single row, left of multiple columns
1511
-            k = 0x01;
1512
-       }
1513
-       while (k < (0x01 << ULTRA_X_PIXELS_PER_CHAR)) {
1514
-         custom->custom_char_bits[brc->y_pixel_offset] |= k;
1515
-         k = k << 1;
1516
-       }
1517
-     }
1518
-   }
1519
-
1520
-
1521
-  // Double row of characters on LCD Display
1522
-  // And this is a bottom custom character
1523
-   if ((n_rows==2) && ((cell_location == LOWER_LEFT) || (cell_location==LOWER_RIGHT))) {
1524
-     if (lr->row == brc->row)  {
1525
-       if (n_cols == 1) {                 // double row, single column case
1526
-          if (ul->column != brc->column) 
1527
-            k = 0x01;
1528
-          else 
1529
-            k = brc->x_pixel_mask;
1530
-       } else {
1531
-          if (cell_location & LOWER_RIGHT) {  // double row, multiple column case
1532
-            if(lr->column != brc->column)   
1533
-              k = 0x01;
1534
-            else 
1535
-              k = brc->x_pixel_mask;
1536
-          } else                            // double row, left of multiple columns
1537
-            k = 0x01;
1538
-       }
1539
-       while (k < (0x01 << ULTRA_X_PIXELS_PER_CHAR)) {
1540
-         custom->custom_char_bits[brc->y_pixel_offset] |= k;
1541
-         k = k << 1;
1542
-       }
1543
-     }
1544
-   }
1545
-
1546
-   /*
1547
-    * Check if right line of box needs to be filled in
1548
-    */
1549
-
1550
-   if (lr->column == brc->column) {     // nothing to do if the lower right part of the mesh pnt isn't in the same column as the box line
1551
-     if ((ul->column == brc->column) ||
1552
-        ((lr->column == brc->column) && (cell_location&TOP_RIGHT)) ||
1553
-        ((lr->column == brc->column) && (cell_location&LOWER_RIGHT))) {   // This mesh point is in the same character cell as the right box line
1554
-
1555
-       if (ul->row != brc->row)
1556
-         k = ULTRA_Y_PIXELS_PER_CHAR;      // if it isn't the last row... do the full character cell
1557
-       else
1558
-         k = brc->y_pixel_offset;
1559
-
1560
-       for (i = 0; i < k; i++)
1561
-         custom->custom_char_bits[i] |= brc->x_pixel_mask;
1562
-     }
1563
-   }
1564
- }
1565
-
1566
-  struct coordinate pixel_location(int x, int y) {
1567
-    struct coordinate ret_val;
1568
-    int xp, yp, r, c;
1569 1530
 
1570
-    x++;  // +1 because there is a line on the left 
1571
-    y++;  // and a line at the top to make the box
1531
+  #endif // AUTO_BED_LEVELING_UBL
1572 1532
 
1573
-    c = x / ULTRA_X_PIXELS_PER_CHAR;
1574
-    r = y / ULTRA_Y_PIXELS_PER_CHAR;
1575
-
1576
-    ret_val.column = c;
1577
-    ret_val.row    = r;
1578
-
1579
-    xp = x - c * ULTRA_X_PIXELS_PER_CHAR;   // get the pixel offsets into the character cell
1580
-    xp = ULTRA_X_PIXELS_PER_CHAR - 1 - xp;  // column within relivant character cell (0 on the right)
1581
-    yp = y - r * ULTRA_Y_PIXELS_PER_CHAR;
1582
-
1583
-    ret_val.x_pixel_mask   = 0x01 << xp;
1584
-    ret_val.x_pixel_offset = xp;
1585
-    ret_val.y_pixel_offset = yp;
1586
-    return ret_val;
1587
-  }
1588
-
1589
-  struct coordinate pixel_location(uint8_t x, uint8_t y) {
1590
-    struct coordinate ret_val;
1591
-    uint8_t xp, yp, r, c;
1592
-
1593
-    x++;  // +1 because there is a line on the left
1594
-    y++;  // and a line at the top to make the box
1595
-
1596
-    c = x / ULTRA_X_PIXELS_PER_CHAR;
1597
-    r = y / ULTRA_Y_PIXELS_PER_CHAR;
1598
-
1599
-    ret_val.column = c;
1600
-    ret_val.row    = r;
1601
-
1602
-    xp = x - c * ULTRA_X_PIXELS_PER_CHAR;   // get the pixel offsets into the character cell
1603
-    xp = ULTRA_X_PIXELS_PER_CHAR - 1 - xp;  // column within relivant character cell (0 on the right)
1604
-    yp = y - r * ULTRA_Y_PIXELS_PER_CHAR;
1605
-
1606
-    ret_val.x_pixel_mask   = 0x01 << xp;
1607
-    ret_val.x_pixel_offset = xp;
1608
-    ret_val.y_pixel_offset = yp;
1609
-
1610
-    return ret_val;
1611
-  }
1612
-
1613
-#endif // AUTO_BED_LEVELING_UBL
1533
+#endif // ULTIPANEL
1614 1534
 
1615 1535
 #endif // ULTRALCD_IMPL_HD44780_H

Loading…
Cancelar
Guardar