• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン14 (tree)
日時2008-05-12 21:42:50
作者satofumi

ログメッセージ

add cwiid wrapper

変更サマリ

差分

--- trunk/libs/controller/samples/wiiJoystickSample.cpp (nonexistent)
+++ trunk/libs/controller/samples/wiiJoystickSample.cpp (revision 14)
@@ -0,0 +1,50 @@
1+/*!
2+ \file
3+ \brief WiiJoystick の動作サンプル
4+
5+ \author Satofumi KAMIMURA
6+
7+ $Id$
8+*/
9+
10+#include "WiiJoystick.h"
11+#include "Delay.h"
12+
13+using namespace qrk;
14+
15+
16+int main(int argc, char *argv[]) {
17+
18+ WiiJoystick joystick;
19+ if (! joystick.connect()) {
20+ printf("WiiJoystick::connect: %s\n", joystick.what());
21+ exit(1);
22+ }
23+ printf("O.K.\n");
24+
25+ size_t buttons_num = joystick.getButtonsNum();
26+ while (1) {
27+
28+ // 軸情報
29+ int x_axis = joystick.getAxisValue(WiiJoystick::AxisX);
30+ int y_axis = joystick.getAxisValue(WiiJoystick::AxisY);
31+ printf("%6d, %6d: ", x_axis, y_axis);
32+
33+ // ボタン情報
34+ for (size_t i = 0; i < buttons_num; ++i) {
35+ bool is_pressed = joystick.isButtonPressed(i);
36+ printf("%d, ", is_pressed ? 1 : 0);
37+ }
38+
39+ // 加速度情報
40+ Grid3D<double> acceleration;
41+ joystick.getAcceleration(acceleration);
42+ printf("%.2f, %.2f, %.2f", acceleration.x, acceleration.y, acceleration.z);
43+
44+ printf("\n");
45+
46+ delay(100);
47+ }
48+
49+ return 0;
50+}
--- trunk/libs/controller/samples/Makefile (nonexistent)
+++ trunk/libs/controller/samples/Makefile (revision 14)
@@ -0,0 +1,32 @@
1+# Makefile for controller/samples
2+# Satofumi KAMIMURA
3+# $Id$
4+
5+# Compile options
6+CC = ${CXX}
7+CXXFLAGS = -g -O0 -Wall -Werror ${INCLUDES} `sdl-config --cflags`
8+INCLUDES = -I.. -I../../system -I../../common
9+LDFLAGS =
10+LDLIBS = `sdl-config --libs` -lcwiid
11+
12+# Target
13+TARGET = \
14+ wiiJoystickSample \
15+
16+all : ${TARGET}
17+
18+clean :
19+ ${RM} *.o ${TARGET}
20+
21+depend :
22+ makedepend -Y -- ${INCLUDES} -- ${wildcard *.h *.cpp}
23+
24+.PHONY : all clean depend
25+######################################################################
26+REQUIRE_LIBS = ../controller.a ../../system/sdl/system_sdl.a
27+${REQUIRE_LIBS} :
28+ cd ${@D} && ${MAKE} ${@F}
29+
30+${TARGET} : ${REQUIRE_LIBS}
31+
32+# DO NOT DELETE
--- trunk/libs/controller/WiiJoystick.cpp (nonexistent)
+++ trunk/libs/controller/WiiJoystick.cpp (revision 14)
@@ -0,0 +1,351 @@
1+/*!
2+ \file
3+ \brief Wii コントローラ
4+
5+ \author Satofumi KAMIMURA
6+
7+ $Id$
8+
9+ wmgui/main.c を参考にしている。
10+
11+ \todo 適切に排他制御を行うべき。データ読み書きと、コールバックのあたり
12+*/
13+
14+#include <string>
15+#include <map>
16+#include <cwiid.h>
17+#include "WiiJoystick.h"
18+
19+using namespace qrk;
20+
21+
22+struct WiiJoystick::pImpl {
23+
24+ class CallbackHandler {
25+
26+ public:
27+ class WiiInformation {
28+ enum { Buttons = 7,
29+ };
30+
31+ public:
32+ bool quit_;
33+ int battery_percent_;
34+
35+ size_t buttons_timestamp_;
36+ short axis_[2];
37+ bool pressed_[Buttons];
38+ int pressed_times_[Buttons];
39+
40+ struct acc_cal calibration_;
41+ Grid3D<double> acceleration_;
42+ size_t acceleration_timestamp_;
43+
44+ WiiInformation(void)
45+ : quit_(false), battery_percent_(0),
46+ buttons_timestamp_(0), acceleration_timestamp_(0) {
47+
48+ // ゼロ初期化
49+ axis_[AxisX] = 0;
50+ axis_[AxisY] = 0;
51+
52+ for (int i = 0; i < Buttons; ++i) {
53+ pressed_[i] = false;
54+ pressed_times_[i] = 0;
55+ }
56+
57+ // !!! calibration_ は未初期化...
58+ }
59+ };
60+ typedef std::map<const cwiid_wiimote_t*, WiiInformation*> WiiHash;
61+ static WiiHash wii_hash_;
62+
63+ CallbackHandler(void) {
64+ }
65+
66+ ~CallbackHandler(void) {
67+ }
68+
69+ static CallbackHandler* getObject(void) {
70+ static CallbackHandler singleton;
71+ return &singleton;
72+ }
73+
74+ void registerObject(const cwiid_wiimote_t* wii) {
75+ WiiInformation* wii_information = new WiiInformation;
76+ wii_hash_.insert(WiiHash::value_type(wii, wii_information));
77+ }
78+
79+ void removeObject(const cwiid_wiimote_t* wii) {
80+ delete wii_hash_[wii];
81+ wii_hash_.erase(wii);
82+ }
83+
84+ void setCalibrationValue(const cwiid_wiimote_t* wii,
85+ struct acc_cal* calibration) {
86+ wii_hash_[wii]->calibration_ = *calibration;
87+ }
88+
89+ bool haveQuitEvent(const cwiid_wiimote_t* wii) {
90+ return wii_hash_[wii];
91+ }
92+
93+ static void recordPressed(cwiid_btn_mesg* mesg, WiiInformation* state) {
94+
95+ uint16_t buttons = mesg->buttons;
96+
97+ // 軸の入力を取得
98+ state->axis_[AxisX] =
99+ ((buttons & CWIID_BTN_LEFT) ? -32767 : 0) +
100+ ((buttons & CWIID_BTN_RIGHT) ? +32767 : 0);
101+
102+ state->axis_[AxisY] =
103+ ((buttons & CWIID_BTN_UP) ? -32767 : 0) +
104+ ((buttons & CWIID_BTN_DOWN) ? +32767 : 0);
105+
106+ // ボタンの押下情報を取得
107+ state->pressed_[BUTTON_A] = (buttons & CWIID_BTN_A) ? true : false;
108+ state->pressed_[BUTTON_B] = (buttons & CWIID_BTN_B) ? true : false;
109+ state->pressed_[BUTTON_MINUS] =
110+ (buttons & CWIID_BTN_MINUS) ? true : false;
111+ state->pressed_[BUTTON_PLUS] = (buttons & CWIID_BTN_PLUS) ? true : false;
112+ state->pressed_[BUTTON_HOME] = (buttons & CWIID_BTN_HOME) ? true : false;
113+ state->pressed_[BUTTON_1] = (buttons & CWIID_BTN_1) ? true : false;
114+ state->pressed_[BUTTON_2] = (buttons & CWIID_BTN_2) ? true : false;
115+
116+ // ボタンが押された回数を更新
117+ // !!!
118+ }
119+
120+ static void recordAcceleration(struct cwiid_acc_mesg *mesg,
121+ WiiInformation* state) {
122+
123+ uint8_t* acc = mesg->acc;
124+ struct acc_cal& calibration = state->calibration_;
125+
126+ state->acceleration_.x =
127+ ((double)acc[CWIID_X] - calibration.zero[CWIID_X]) /
128+ (calibration.one[CWIID_X] - calibration.zero[CWIID_X]);
129+ state->acceleration_.y =
130+ ((double)acc[CWIID_Y] - calibration.zero[CWIID_Y]) /
131+ (calibration.one[CWIID_Y] - calibration.zero[CWIID_Y]);
132+ state->acceleration_.z =
133+ ((double)acc[CWIID_Z] - calibration.zero[CWIID_Z]) /
134+ (calibration.one[CWIID_Z] - calibration.zero[CWIID_Z]);
135+ }
136+
137+ static void callback(cwiid_wiimote_t *wii, int mesg_count,
138+ union cwiid_mesg mesg_array[],
139+ struct timespec *timestamp) {
140+
141+ WiiInformation* state = wii_hash_[wii];
142+
143+ for (int i = 0; i < mesg_count; ++i) {
144+
145+ switch (mesg_array[i].type) {
146+ case CWIID_MESG_STATUS:
147+ wii_hash_[wii]->battery_percent_ =
148+ static_cast<int>((100.0 * mesg_array[i].status_mesg.battery
149+ / CWIID_BATTERY_MAX));
150+ // 元のソースでは、ここで NUNCHUK とかの処理もしていたが、省略
151+ break;
152+
153+ case CWIID_MESG_BTN:
154+ // 押下の記録
155+ recordPressed(&mesg_array[i].btn_mesg, state);
156+ break;
157+
158+ case CWIID_MESG_ACC:
159+ // 加速度情報の取得
160+ recordAcceleration(&mesg_array[i].acc_mesg, state);
161+ break;
162+
163+ case CWIID_MESG_IR:
164+ //cwiid_ir(&mesg_array[i].ir_mesg);
165+ // !!! とりあえず省略
166+ break;
167+
168+ case CWIID_MESG_ERROR:
169+ wii_hash_[wii]->quit_ = true;
170+ break;
171+
172+ default:
173+ break;
174+ }
175+ }
176+ }
177+
178+ static int getAxisValue(size_t index, const cwiid_wiimote_t *wii) {
179+ return wii_hash_[wii]->axis_[index];
180+ }
181+
182+ static bool isButtonPressed(size_t index, const cwiid_wiimote_t *wii) {
183+ return wii_hash_[wii]->pressed_[index];
184+ }
185+
186+ static int getBatteryPercent(const cwiid_wiimote_t *wii) {
187+ return wii_hash_[wii]->battery_percent_;
188+ }
189+
190+ static void getAcceleration(Grid3D<double>& acceleration, size_t timestamp,
191+ const cwiid_wiimote_t *wii) {
192+ acceleration = wii_hash_[wii]->acceleration_;
193+ }
194+ };
195+
196+ std::string error_message_;
197+ cwiid_wiimote_t* wii_;
198+ bdaddr_t bdaddr_;
199+ CallbackHandler* callback_;
200+ struct acc_cal calibration_;
201+
202+ pImpl(void)
203+ : error_message_("no error."), wii_(NULL), bdaddr_(*BDADDR_ANY),
204+ callback_(CallbackHandler::getObject()) {
205+ }
206+
207+ ~pImpl(void) {
208+ disconnect();
209+ }
210+
211+ bool isError(cwiid_wiimote_t* wii) {
212+ return (callback_->haveQuitEvent(wii)) ? true : false;
213+ }
214+
215+ bool connect(void) {
216+ disconnect();
217+
218+ // 接続
219+ wii_ = cwiid_open(&bdaddr_, CWIID_FLAG_MESG_IFC);
220+ if (wii_ == NULL) {
221+ error_message_ = "unable to connect.";
222+ return false;
223+ }
224+ setRepeatMode();
225+
226+ // コールバックを登録
227+ if (cwiid_set_mesg_callback(wii_, &CallbackHandler::callback)) {
228+ disconnect();
229+ error_message_ = "error setting callback";
230+ return false;
231+ }
232+ callback_->registerObject(wii_);
233+
234+ // キャリブレーション値の取得
235+ if (cwiid_get_acc_cal(wii_, CWIID_EXT_NONE, &calibration_)) {
236+ error_message_ = "unable to retrieve accelerometer calibration";
237+ return false;
238+ }
239+ callback_->setCalibrationValue(wii_, &calibration_);
240+
241+ return true;
242+ }
243+
244+ void disconnect(void) {
245+
246+ if (! wii_) {
247+ // 接続されていなければ、戻る
248+ return;
249+ }
250+
251+ // 切断処理
252+ callback_->removeObject(wii_);
253+ cwiid_close(wii_);
254+ wii_ = NULL;
255+ }
256+
257+ void setRepeatMode(void) {
258+ uint8_t rpt_mode =
259+ CWIID_RPT_STATUS | CWIID_RPT_BTN | CWIID_RPT_IR | CWIID_RPT_ACC;
260+
261+ if (cwiid_set_rpt_mode(wii_, rpt_mode)) {
262+ error_message_ = "error setting report mode";
263+ }
264+ }
265+};
266+WiiJoystick::pImpl::CallbackHandler::WiiHash
267+WiiJoystick::pImpl::CallbackHandler::wii_hash_;
268+
269+
270+WiiJoystick::WiiJoystick(void) : pimpl(new pImpl) {
271+}
272+
273+
274+WiiJoystick::~WiiJoystick(void) {
275+}
276+
277+
278+bool WiiJoystick::findController(int timeout) {
279+
280+ bool exist = (cwiid_find_wiimote(&pimpl->bdaddr_, timeout)) ? false : true;
281+ return exist;
282+}
283+
284+
285+const char* WiiJoystick::what(void) {
286+ return pimpl->error_message_.c_str();
287+}
288+
289+
290+bool WiiJoystick::connect(void) {
291+ return pimpl->connect();
292+}
293+
294+
295+void WiiJoystick::disconnect(void) {
296+ pimpl->disconnect();
297+}
298+
299+
300+size_t WiiJoystick::getAxisNum(void) {
301+ return 2;
302+}
303+
304+
305+int WiiJoystick::getAxisValue(size_t index) {
306+
307+ // !!! 排他制御
308+
309+ return pimpl->callback_->getAxisValue(index, pimpl->wii_);
310+}
311+
312+
313+size_t WiiJoystick::getButtonsNum(void) {
314+ return 7;
315+}
316+
317+
318+bool WiiJoystick::isButtonPressed(size_t index) {
319+
320+ // !!! 排他制御
321+
322+ return pimpl->callback_->isButtonPressed(index, pimpl->wii_);
323+}
324+
325+
326+int WiiJoystick::getButtonPressedTimes(size_t index) {
327+
328+ // !!!
329+ return 0;
330+}
331+
332+
333+void WiiJoystick::getAcceleration(Grid3D<double>& acceleration,
334+ size_t* timestamp) {
335+
336+ size_t timestamp_value = 0;
337+ pimpl->callback_->getAcceleration(acceleration, timestamp_value,
338+ pimpl->wii_);
339+
340+ if (timestamp) {
341+ *timestamp = timestamp_value;
342+ }
343+}
344+
345+
346+size_t WiiJoystick::getBatteryPercent(void) {
347+
348+ // !!! 排他制御
349+
350+ return pimpl->callback_->getBatteryPercent(pimpl->wii_);
351+}
--- trunk/libs/controller/Makefile (nonexistent)
+++ trunk/libs/controller/Makefile (revision 14)
@@ -0,0 +1,32 @@
1+# Makefile for libs/controller
2+# Satofumi KAMIMURA
3+# $Id$
4+
5+# Compile options
6+CC = ${CXX}
7+CXXFLAGS = -g -O0 -Wall -Werror ${INCLUDES}
8+INCLUDES = -I../common
9+
10+# Target
11+CONTROLLER_LIB = controller.a
12+TARGET = ${CONTROLLER_LIB}
13+
14+
15+all : ${TARGET}
16+
17+clean :
18+ ${RM} *.o ${TARGET}
19+ cd samples/ && ${MAKE} clean
20+
21+depend :
22+ makedepend -Y -- ${INCLUDES} -- ${wildcard *.h *.cpp}
23+
24+.PHONY : all clean depend
25+######################################################################
26+${CONTROLLER_LIB} : \
27+ ${CONTROLLER_LIB}(WiiJoystick.o)
28+
29+# DO NOT DELETE
30+
31+WiiJoystick.o: ../common/GridTypes.h
32+WiiJoystick.o: WiiJoystick.h ../common/GridTypes.h
--- trunk/libs/controller/WiiJoystick.h (nonexistent)
+++ trunk/libs/controller/WiiJoystick.h (revision 14)
@@ -0,0 +1,147 @@
1+#ifndef WII_JOYSTICK_H
2+#define WII_JOYSTICK_H
3+
4+/*!
5+ \file
6+ \brief Wii コントローラ
7+
8+ \author Satofumi KAMIMURA
9+
10+ $Id$
11+
12+ \todo タイムスタンプのインターフェースを定義して継承すべき
13+*/
14+
15+#include <memory>
16+#include "GridTypes.h"
17+
18+
19+namespace qrk {
20+ class WiiJoystick {
21+ WiiJoystick(const WiiJoystick& rhs);
22+ WiiJoystick& operator = (const WiiJoystick& rhs);
23+
24+ struct pImpl;
25+ const std::auto_ptr<pImpl> pimpl;
26+
27+ public:
28+ enum {
29+ DefaultTimeout = 1000,
30+
31+ AxisX = 0,
32+ AxisY = 1,
33+
34+ BUTTON_A = 0,
35+ BUTTON_B,
36+ BUTTON_MINUS,
37+ BUTTON_PLUS,
38+ BUTTON_HOME,
39+ BUTTON_1,
40+ BUTTON_2,
41+ };
42+
43+ WiiJoystick(void);
44+ ~WiiJoystick(void);
45+
46+ /*!
47+ \brief Wii リモコン数の取得
48+
49+ \retrun Wii リモコン数
50+
51+ \attention 未実装
52+ */
53+ bool findController(int timeout = DefaultTimeout);
54+
55+ /*!
56+ \brief 状態の取得
57+
58+ \return 状態を示す文字列
59+ */
60+ const char* what(void);
61+
62+ /*!
63+ \brief 接続
64+
65+ Wii への接続を行う。
66+
67+ \param [i] id 接続する Wii リモコンの番号
68+ */
69+ bool connect(void);
70+
71+ /*!
72+ \brief 切断
73+ */
74+ void disconnect(void);
75+
76+ /*!
77+ \brief 軸の数を取得
78+
79+ \return 軸の数
80+ */
81+ size_t getAxisNum(void);
82+
83+ /*!
84+ \brief 軸の入力値を取得
85+
86+ \param index [i] 軸の番号
87+
88+ \return 軸の入力値
89+ */
90+ int getAxisValue(size_t index);
91+
92+ /*!
93+ \brief ボタンの数を取得
94+
95+ \return ボタンの数
96+ */
97+ size_t getButtonsNum(void);
98+
99+ /*!
100+ \brief ボタン押下情報の取得
101+
102+ \param index [i] ボタンの番号
103+
104+ \retval true 押されている
105+ \retval false 離されている
106+ */
107+ bool isButtonPressed(size_t index);
108+
109+ /*!
110+ \brief ボタンが押下回数の取得
111+
112+ 最後にこのメソッドが呼ばれてから、ボタンが何回押されたかを返す
113+
114+ \param index [i] ボタンの番号
115+
116+ \return ボタンの押下回数
117+
118+ \attention 未実装
119+ */
120+ int getButtonPressedTimes(size_t index);
121+
122+ /*!
123+ \brief 加速度情報の取得
124+
125+ \param acceleration [o] 加速度情報 [g]
126+ \param timestamp [o] データ取得時のタイムスタンプ
127+
128+ \attention timestamp は未実装
129+ */
130+ void getAcceleration(qrk::Grid3D<double>& acceleration,
131+ size_t* timestamp = NULL);
132+
133+ /*!
134+ \brief バッテリー充電率の取得
135+
136+ \return バッテリーの充電率
137+ */
138+ size_t getBatteryPercent(void);
139+
140+ // Wii コントローラの制御
141+ // !!! 振動
142+ // !!! LED
143+ // !!! 音
144+ };
145+};
146+
147+#endif /*! WII_JOYSTICK_H */
--- trunk/libs/sound/CdromPlay.h (revision 13)
+++ trunk/libs/sound/CdromPlay.h (revision 14)
@@ -8,6 +8,8 @@
88 \author Satofumi KAMIMURA
99
1010 $Id$
11+
12+ \todo CD-ROM の有無を調べるだけのメソッド追加を検討する
1113 */
1214
1315 #include <memory>
@@ -76,12 +78,21 @@
7678 size_t play_frame = 0,
7779 size_t tracks = 1);
7880
81+ /*!
82+ \brief 再生中かの取得
83+
84+ \retval true 再生中
85+ \retval false それ以外
86+
87+ \bug 短い周期で呼び出しを繰り返すと再生がぶれる。SDL-1.2 の仕様か?
88+ */
7989 bool isPlaying(void);
8090
91+#if 0
8192 bool getCurrentFrame(size_t* frame,
8293 size_t* min = NULL, size_t* sec = NULL);
94+#endif
8395
84- // !!! 指定トラックの再生 / 指定範囲の再生
8596 void stop(void);
8697 void pause(void);
8798 void resume(void);
--- trunk/libs/sound/samples/cdromPlaySample.cpp (revision 13)
+++ trunk/libs/sound/samples/cdromPlaySample.cpp (revision 14)
@@ -43,19 +43,16 @@
4343 // トラックを順番に再生
4444 size_t n = tracks.size();
4545 for (size_t i = 0; i < n; ++i) {
46- if (! cdrom.playTrack(i)) {
46+ int play_msec = cdrom.playTrack(i);
47+ if (play_msec < 0) {
4748 printf("CdromPlay::playTrack: %s\n", cdrom.what());
4849 exit(1);
4950 }
51+ printf("play track %d\n", i + 1);
5052
51- while (cdrom.isPlaying()) {
52- size_t min = 0;
53- size_t sec = 0;
54- cdrom.getCurrentFrame(NULL, &min, &sec);
55- printf("\r[%2d:%02d]", min, sec);
56- fflush(stdout);
57- delay(200);
58- }
53+ do {
54+ delay(500);
55+ } while (cdrom.isPlaying());
5956 }
6057
6158 return 0;
--- trunk/libs/sound/CdromPlay.cpp (revision 13)
+++ trunk/libs/sound/CdromPlay.cpp (revision 14)
@@ -26,9 +26,11 @@
2626 std::string error_message_;
2727 SDL_CD* cdrom_;
2828 std::vector<track_t> track_list_;
29+ CDstatus cd_status_;
2930
3031 pImpl(size_t id)
31- : drive_id_(id), error_message_("no error"), cdrom_(NULL) {
32+ : drive_id_(id), error_message_("no error"), cdrom_(NULL),
33+ cd_status_(CD_ERROR) {
3234 openDrive(drive_id_);
3335 }
3436
@@ -66,8 +68,8 @@
6668 }
6769 }
6870
69- CDstatus status = SDL_CDStatus(cdrom_);
70- if (! CD_INDRIVE(status)) {
71+ cd_status_ = SDL_CDStatus(NULL);
72+ if (! CD_INDRIVE(cd_status_)) {
7173 error_message_ = "not found CD-ROM.";
7274 return false;
7375 }
@@ -99,7 +101,7 @@
99101 }
100102
101103 int ntrack = (play_frame == 0) ? 1 : 0;
102- SDL_CDPlayTracks(cdrom_, static_cast<int>(id),
104+ SDL_CDPlayTracks(NULL, static_cast<int>(id),
103105 static_cast<int>(start_frame),
104106 ntrack, static_cast<int>(play_frame));
105107 return true;
@@ -106,14 +108,16 @@
106108 }
107109
108110 void stop(void) {
109- SDL_CDStop(cdrom_);
111+ SDL_CDStop(NULL);
110112 }
111113
112114 bool getCurrentFrame(size_t* frame, size_t* min, size_t* sec) {
113115
116+#if 0
114117 if (! checkDrive(track_list_)) {
115118 return false;
116119 }
120+#endif
117121
118122 // 値の取得
119123 size_t frame_length = 0;
@@ -120,6 +124,7 @@
120124 size_t min_length = 0;
121125 size_t sec_length = 0;
122126 FRAMES_TO_MSF(cdrom_->cur_frame, &min_length, &sec_length, &frame_length);
127+ fprintf(stderr, "%d, %d, %d\n", frame_length, min_length, sec_length);
123128
124129 // 代入
125130 if (frame) {
@@ -165,7 +170,7 @@
165170 int CdromPlay::playTrack(size_t track_id,
166171 size_t start_frame, size_t play_frame,
167172 size_t tracks) {
168- fprintf(stderr, "play()\n");
173+ //fprintf(stderr, "play(%d, %d, %d, %d)\n", track_id, start_frame, play_frame, tracks);
169174
170175 if (! pimpl->play(track_id, start_frame, play_frame)) {
171176 return -1;
@@ -186,30 +191,16 @@
186191
187192 bool CdromPlay::isPlaying(void) {
188193
189- // CD_FPS 分だけ待機し、その間にフレーム位置が移動したら、再生中とみなす
190- // !!! いいのかな? こんな実装で
191-
192- // 現在のフレーム位置を取得
193- size_t first_frame = 0;
194- if (! getCurrentFrame(&first_frame)) {
195- return false;
196- }
197-
198- delay(1000 / CD_FPS);
199-
200- // CD_FPS 経過後のフレーム位置を取得
201- size_t last_frame = 0;
202- if (! getCurrentFrame(&last_frame)) {
203- return false;
204- }
205-
206- return (first_frame == last_frame) ? false : true;
194+ pimpl->checkDrive(pimpl->track_list_);
195+ return (pimpl->cd_status_ == CD_PLAYING) ? true : false;
207196 }
208197
209198
199+#if 0
210200 bool CdromPlay::getCurrentFrame(size_t* frame, size_t* min, size_t* sec) {
211201 return pimpl->getCurrentFrame(frame, min, sec);
212202 }
203+#endif
213204
214205
215206 void CdromPlay::stop(void) {
@@ -218,15 +209,15 @@
218209
219210
220211 void CdromPlay::pause(void) {
221- SDL_CDPause(pimpl->cdrom_);
212+ SDL_CDPause(NULL);
222213 }
223214
224215
225216 void CdromPlay::resume(void) {
226- SDL_CDResume(pimpl->cdrom_);
217+ SDL_CDResume(NULL);
227218 }
228219
229220
230221 void CdromPlay::eject(void) {
231- SDL_CDEject(pimpl->cdrom_);
222+ SDL_CDEject(NULL);
232223 }
--- trunk/libs/common/GridTypes.h (nonexistent)
+++ trunk/libs/common/GridTypes.h (revision 14)
@@ -0,0 +1,42 @@
1+#ifndef GRID_TYPES_H
2+#define GRID_TYPES_H
3+
4+/*!
5+ \brief 型定義
6+
7+ \author Satofumi KAMIMURA
8+
9+ $Id$
10+*/
11+
12+namespace qrk {
13+
14+ /*!
15+ \brief 3次元位置
16+ */
17+ template<class T> class Grid3D {
18+ public:
19+ T x;
20+ T y;
21+ T z;
22+
23+ Grid3D(void) : x(0), y(0), z(0) {
24+ }
25+
26+ Grid3D(const Grid3D& rhs) : x(rhs.x), y(rhs.y), z(rhs.x) {
27+ }
28+
29+ Grid3D& operator = (const Grid3D& rhs) {
30+ this->x = rhs.x;
31+ this->y = rhs.y;
32+ this->z = rhs.z;
33+
34+ return *this;
35+ }
36+
37+ ~Grid3D(void) {
38+ }
39+ };
40+};
41+
42+#endif /* !GRID_TYPES_H */
--- trunk/libs/Makefile (revision 13)
+++ trunk/libs/Makefile (revision 14)
@@ -4,4 +4,4 @@
44
55 include ../handover.mk
66
7-TARGET_DIR = system/ gui/ sound/
7+TARGET_DIR = system/ common/ gui/ sound/ controller/
--- trunk/programs/CdPlayer/CdPlayerWidget.cpp (revision 13)
+++ trunk/programs/CdPlayer/CdPlayerWidget.cpp (revision 14)
@@ -7,6 +7,7 @@
77 $Id$
88 */
99
10+#include <QTimer>
1011 #include <QShortcut>
1112 #include "CdPlayerWidget.h"
1213 #include "CdromPlay.h"
@@ -15,7 +16,10 @@
1516
1617
1718 struct CdPlayerWidget::pImpl {
19+
1820 CdromPlay cdrom_;
21+ std::vector<CdromPlay::track_t> tracks_;
22+ std::vector<CdromPlay::track_t> prev_tracks_;
1923
2024 void initForm(CdPlayerWidget* parent) {
2125
@@ -25,6 +29,7 @@
2529 parent->track_table_->setHorizontalHeaderLabels(labels);
2630
2731 // LCD を初期化
32+ // !!! 線も塗りつぶすようにする
2833 parent->frame_lcd_->display(" 00:00");
2934
3035 // 初期ボリューム値の取得
@@ -33,16 +38,51 @@
3338 // Ctrl-q で終了できるようにする
3439 (void) new QShortcut(Qt::CTRL + Qt::Key_Q, parent, SLOT(close()));
3540
36-#if 0
3741 // ボタンイベントの登録
38- connect(parent->eject_button_, SIGNAL(clicked()),
39- parent, SLOT(eject()));
42+ connect(parent->eject_button_, SIGNAL(clicked()), parent, SLOT(eject()));
4043 // !!!
41-#endif
4244
4345 // 定期的に CD-ROM があるかをチェックする
44- // !!!
46+ QTimer* check_timer = new QTimer(parent);
47+ connect(check_timer, SIGNAL(timeout()), parent, SLOT(checkCdrom()));
48+ check_timer->start(1000);
4549 }
50+
51+ void checkCdrom(void) {
52+
53+ // !!! この処理が遅い? スレッド化すべきかも。
54+
55+ // 読み出してみて、それが現在の読み出し内容と異なるなら、テーブル内容を更新
56+ std::vector<CdromPlay::track_t> current_tracks;
57+ cdrom_.getTracks(current_tracks);
58+
59+ if (isSameTracks(current_tracks, tracks_)) {
60+ return;
61+ }
62+ std::swap(tracks_, current_tracks);
63+
64+ // テーブル内容の更新
65+ fprintf(stderr, "update track table\n");
66+ }
67+
68+ bool isSameTracks(std::vector<CdromPlay::track_t>& a,
69+ std::vector<CdromPlay::track_t>& b) {
70+
71+ if (a.size() != b.size()) {
72+ // そもそも、トラック長が異なる
73+ return false;
74+ }
75+
76+ size_t n = a.size();
77+ for (size_t i = 0; i < n; ++i) {
78+ // !!! トラックのデータタイプも比較すべきか?
79+ if (a[i].frame_length != b[i].frame_length) {
80+ // トラックの長さが異なる
81+ return false;
82+ }
83+ }
84+ return true;
85+ }
4686 };
4787
4888
@@ -64,3 +104,14 @@
64104
65105 CdPlayerWidget::~CdPlayerWidget(void) {
66106 }
107+
108+
109+void CdPlayerWidget::eject(void) {
110+ pimpl->cdrom_.eject();
111+}
112+
113+
114+void CdPlayerWidget::checkCdrom(void) {
115+ fprintf(stderr, "check\n");
116+ pimpl->checkCdrom();
117+}
--- trunk/programs/CdPlayer/CdPlayerWidget.h (revision 13)
+++ trunk/programs/CdPlayer/CdPlayerWidget.h (revision 14)
@@ -27,6 +27,10 @@
2727 CdPlayerWidget(void);
2828 CdPlayerWidget(QWidget* parent);
2929 ~CdPlayerWidget(void);
30+
31+ public slots:
32+ void eject(void);
33+ void checkCdrom(void);
3034 };
3135 };
3236
旧リポジトリブラウザで表示