File tree Expand file tree Collapse file tree 13 files changed +70
-61
lines changed
Expand file tree Collapse file tree 13 files changed +70
-61
lines changed Original file line number Diff line number Diff line change 33.vscode /c_cpp_properties.json
44.vscode /launch.json
55.vscode /ipch
6+ examples /* /.vscode
7+ examples /* /.gitignore
Original file line number Diff line number Diff line change 11#include "animation/Animation.h"
22#include "servo/Servo.h"
33#include "show/Show.h"
4+ #include "live/Live.h"
45#include <Arduino.h>
Original file line number Diff line number Diff line change @@ -111,8 +111,8 @@ void Animation::handleStopMode() {
111111}
112112
113113void Animation::handleLiveMode () {
114- while (this ->serial ->available () > 0 ) {
115- this ->command .read (this ->serial );
114+ while (this ->liveStream ->available () > 0 ) {
115+ this ->command .read (this ->liveStream );
116116
117117 if (!this ->command .isComplete () || !this ->command .isValid ()) {
118118 continue ;
@@ -168,12 +168,12 @@ void Animation::stop(byte stepDelay) {
168168 this ->changeMode (MODE_STOP);
169169}
170170
171- void Animation::live (Stream &serial ) {
171+ void Animation::live (Stream &liveStream ) {
172172 if (this ->mode != MODE_DEFAULT) {
173173 return ;
174174 }
175175
176- this ->serial = &serial ;
176+ this ->liveStream = &liveStream ;
177177 this ->changeMode (MODE_LIVE);
178178}
179179
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ class Animation {
2929 unsigned long lastMicros;
3030
3131 Servo *servos[MAX_SERVO_COUNT] = {};
32- Stream *serial ;
32+ Stream *liveStream ;
3333 Command command;
3434 mcb modeCallback = nullptr ;
3535
@@ -57,7 +57,7 @@ class Animation {
5757 void pause ();
5858 void loop (unsigned long currentMicros = micros());
5959 void stop (byte stepDelay = 20 );
60- void live (Stream &serial );
60+ void live (Stream &liveStream );
6161
6262 byte getFPS ();
6363 byte getMode ();
Original file line number Diff line number Diff line change 33
44using namespace BlenderServoAnimation ;
55
6- void Command::read (Stream *serial ) {
7- byte receivedByte = serial ->read ();
6+ void Command::read (Stream *liveStream ) {
7+ byte receivedByte = liveStream ->read ();
88
99 if (!this ->receiving && receivedByte != START_MARKER) {
1010 return ;
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ class Command {
2525 bool complete = false ;
2626
2727public:
28- void read (Stream *serial );
28+ void read (Stream *liveStream );
2929
3030 bool isValid ();
3131 bool isComplete ();
Original file line number Diff line number Diff line change 1+ #include " Live.h"
2+ #include < Arduino.h>
3+
4+ using namespace BlenderServoAnimation ;
5+
6+ int Live::available () {
7+ return this ->readIndex != this ->writeIndex ;
8+ }
9+
10+ int Live::peek () {
11+ return this ->buffer [this ->readIndex ];
12+ }
13+
14+ int Live::read () {
15+ int value = this ->buffer [this ->readIndex ++];
16+
17+ if (this ->readIndex >= BUFFER_SIZE) {
18+ this ->readIndex = 0 ;
19+ }
20+
21+ return value;
22+ }
23+
24+ size_t Live::write (uint8_t value) {
25+ this ->buffer [this ->writeIndex ++] = value;
26+
27+ if (this ->writeIndex >= BUFFER_SIZE) {
28+ this ->writeIndex = 0 ;
29+ }
30+
31+ return 1 ;
32+ }
33+
34+ void Live::flush () {
35+ for (int i = 0 ; i < BUFFER_SIZE; i++) {
36+ this ->buffer [i] = 0 ;
37+ }
38+
39+ this ->readIndex = 0 ;
40+ this ->writeIndex = 0 ;
41+ }
Original file line number Diff line number Diff line change 11#include < Arduino.h>
22
3- #ifndef BlenderServoAnimation_Serial_Mock_H
4- #define BlenderServoAnimation_Serial_Mock_H
3+ #ifndef BlenderServoAnimation_Live_H
4+ #define BlenderServoAnimation_Live_H
55
6- class SerialMock : public Stream {
6+ namespace BlenderServoAnimation {
7+
8+ class Live : public Stream {
79private:
810 static const byte BUFFER_SIZE = 20 ;
911
1012 byte buffer[BUFFER_SIZE];
11- byte readIndex = 0 ;
1213 byte writeIndex = 0 ;
14+ byte readIndex = 0 ;
1315
1416public:
1517 int available ();
@@ -23,4 +25,6 @@ class SerialMock : public Stream {
2325 void flush ();
2426};
2527
28+ } // namespace BlenderServoAnimation
29+
2630#endif
Original file line number Diff line number Diff line change @@ -113,7 +113,7 @@ void Show::stop(byte stepDelay) {
113113 this ->changeMode (MODE_STOP);
114114}
115115
116- void Show::live (Stream &serial ) {
116+ void Show::live (Stream &liveStream ) {
117117 if (!this ->hasAnimations () || this ->mode != MODE_DEFAULT) {
118118 return ;
119119 }
@@ -122,7 +122,7 @@ void Show::live(Stream &serial) {
122122 this ->animation = this ->animations [this ->playIndex ];
123123 }
124124
125- this ->animation ->live (serial );
125+ this ->animation ->live (liveStream );
126126 this ->changeMode (MODE_LIVE);
127127}
128128
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ class Show {
5252 void loop (unsigned long currentMicros = micros());
5353 void pause ();
5454 void stop (byte stepDelay = 20 );
55- void live (Stream &serial );
55+ void live (Stream &liveStream );
5656 void reset ();
5757
5858 bool hasAnimations ();
You can’t perform that action at this time.
0 commit comments