Consistent static/value item macros

This commit is contained in:
Scott Lahteine 2020-08-23 00:12:03 -05:00
parent db04bcb727
commit e7b730528e
3 changed files with 45 additions and 35 deletions

View File

@ -73,7 +73,7 @@ int pf_bsearch_r(void *userdata, size_t num_data, pf_bsearch_cb_comp_t cb_comp,
return -1; return -1;
} }
/* This function gets the character at the pstart position, interpreting UTF8 multybyte sequences /* This function gets the character at the pstart position, interpreting UTF8 multibyte sequences
and returns the pointer to the next character */ and returns the pointer to the next character */
uint8_t* get_utf8_value_cb(uint8_t *pstart, read_byte_cb_t cb_read_byte, wchar_t *pval) { uint8_t* get_utf8_value_cb(uint8_t *pstart, read_byte_cb_t cb_read_byte, wchar_t *pval) {
uint32_t val = 0; uint32_t val = 0;
@ -161,7 +161,6 @@ uint8_t* get_utf8_value_cb(uint8_t *pstart, read_byte_cb_t cb_read_byte, wchar_t
} }
static inline uint8_t utf8_strlen_cb(const char *pstart, read_byte_cb_t cb_read_byte) { static inline uint8_t utf8_strlen_cb(const char *pstart, read_byte_cb_t cb_read_byte) {
uint8_t cnt = 0; uint8_t cnt = 0;
uint8_t *pnext = (uint8_t *)pstart; uint8_t *pnext = (uint8_t *)pstart;
for (;;) { for (;;) {

View File

@ -34,9 +34,6 @@
#include "game/game.h" #include "game/game.h"
#endif #endif
#define VALUE_ITEM(MSG, VALUE, STYL) do{ char msg[21]; strcpy_P(msg, PSTR(": ")); strcpy(msg + 2, VALUE); STATIC_ITEM(MSG, STYL, msg); }while(0)
#define VALUE_ITEM_P(MSG, PVALUE, STYL) do{ char msg[21]; strcpy_P(msg, PSTR(": ")); strcpy_P(msg + 2, PSTR(PVALUE)); STATIC_ITEM(MSG, STYL, msg); }while(0)
#if ENABLED(PRINTCOUNTER) #if ENABLED(PRINTCOUNTER)
#include "../../module/printcounter.h" #include "../../module/printcounter.h"
@ -52,14 +49,14 @@
char buffer[21]; char buffer[21];
START_SCREEN(); // 12345678901234567890 START_SCREEN(); // 12345678901234567890
VALUE_ITEM(MSG_INFO_PRINT_COUNT, i16tostr3left(stats.totalPrints), SS_LEFT); // Print Count: 999 STATIC_ITEM(MSG_INFO_PRINT_COUNT, SS_LEFT, i16tostr3left(stats.totalPrints)); // Print Count: 999
VALUE_ITEM(MSG_INFO_COMPLETED_PRINTS, i16tostr3left(stats.finishedPrints), SS_LEFT); // Completed : 666 STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS, SS_LEFT, i16tostr3left(stats.finishedPrints)); // Completed : 666
STATIC_ITEM(MSG_INFO_PRINT_TIME, SS_LEFT); // Total print Time: STATIC_ITEM(MSG_INFO_PRINT_TIME, SS_LEFT); // Total print Time:
STATIC_ITEM_P(PSTR("> "), SS_LEFT, duration_t(stats.printTime).toString(buffer)); // > 99y 364d 23h 59m 59s STATIC_ITEM_P(PSTR("> "), SS_LEFT, duration_t(stats.printTime).toString(buffer)); // > 99y 364d 23h 59m 59s
STATIC_ITEM(MSG_INFO_PRINT_LONGEST, SS_LEFT); // Longest job time: STATIC_ITEM(MSG_INFO_PRINT_LONGEST, SS_LEFT); // Longest job time:
STATIC_ITEM_P(PSTR("> "), SS_LEFT, duration_t(stats.longestPrint).toString(buffer)); // > 99y 364d 23h 59m 59s STATIC_ITEM_P(PSTR("> "), SS_LEFT, duration_t(stats.longestPrint).toString(buffer)); // > 99y 364d 23h 59m 59s
STATIC_ITEM(MSG_INFO_PRINT_FILAMENT, SS_LEFT); // Extruded total: STATIC_ITEM(MSG_INFO_PRINT_FILAMENT, SS_LEFT); // Extruded total:
sprintf_P(buffer, PSTR("%ld.%im") sprintf_P(buffer, PSTR("%ld.%im")
@ -73,8 +70,8 @@
#endif #endif
#if SERVICE_INTERVAL_1 > 0 #if SERVICE_INTERVAL_1 > 0
STATIC_ITEM_P(PSTR(SERVICE_NAME_1 " "), SS_LEFT, buffer); // Service X in: STATIC_ITEM_P(PSTR(SERVICE_NAME_1 " "), SS_LEFT, buffer); // Service X in:
STATIC_ITEM_P(PSTR("> "), SS_LEFT, duration_t(stats.nextService1).toString(buffer)); // > 7d 12h 11m 10s STATIC_ITEM_P(PSTR("> "), SS_LEFT, duration_t(stats.nextService1).toString(buffer)); // > 7d 12h 11m 10s
#endif #endif
#if SERVICE_INTERVAL_2 > 0 #if SERVICE_INTERVAL_2 > 0
@ -104,8 +101,8 @@ void menu_info_thermistors() {
#define THERMISTOR_ID TEMP_SENSOR_0 #define THERMISTOR_ID TEMP_SENSOR_0
#include "../thermistornames.h" #include "../thermistornames.h"
STATIC_ITEM_P(PSTR(LCD_STR_E0 ": " THERMISTOR_NAME), SS_INVERT); STATIC_ITEM_P(PSTR(LCD_STR_E0 ": " THERMISTOR_NAME), SS_INVERT);
VALUE_ITEM_P(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_0_MINTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_0_MINTEMP), SS_LEFT);
VALUE_ITEM_P(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_0_MAXTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_0_MAXTEMP), SS_LEFT);
#endif #endif
#if TEMP_SENSOR_1 != 0 #if TEMP_SENSOR_1 != 0
@ -113,8 +110,8 @@ void menu_info_thermistors() {
#define THERMISTOR_ID TEMP_SENSOR_1 #define THERMISTOR_ID TEMP_SENSOR_1
#include "../thermistornames.h" #include "../thermistornames.h"
STATIC_ITEM_P(PSTR(LCD_STR_E1 ": " THERMISTOR_NAME), SS_INVERT); STATIC_ITEM_P(PSTR(LCD_STR_E1 ": " THERMISTOR_NAME), SS_INVERT);
VALUE_ITEM_P(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_1_MINTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_1_MINTEMP), SS_LEFT);
VALUE_ITEM_P(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_1_MAXTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_1_MAXTEMP), SS_LEFT);
#endif #endif
#if TEMP_SENSOR_2 != 0 #if TEMP_SENSOR_2 != 0
@ -122,8 +119,8 @@ void menu_info_thermistors() {
#define THERMISTOR_ID TEMP_SENSOR_2 #define THERMISTOR_ID TEMP_SENSOR_2
#include "../thermistornames.h" #include "../thermistornames.h"
STATIC_ITEM_P(PSTR(LCD_STR_E2 ": " THERMISTOR_NAME), SS_INVERT); STATIC_ITEM_P(PSTR(LCD_STR_E2 ": " THERMISTOR_NAME), SS_INVERT);
VALUE_ITEM_P(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_2_MINTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_2_MINTEMP), SS_LEFT);
VALUE_ITEM_P(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_2_MAXTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_2_MAXTEMP), SS_LEFT);
#endif #endif
#if TEMP_SENSOR_3 != 0 #if TEMP_SENSOR_3 != 0
@ -131,8 +128,8 @@ void menu_info_thermistors() {
#define THERMISTOR_ID TEMP_SENSOR_3 #define THERMISTOR_ID TEMP_SENSOR_3
#include "../thermistornames.h" #include "../thermistornames.h"
STATIC_ITEM_P(PSTR(LCD_STR_E3 ": " THERMISTOR_NAME), SS_INVERT); STATIC_ITEM_P(PSTR(LCD_STR_E3 ": " THERMISTOR_NAME), SS_INVERT);
VALUE_ITEM_P(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_3_MINTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_3_MINTEMP), SS_LEFT);
VALUE_ITEM_P(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_3_MAXTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_3_MAXTEMP), SS_LEFT);
#endif #endif
#if TEMP_SENSOR_4 != 0 #if TEMP_SENSOR_4 != 0
@ -140,8 +137,8 @@ void menu_info_thermistors() {
#define THERMISTOR_ID TEMP_SENSOR_4 #define THERMISTOR_ID TEMP_SENSOR_4
#include "../thermistornames.h" #include "../thermistornames.h"
STATIC_ITEM_P(PSTR(LCD_STR_E4 ": " THERMISTOR_NAME), SS_INVERT); STATIC_ITEM_P(PSTR(LCD_STR_E4 ": " THERMISTOR_NAME), SS_INVERT);
VALUE_ITEM_P(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_4_MINTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_4_MINTEMP), SS_LEFT);
VALUE_ITEM_P(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_4_MAXTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_4_MAXTEMP), SS_LEFT);
#endif #endif
#if TEMP_SENSOR_5 != 0 #if TEMP_SENSOR_5 != 0
@ -149,8 +146,8 @@ void menu_info_thermistors() {
#define THERMISTOR_ID TEMP_SENSOR_5 #define THERMISTOR_ID TEMP_SENSOR_5
#include "../thermistornames.h" #include "../thermistornames.h"
STATIC_ITEM_P(PSTR(LCD_STR_E5 ": " THERMISTOR_NAME), SS_INVERT); STATIC_ITEM_P(PSTR(LCD_STR_E5 ": " THERMISTOR_NAME), SS_INVERT);
VALUE_ITEM_P(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_5_MINTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_5_MINTEMP), SS_LEFT);
VALUE_ITEM_P(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_5_MAXTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_5_MAXTEMP), SS_LEFT);
#endif #endif
#if TEMP_SENSOR_6 != 0 #if TEMP_SENSOR_6 != 0
@ -158,8 +155,8 @@ void menu_info_thermistors() {
#define THERMISTOR_ID TEMP_SENSOR_6 #define THERMISTOR_ID TEMP_SENSOR_6
#include "../thermistornames.h" #include "../thermistornames.h"
STATIC_ITEM_P(PSTR(LCD_STR_E6 ": " THERMISTOR_NAME), SS_INVERT); STATIC_ITEM_P(PSTR(LCD_STR_E6 ": " THERMISTOR_NAME), SS_INVERT);
VALUE_ITEM_P(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_6_MINTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_6_MINTEMP), SS_LEFT);
VALUE_ITEM_P(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_6_MAXTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_6_MAXTEMP), SS_LEFT);
#endif #endif
#if TEMP_SENSOR_7 != 0 #if TEMP_SENSOR_7 != 0
@ -167,8 +164,8 @@ void menu_info_thermistors() {
#define THERMISTOR_ID TEMP_SENSOR_7 #define THERMISTOR_ID TEMP_SENSOR_7
#include "../thermistornames.h" #include "../thermistornames.h"
STATIC_ITEM_P(PSTR(LCD_STR_E7 ": " THERMISTOR_NAME), SS_INVERT); STATIC_ITEM_P(PSTR(LCD_STR_E7 ": " THERMISTOR_NAME), SS_INVERT);
VALUE_ITEM_P(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_7_MINTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MIN_TEMP, STRINGIFY(HEATER_7_MINTEMP), SS_LEFT);
VALUE_ITEM_P(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_7_MAXTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MAX_TEMP, STRINGIFY(HEATER_7_MAXTEMP), SS_LEFT);
#endif #endif
#if EXTRUDERS #if EXTRUDERS
@ -180,8 +177,8 @@ void menu_info_thermistors() {
#define THERMISTOR_ID TEMP_SENSOR_BED #define THERMISTOR_ID TEMP_SENSOR_BED
#include "../thermistornames.h" #include "../thermistornames.h"
STATIC_ITEM_P(PSTR("BED:" THERMISTOR_NAME), SS_INVERT); STATIC_ITEM_P(PSTR("BED:" THERMISTOR_NAME), SS_INVERT);
VALUE_ITEM_P(MSG_INFO_MIN_TEMP, STRINGIFY(BED_MINTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MIN_TEMP, STRINGIFY(BED_MINTEMP), SS_LEFT);
VALUE_ITEM_P(MSG_INFO_MAX_TEMP, STRINGIFY(BED_MAXTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MAX_TEMP, STRINGIFY(BED_MAXTEMP), SS_LEFT);
STATIC_ITEM(TERN(WATCH_BED, MSG_INFO_RUNAWAY_ON, MSG_INFO_RUNAWAY_OFF), SS_LEFT); STATIC_ITEM(TERN(WATCH_BED, MSG_INFO_RUNAWAY_ON, MSG_INFO_RUNAWAY_OFF), SS_LEFT);
#endif #endif
@ -190,8 +187,8 @@ void menu_info_thermistors() {
#define THERMISTOR_ID TEMP_SENSOR_CHAMBER #define THERMISTOR_ID TEMP_SENSOR_CHAMBER
#include "../thermistornames.h" #include "../thermistornames.h"
STATIC_ITEM_P(PSTR("CHAM:" THERMISTOR_NAME), SS_INVERT); STATIC_ITEM_P(PSTR("CHAM:" THERMISTOR_NAME), SS_INVERT);
VALUE_ITEM_P(MSG_INFO_MIN_TEMP, STRINGIFY(CHAMBER_MINTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MIN_TEMP, STRINGIFY(CHAMBER_MINTEMP), SS_LEFT);
VALUE_ITEM_P(MSG_INFO_MAX_TEMP, STRINGIFY(CHAMBER_MAXTEMP), SS_LEFT); PSTRING_ITEM(MSG_INFO_MAX_TEMP, STRINGIFY(CHAMBER_MAXTEMP), SS_LEFT);
STATIC_ITEM(TERN(WATCH_CHAMBER, MSG_INFO_RUNAWAY_ON, MSG_INFO_RUNAWAY_OFF), SS_LEFT); STATIC_ITEM(TERN(WATCH_CHAMBER, MSG_INFO_RUNAWAY_ON, MSG_INFO_RUNAWAY_OFF), SS_LEFT);
#endif #endif
@ -209,9 +206,9 @@ void menu_info_board() {
#ifdef BOARD_WEBSITE_URL #ifdef BOARD_WEBSITE_URL
STATIC_ITEM_P(PSTR(BOARD_WEBSITE_URL), SS_LEFT); // www.my3dprinter.com STATIC_ITEM_P(PSTR(BOARD_WEBSITE_URL), SS_LEFT); // www.my3dprinter.com
#endif #endif
VALUE_ITEM_P(MSG_INFO_BAUDRATE, STRINGIFY(BAUDRATE), SS_CENTER); // Baud: 250000 PSTRING_ITEM(MSG_INFO_BAUDRATE, STRINGIFY(BAUDRATE), SS_CENTER); // Baud: 250000
VALUE_ITEM_P(MSG_INFO_PROTOCOL, PROTOCOL_VERSION, SS_CENTER); // Protocol: 1.0 PSTRING_ITEM(MSG_INFO_PROTOCOL, PROTOCOL_VERSION, SS_CENTER); // Protocol: 1.0
VALUE_ITEM_P(MSG_INFO_PSU, PSU_NAME, SS_CENTER); PSTRING_ITEM(MSG_INFO_PSU, PSU_NAME, SS_CENTER);
END_SCREEN(); END_SCREEN();
} }
@ -242,7 +239,7 @@ void menu_info_board() {
STATIC_ITEM_P(PSTR(STRING_DISTRIBUTION_DATE)); // YYYY-MM-DD HH:MM STATIC_ITEM_P(PSTR(STRING_DISTRIBUTION_DATE)); // YYYY-MM-DD HH:MM
STATIC_ITEM_P(PSTR(MACHINE_NAME)); // My3DPrinter STATIC_ITEM_P(PSTR(MACHINE_NAME)); // My3DPrinter
STATIC_ITEM_P(PSTR(WEBSITE_URL)); // www.my3dprinter.com STATIC_ITEM_P(PSTR(WEBSITE_URL)); // www.my3dprinter.com
VALUE_ITEM_P(MSG_INFO_EXTRUDERS, STRINGIFY(EXTRUDERS), SS_CENTER); // Extruders: 2 PSTRING_ITEM(MSG_INFO_EXTRUDERS, STRINGIFY(EXTRUDERS), SS_CENTER); // Extruders: 2
#if HAS_LEVELING #if HAS_LEVELING
STATIC_ITEM( STATIC_ITEM(
TERN_(AUTO_BED_LEVELING_3POINT, MSG_3POINT_LEVELING) // 3-Point Leveling TERN_(AUTO_BED_LEVELING_3POINT, MSG_3POINT_LEVELING) // 3-Point Leveling

View File

@ -328,6 +328,20 @@ class MenuItem_bool : public MenuEditItemBase {
NEXT_ITEM(); \ NEXT_ITEM(); \
}while(0) }while(0)
// PSTRING_ITEM is like STATIC_ITEM but it takes
// two PSTRs with the style as the last parameter.
#define PSTRING_ITEM_P(PLABEL, PVAL, STYL) do{ \
constexpr int m = 20; \
char msg[m+1]; \
msg[0] = ':'; msg[1] = ' '; \
strncpy_P(msg+2, PSTR(PVAL), m-2); \
if (msg[m-1] & 0x80) msg[m-1] = '\0'; \
STATIC_ITEM_P(PLABEL, STYL, msg); \
}while(0)
#define PSTRING_ITEM(LABEL, V...) PSTRING_ITEM_P(GET_TEXT(LABEL), ##V)
#define STATIC_ITEM(LABEL, V...) STATIC_ITEM_P(GET_TEXT(LABEL), ##V) #define STATIC_ITEM(LABEL, V...) STATIC_ITEM_P(GET_TEXT(LABEL), ##V)
#define STATIC_ITEM_N(LABEL, N, V...) STATIC_ITEM_N_P(GET_TEXT(LABEL), ##V) #define STATIC_ITEM_N(LABEL, N, V...) STATIC_ITEM_N_P(GET_TEXT(LABEL), ##V)