Browse Source

Simplify counting of printable characters

Scott Lahteine 8 years ago
parent
commit
4a96433b7e
3 changed files with 10 additions and 18 deletions
  1. 0
    1
      Marlin/macros.h
  2. 3
    15
      Marlin/ultralcd.cpp
  3. 7
    2
      Marlin/utf_mapper.h

+ 0
- 1
Marlin/macros.h View File

127
 #define DECIMAL(a) (NUMERIC(a) || a == '.')
127
 #define DECIMAL(a) (NUMERIC(a) || a == '.')
128
 #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-' || (a) == '+')
128
 #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-' || (a) == '+')
129
 #define DECIMAL_SIGNED(a) (DECIMAL(a) || (a) == '-' || (a) == '+')
129
 #define DECIMAL_SIGNED(a) (DECIMAL(a) || (a) == '-' || (a) == '+')
130
-#define PRINTABLE(C) (((C) & 0xC0u) != 0x80u)
131
 #define COUNT(a) (sizeof(a)/sizeof(*a))
130
 #define COUNT(a) (sizeof(a)/sizeof(*a))
132
 #define ZERO(a) memset(a,0,sizeof(a))
131
 #define ZERO(a) memset(a,0,sizeof(a))
133
 #define COPY(a,b) memcpy(a,b,min(sizeof(a),sizeof(b)))
132
 #define COPY(a,b) memcpy(a,b,min(sizeof(a),sizeof(b)))

+ 3
- 15
Marlin/ultralcd.cpp View File

3885
 int lcd_strlen(const char* s) {
3885
 int lcd_strlen(const char* s) {
3886
   int i = 0, j = 0;
3886
   int i = 0, j = 0;
3887
   while (s[i]) {
3887
   while (s[i]) {
3888
-    #if ENABLED(MAPPER_NON)
3889
-      j++;
3890
-    #else
3891
-      if (PRINTABLE(s[i])) j++;
3892
-    #endif
3888
+    if (PRINTABLE(s[i])) j++;
3893
     i++;
3889
     i++;
3894
   }
3890
   }
3895
   return j;
3891
   return j;
3898
 int lcd_strlen_P(const char* s) {
3894
 int lcd_strlen_P(const char* s) {
3899
   int j = 0;
3895
   int j = 0;
3900
   while (pgm_read_byte(s)) {
3896
   while (pgm_read_byte(s)) {
3901
-    #if ENABLED(MAPPER_NON)
3902
-      j++;
3903
-    #else
3904
-      if (PRINTABLE(pgm_read_byte(s))) j++;
3905
-    #endif
3897
+    if (PRINTABLE(pgm_read_byte(s))) j++;
3906
     s++;
3898
     s++;
3907
   }
3899
   }
3908
   return j;
3900
   return j;
4167
   void set_utf_strlen(char* s, uint8_t n) {
4159
   void set_utf_strlen(char* s, uint8_t n) {
4168
     uint8_t i = 0, j = 0;
4160
     uint8_t i = 0, j = 0;
4169
     while (s[i] && (j < n)) {
4161
     while (s[i] && (j < n)) {
4170
-      #if ENABLED(MAPPER_NON)
4171
-        j++;
4172
-      #else
4173
-        if (PRINTABLE(s[i])) j++;
4174
-      #endif
4162
+      if (PRINTABLE(s[i])) j++;
4175
       i++;
4163
       i++;
4176
     }
4164
     }
4177
     while (j++ < n) s[i++] = ' ';
4165
     while (j++ < n) s[i++] = ' ';

+ 7
- 2
Marlin/utf_mapper.h View File

23
 #ifndef UTF_MAPPER_H
23
 #ifndef UTF_MAPPER_H
24
 #define UTF_MAPPER_H
24
 #define UTF_MAPPER_H
25
 
25
 
26
-#include  "language.h"
26
+#include "language.h"
27
 
27
 
28
 #if ENABLED(DOGLCD)
28
 #if ENABLED(DOGLCD)
29
   #define HARDWARE_CHAR_OUT u8g.print
29
   #define HARDWARE_CHAR_OUT u8g.print
144
   #endif // DISPLAY_CHARSET_HD44780
144
   #endif // DISPLAY_CHARSET_HD44780
145
 #endif // SIMULATE_ROMFONT
145
 #endif // SIMULATE_ROMFONT
146
 
146
 
147
+#define PRINTABLE(C) (((C) & 0xC0u) != 0x80u)
148
+
147
 #if ENABLED(MAPPER_C2C3)
149
 #if ENABLED(MAPPER_C2C3)
148
 
150
 
149
   char charset_mapper(const char c) {
151
   char charset_mapper(const char c) {
466
 
468
 
467
   #define MAPPER_NON
469
   #define MAPPER_NON
468
 
470
 
471
+  #undef PRINTABLE
472
+  #define PRINTABLE(C) true
473
+
469
   char charset_mapper(const char c) {
474
   char charset_mapper(const char c) {
470
-    HARDWARE_CHAR_OUT( c );
475
+    HARDWARE_CHAR_OUT(c);
471
     return 1;
476
     return 1;
472
   }
477
   }
473
 
478
 

Loading…
Cancel
Save