Skip to content

Commit 5e36bc7

Browse files
committed
support animations without fps and frames
1 parent 951be16 commit 5e36bc7

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/BlenderServoAnimation.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
using namespace BlenderServoAnimation;
66

7+
Animation::Animation() {
8+
}
9+
710
Animation::Animation(byte fps, int frames) {
811
this->frameMillis = Animation::SECOND_IN_MILLIS / fps;
912
this->frames = frames;
10-
this->mode = Animation::MODE_DEFAULT;
1113
}
1214

1315
void Animation::addServo(Servo servo) {
@@ -39,7 +41,9 @@ void Animation::run(unsigned long currentMillis) {
3941
}
4042

4143
void Animation::handlePlayMode() {
42-
if (this->currentMillis - this->lastMillis < this->frameMillis) {
44+
bool isNewFrame = this->currentMillis - this->lastMillis >= this->frameMillis;
45+
46+
if (!isNewFrame || this->frames == 0) {
4347
return;
4448
}
4549

src/BlenderServoAnimation.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ class Animation {
1111
static const int MAX_SERVO_COUNT = 256;
1212
static const int SECOND_IN_MILLIS = 1000;
1313

14-
byte frameMillis;
15-
byte mode;
16-
byte stopStepDelay;
14+
byte frameMillis = 0;
15+
byte stopStepDelay = 20;
16+
byte mode = MODE_DEFAULT;
1717

1818
int frame = 0;
19-
int frames;
19+
int frames = 0;
2020

2121
unsigned long currentMillis;
2222
unsigned long lastMillis;
@@ -38,6 +38,8 @@ class Animation {
3838
static const byte MODE_STOP = 3;
3939
static const byte MODE_LIVE = 4;
4040

41+
Animation();
42+
4143
Animation(byte fps, int frames);
4244

4345
void addServo(Servo servo);

test/test_animation/test_animation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void test_stop(void) {
123123
}
124124

125125
void test_live(void) {
126-
Animation animation(FPS, 5);
126+
Animation animation;
127127
SerialMock mock;
128128
Servo servos[] = {
129129
Servo(0, positionsA, move),

0 commit comments

Comments
 (0)