Fix watch screen update when file played from console
authorJim Morris <morris@wolfman.com>
Mon, 24 Jun 2013 07:42:35 +0000 (00:42 -0700)
committerJim Morris <morris@wolfman.com>
Mon, 24 Jun 2013 07:42:35 +0000 (00:42 -0700)
Only display filename part on LCD when play from LCD

src/modules/utils/panel/Panel.cpp
src/modules/utils/panel/Panel.h
src/modules/utils/panel/screens/FileScreen.cpp
src/modules/utils/panel/screens/WatchScreen.cpp

index 275877e..c577ae9 100644 (file)
@@ -28,6 +28,7 @@ Panel::Panel(){
     this->lcd= NULL;
     this->do_buttons = false;
     this->idle_time= 0;
+    strcpy(this->playing_file, "Playing file");
 }
 
 Panel::~Panel() {
@@ -310,4 +311,12 @@ bool Panel::is_playing() const {
         return b;
     }
     return false;
-}
\ No newline at end of file
+}
+
+void  Panel::set_playing_file(string f) {
+    // just copy the first 20 characters after the first / if there
+    size_t n= f.find_last_of('/');
+    if(n == string::npos) n= 0;
+    strncpy(playing_file, f.substr(n+1, 19).c_str(), sizeof(playing_file));
+    playing_file[sizeof(playing_file)-1]= 0;
+}
index afdd3e6..8457093 100644 (file)
@@ -76,8 +76,8 @@ class Panel : public Module {
 
         // file playing from sd
         bool is_playing() const;
-        void set_playing_file(string f) { playing_file= f; }
-        string get_playing_file() { return playing_file; }
+        void set_playing_file(string f);
+        const char* get_playing_file() { return playing_file; }
         
         // public as it is directly accessed by screens... not good
         // TODO pass lcd into ctor of each sub screen
@@ -124,7 +124,7 @@ class Panel : public Module {
         double default_hotend_temperature;
         double default_bed_temperature;
         
-        string playing_file;
+        char playing_file[20];
 };
 
 #endif
index e0c607e..26200f8 100644 (file)
@@ -165,8 +165,8 @@ uint16_t FileScreen::count_folder_content(std::string folder){
 void FileScreen::on_main_loop(){
     if(this->start_play){
         this->start_play= false;
-        play(this->play_path);
-        panel->set_playing_file(this->play_path);
+        this->panel->set_playing_file(this->play_path);
+        this->play(this->play_path);
         this->panel->enter_screen(this->parent);
         return;
     }
index 3571e90..75de106 100644 (file)
@@ -131,7 +131,6 @@ void WatchScreen::display_menu_line(uint16_t line){
         case 0: this->panel->lcd->printf("H%03d/%03dc B%03d/%03dc", this->hotendtemp, this->hotendtarget, this->bedtemp, this->bedtarget); break;
         case 1: this->panel->lcd->printf("X%4d Y%4d Z%7.2f", (int)round(this->pos[0]), (int)round(this->pos[1]), this->pos[2]); break;
         case 2: this->panel->lcd->printf("%3d%% %2d:%02d %3d%% sd", (int)round(this->current_speed), this->elapsed_time/60, this->elapsed_time%60, this->sd_pcnt_played); break;
-        case 3: this->panel->lcd->printf("%19s", panel->is_playing() ? panel->get_playing_file().substr(4, 19).c_str() : "Smoothie ready"); break;
+        case 3: this->panel->lcd->printf("%19s", panel->is_playing() ? panel->get_playing_file() : "Smoothie ready"); break;
     }
-
 }