@@ -32,11 +32,6 @@ const char * btnm_map[] = { "RECORD", "\n", "REPLAY", "\n", "ZERO_POSITION", "\n
3232static float sample_buf[SAMPLE_BUF_SIZE];
3333static int sample_cnt;
3434
35- IdleState LearnAndRepeatApp::_idle_state;
36- RecordState LearnAndRepeatApp::_record_state;
37- ReplayState LearnAndRepeatApp::_replay_state;
38- ZeroState LearnAndRepeatApp::_zero_state;
39-
4035extern LearnAndRepeatApp app;
4136
4237/* *************************************************************************************
@@ -107,7 +102,7 @@ void custom_main_menu()
107102
108103State * State::handle_OnZeroPosition ()
109104{
110- return &LearnAndRepeatApp::_zero_state ;
105+ return new ZeroState () ;
111106}
112107
113108/* *************************************************************************************
@@ -126,12 +121,12 @@ void IdleState::onExit()
126121
127122State * IdleState::handle_OnRecord ()
128123{
129- return &LearnAndRepeatApp::_record_state ;
124+ return new RecordState () ;
130125}
131126
132127State * IdleState::handle_OnReplay ()
133128{
134- return &LearnAndRepeatApp::_replay_state ;
129+ return new ReplayState () ;
135130}
136131
137132/* *************************************************************************************
@@ -159,14 +154,14 @@ void RecordState::onExit()
159154
160155State * RecordState::handle_OnRecord ()
161156{
162- return &LearnAndRepeatApp::_idle_state ;
157+ return new IdleState () ;
163158}
164159
165160State * RecordState::handle_OnTimerTick ()
166161{
167162 /* The sample buffer is full. */
168163 if (sample_cnt >= SAMPLE_BUF_SIZE) {
169- return &LearnAndRepeatApp::_idle_state ;
164+ return new IdleState () ;
170165 }
171166
172167 /* We still have space, let's sample some data. */
@@ -185,8 +180,6 @@ State * RecordState::handle_OnTimerTick()
185180
186181void ReplayState::onEnter ()
187182{
188- _replay_cnt = 0 ;
189-
190183 btnm_map[2 ] = " STOP" ;
191184 lv_btnmatrix_set_btn_ctrl (btnm, 0 , LV_BTNMATRIX_CTRL_DISABLED);
192185 lv_btnmatrix_set_btn_ctrl (btnm, 1 , LV_BTNMATRIX_CTRL_CHECKED);
@@ -202,14 +195,14 @@ void ReplayState::onExit()
202195
203196State * ReplayState::handle_OnReplay ()
204197{
205- return &LearnAndRepeatApp::_idle_state ;
198+ return new IdleState () ;
206199}
207200
208201State * ReplayState::handle_OnTimerTick ()
209202{
210203 /* All samples have been replayed. */
211204 if (_replay_cnt >= sample_cnt) {
212- return &LearnAndRepeatApp::_idle_state ;
205+ return new IdleState () ;
213206 }
214207
215208 /* Replay recorded movements. */
@@ -232,7 +225,7 @@ State * ReplayState::handle_OnTimerTick()
232225
233226State * ZeroState::handle_OnTimerTick ()
234227{
235- return &LearnAndRepeatApp::_idle_state ;
228+ return new IdleState () ;
236229}
237230
238231void ZeroState::onEnter ()
0 commit comments