static char* lcd_sd_menu_filename_callback(uint8_t nr) { //This code uses the card.longFilename as buffer to store the filename, to save memory. if (nr == 0) { if (card.atRoot()) { strcpy_P(card.longFilename, PSTR("< RETURN")); }else{ strcpy_P(card.longFilename, PSTR("< BACK")); } }else{ card.longFilename[0] = '\0'; for(uint8_t idx=0; idx<LCD_CACHE_COUNT; idx++) { if (LCD_CACHE_ID(idx) == nr) strcpy(card.longFilename, LCD_CACHE_FILENAME(idx)); } if (card.longFilename[0] == '\0') { card.getfilename(nr - 1); if (!card.longFilename[0]) strcpy(card.longFilename, card.filename); if (!card.filenameIsDir) { if (strchr(card.longFilename, '.')) strrchr(card.longFilename, '.')[0] = '\0'; } uint8_t idx = nr % LCD_CACHE_COUNT; LCD_CACHE_ID(idx) = nr; strcpy(LCD_CACHE_FILENAME(idx), card.longFilename); LCD_CACHE_TYPE(idx) = card.filenameIsDir ? 1 : 0; if (card.errorCode() && card.sdInserted) { //On a read error reset the file position and try to keep going. (not pretty, but these read errors are annoying as hell) card.clearError(); LCD_CACHE_ID(idx) = 255; card.longFilename[0] = '\0'; } } } return card.longFilename; }
void lcd_sd_menu_details_callback(uint8_t nr) { if (nr == 0) { return; } for(uint8_t idx=0; idx<LCD_CACHE_COUNT; idx++) { if (LCD_CACHE_ID(idx) == nr) { if (LCD_CACHE_TYPE(idx) == 1) { lcd_lib_draw_string_centerP(53, PSTR("Folder")); }else{ char buffer[64]; if (LCD_DETAIL_CACHE_ID() != nr) { card.getfilename(nr - 1); if (card.errorCode()) { card.clearError(); return; } LCD_DETAIL_CACHE_ID() = nr; LCD_DETAIL_CACHE_TIME() = 0; for(uint8_t e=0; e<EXTRUDERS; e++) LCD_DETAIL_CACHE_MATERIAL(e) = 0; card.openFile(card.filename, true); if (card.isFileOpen()) { for(uint8_t n=0;n<8;n++) { card.fgets(buffer, sizeof(buffer)); buffer[sizeof(buffer)-1] = '\0'; while (strlen(buffer) > 0 && buffer[strlen(buffer)-1] < ' ') buffer[strlen(buffer)-1] = '\0'; if (strncmp_P(buffer, PSTR(";TIME:"), 6) == 0) LCD_DETAIL_CACHE_TIME() = atol(buffer + 6); else if (strncmp_P(buffer, PSTR(";MATERIAL:"), 10) == 0) LCD_DETAIL_CACHE_MATERIAL(0) = atol(buffer + 10); #if EXTRUDERS > 1 else if (strncmp_P(buffer, PSTR(";MATERIAL2:"), 11) == 0) LCD_DETAIL_CACHE_MATERIAL(1) = atol(buffer + 11); #endif } } if (card.errorCode()) { //On a read error reset the file position and try to keep going. (not pretty, but these read errors are annoying as hell) card.clearError(); LCD_DETAIL_CACHE_ID() = 255; } } if (LCD_DETAIL_CACHE_TIME() > 0) { char* c = buffer; if (led_glow_dir) { strcpy_P(c, PSTR("Time: ")); c += 6; c = int_to_time_string(LCD_DETAIL_CACHE_TIME(), c); }else{ strcpy_P(c, PSTR("Material: ")); c += 10; float length = float(LCD_DETAIL_CACHE_MATERIAL(0)) / (M_PI * (material[0].diameter / 2.0) * (material[0].diameter / 2.0)); if (length < 10000) c = float_to_string(length / 1000.0, c, PSTR("m")); else c = int_to_string(length / 1000.0, c, PSTR("m")); #if EXTRUDERS > 1 if (LCD_DETAIL_CACHE_MATERIAL(1)) { *c++ = '/'; float length = float(LCD_DETAIL_CACHE_MATERIAL(1)) / (M_PI * (material[1].diameter / 2.0) * (material[1].diameter / 2.0)); if (length < 10000) c = float_to_string(length / 1000.0, c, PSTR("m")); else c = int_to_string(length / 1000.0, c, PSTR("m")); } #endif } lcd_lib_draw_string(3, 53, buffer); }else{ lcd_lib_draw_stringP(3, 53, PSTR("No info available")); } } } } }