|
2 | 2 | #include "AnimationData.h"
|
3 | 3 | #include <Arduino.h>
|
4 | 4 |
|
5 |
| -using namespace BlenderServoAnimation; |
| 5 | +using BlenderServoAnimation::Animation; |
| 6 | +using BlenderServoAnimation::Scene; |
6 | 7 |
|
7 | 8 | Animation::~Animation() {
|
8 | 9 | if (this->scenes) {
|
9 | 10 | delete[] this->scenes;
|
10 | 11 | }
|
11 | 12 |
|
12 |
| - if (this->liveStream != nullptr && this->isOneTimeLiveStream) { |
| 13 | + if (this->liveStream != nullptr) { |
13 | 14 | delete this->liveStream;
|
14 | 15 | }
|
15 | 16 |
|
@@ -189,25 +190,38 @@ void Animation::stop() {
|
189 | 190 | this->changeMode(MODE_STOP);
|
190 | 191 | }
|
191 | 192 |
|
192 |
| -void Animation::live(Stream &stream) { |
| 193 | +void Animation::live() { |
193 | 194 | if (this->mode != MODE_DEFAULT) {
|
194 | 195 | return;
|
195 | 196 | }
|
196 | 197 |
|
197 |
| - this->liveStream = new AnimationData(&stream); |
198 |
| - this->isOneTimeLiveStream = true; |
| 198 | + if (this->liveStream != nullptr) { |
| 199 | + delete this->liveStream; |
| 200 | + } |
| 201 | + |
| 202 | + this->liveStream = new AnimationData(); |
199 | 203 | this->changeMode(MODE_LIVE);
|
200 | 204 | }
|
201 | 205 |
|
202 |
| -void Animation::live(AnimationData &data) { |
| 206 | +void Animation::live(Stream &stream) { |
203 | 207 | if (this->mode != MODE_DEFAULT) {
|
204 | 208 | return;
|
205 | 209 | }
|
206 | 210 |
|
207 |
| - this->liveStream = &data; |
| 211 | + if (this->liveStream != nullptr) { |
| 212 | + delete this->liveStream; |
| 213 | + } |
| 214 | + |
| 215 | + this->liveStream = new AnimationData(&stream); |
208 | 216 | this->changeMode(MODE_LIVE);
|
209 | 217 | }
|
210 | 218 |
|
| 219 | +void Animation::writeLiveStream(byte value) { |
| 220 | + if (this->liveStream != nullptr) { |
| 221 | + this->liveStream->writeByte(value); |
| 222 | + } |
| 223 | +} |
| 224 | + |
211 | 225 | byte Animation::getMode() {
|
212 | 226 | return this->mode;
|
213 | 227 | }
|
@@ -286,7 +300,6 @@ void Animation::handlePlayMode(unsigned long currentMicros) {
|
286 | 300 |
|
287 | 301 | if (!this->scene) {
|
288 | 302 | this->changeMode(MODE_DEFAULT);
|
289 |
| - return; |
290 | 303 | }
|
291 | 304 | }
|
292 | 305 |
|
@@ -327,7 +340,7 @@ void Animation::changeMode(byte mode) {
|
327 | 340 | byte prevMode = this->mode;
|
328 | 341 | this->mode = mode;
|
329 | 342 |
|
330 |
| - if (prevMode == MODE_LIVE && this->isOneTimeLiveStream) { |
| 343 | + if (prevMode == MODE_LIVE) { |
331 | 344 | delete this->liveStream;
|
332 | 345 | this->liveStream = nullptr;
|
333 | 346 | }
|
|
0 commit comments