Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem_Warning_Fixed
Dependents: DISCO-F746_WAV_PLAYER WAV
Diff: FileSelectorWav.cpp
- Revision:
- 17:abfd6af9a236
- Parent:
- 12:f73e11831c1c
- Child:
- 18:6631cd0fbbcd
diff -r 299cc1052baa -r abfd6af9a236 FileSelectorWav.cpp
--- a/FileSelectorWav.cpp Wed Mar 22 09:20:13 2017 +0000
+++ b/FileSelectorWav.cpp Thu Mar 23 02:58:48 2017 +0000
@@ -2,7 +2,7 @@
// FileSelector class
// SD カード内のファイル名の一覧を表示し,ファイルを選択する
//
-// 2017/03/17, Copyright (c) 2017 MIKAMI, Naoki
+// 2017/03/23, Copyright (c) 2017 MIKAMI, Naoki
//--------------------------------------------------------------
#include "FileSelectorWav.hpp"
@@ -16,7 +16,8 @@
fileNames_(maxFiles), fileNameLabels_(MAX_LIST_PAGE_),
next_(50, 238, 64, 36, 2, (string[]){"<", ">"}, 10, 0, 2, -1, Font24),
pageLabel_(210, 250, Label::LEFT, Font16),
- lcd_(GuiBase::GetLcd()), sdReader_(reader), page_(1)
+ lcd_(GuiBase::GetLcd()), sdReader_(reader), page_(1),
+ nOld_(-1), kOld_(-1)
{
Array<string> nonString(MAX_LIST_PAGE_, "");
rect_ = new ButtonGroup(X_, Y_, W_H_, W_H_, MAX_LIST_PAGE_,
@@ -38,6 +39,7 @@
for (int n=0; n<MAX_LIST_PAGE_; n++) delete fileNameLabels_[n];
}
+ // ファイルの一覧表を作る.WAV ファイルが存在しない場合は false を返す
bool FileSelector::CreateTable()
{
DIR* dp = opendir("/sd");
@@ -63,16 +65,15 @@
}
if (fileCount_ >= MAX_FILES_) break;
}
- closedir(dp);
+ closedir(dp);
}
else
- return false;
- if (fileCount_ == 0) return false;
+ return false; // SD カードが装着されていない場合
+ if (fileCount_ == 0) return false; // 該当する WAV ファイルが存在しない場合
div_t m = div(fileCount_, MAX_LIST_PAGE_);
maxPage_ = (m.rem == 0) ? m.quot : m.quot+1;
- rect_->EraseAll();
- return true;
+ return true; // 該当する WAV ファイルが存在する場合
}
// ファイルを選択する
@@ -84,15 +85,27 @@
if (m==0) page_--;
else page_++;
DisplayFileList(false);
- wait_ms(200);
+ nOld_ = -1;
+ wait_ms(300);
}
int n;
if (rect_->GetTouchedNumber(n))
{
int k = (page_ - 1)*MAX_LIST_PAGE_ + n;
- fileNameLabels_[n]->Draw(GetFileNameNoExt(k), TOUCHED_COLOR_);
+ fileNameLabels_[n]->Draw(GetFileNameNoExt(k),
+ TOUCHED_COLOR_);
fileName = fileNames_[k];
+ // 同じページで以前に選択されているファイル名の色を戻す
+ if (nOld_ != -1)
+ fileNameLabels_[nOld_]->Draw(GetFileNameNoExt(kOld_),
+ BASE_COLOR_);
+ if (page_ == maxPage_) // 最後のページで余分な四角形を消去
+ for (int j=fileCount_ % MAX_LIST_PAGE_ + 1;
+ j < MAX_LIST_PAGE_; j++) rect_->Erase(j);
+ nOld_ = n;
+ kOld_ = k;
+ wait_ms(300);
return true;
}
else
@@ -115,10 +128,9 @@
fileNameLabels_[n]->Draw(GetFileNameNoExt(n+(page_-1)*MAX_LIST_PAGE_));
// 前のページ,次のページの選択ボタンなどを表示する
- next_.ActivateAll();
- next_.DrawAll();
- if (page_ == 1) next_.Inactivate(0);
- if (page_ == maxPage_) next_.Inactivate(1);
+ next_.InactivateAll();
+ if (page_ > 1) next_.Activate(0); // "<" 有効
+ if (page_ < maxPage_) next_.Activate(1); // ">" 有効
char page[6];
sprintf(page, "%d/%d", page_, maxPage_);
pageLabel_.Draw(page);
@@ -143,3 +155,4 @@
return name;
}
}
+