Skip to content

Commit 18d97c0

Browse files
committed
simplify src structure and rename live classes
1 parent 7a616c5 commit 18d97c0

File tree

15 files changed

+45
-45
lines changed

15 files changed

+45
-45
lines changed

examples/LiveModeESP32WebSocket/LiveModeESP32WebSocket.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ BlenderServoAnimation::Servo myBlenderServo(0, move);
3939

4040
// Live mode stream instance acting as a middleware between web socket and
4141
// animation object
42-
BlenderServoAnimation::Live live;
42+
BlenderServoAnimation::LiveStream liveStream;
4343

4444
// Handler function writing data to the live stream instance when receiving data
4545
void onWebSocketEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
@@ -49,7 +49,7 @@ void onWebSocketEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
4949
}
5050

5151
for (size_t i = 0; i < len; i++) {
52-
live.write(data[i]);
52+
liveStream.write(data[i]);
5353
}
5454
}
5555

@@ -76,7 +76,7 @@ void setup() {
7676
animation.addServo(myBlenderServo);
7777

7878
// Trigger the animation live mode
79-
animation.live(live);
79+
animation.live(liveStream);
8080
}
8181

8282
void loop() {
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "animation/Animation.h"
2-
#include "servo/Servo.h"
1+
#include "Animation.h"
2+
#include "Servo.h"
33
#include <Arduino.h>
44

55
using namespace BlenderServoAnimation;
@@ -112,14 +112,14 @@ void Animation::handleStopMode() {
112112

113113
void Animation::handleLiveMode() {
114114
while (this->liveStream->available() > 0) {
115-
this->command.read(this->liveStream);
115+
this->liveCommand.read(this->liveStream);
116116

117-
if (!this->command.isComplete() || !this->command.isValid()) {
117+
if (!this->liveCommand.isComplete() || !this->liveCommand.isValid()) {
118118
continue;
119119
}
120120

121-
byte id = this->command.getServoID();
122-
int position = this->command.getServoPosition();
121+
byte id = this->liveCommand.getServoID();
122+
int position = this->liveCommand.getServoPosition();
123123

124124
for (int i = 0; i < MAX_SERVO_COUNT; i++) {
125125
Servo *servo = this->servos[i];
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "command/Command.h"
2-
#include "servo/Servo.h"
1+
#include "LiveCommand.h"
2+
#include "Servo.h"
33
#include <Arduino.h>
44
#include <stdarg.h>
55

@@ -30,7 +30,7 @@ class Animation {
3030

3131
Servo *servos[MAX_SERVO_COUNT] = {};
3232
Stream *liveStream;
33-
Command command;
33+
LiveCommand liveCommand;
3434
mcb modeCallback = nullptr;
3535

3636
void changeMode(byte mode);

src/BlenderServoAnimation.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "animation/Animation.h"
2-
#include "live/Live.h"
3-
#include "servo/Servo.h"
4-
#include "show/Show.h"
1+
#include "Animation.h"
2+
#include "LiveStream.h"
3+
#include "Servo.h"
4+
#include "Show.h"
55
#include <Arduino.h>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "command/Command.h"
1+
#include "LiveCommand.h"
22
#include <Arduino.h>
33

44
using namespace BlenderServoAnimation;
55

6-
void Command::read(Stream *liveStream) {
6+
void LiveCommand::read(Stream *liveStream) {
77
byte receivedByte = liveStream->read();
88

99
if (!this->receiving && receivedByte != START_MARKER) {
@@ -29,20 +29,20 @@ void Command::read(Stream *liveStream) {
2929
}
3030
}
3131

32-
bool Command::isValid() {
32+
bool LiveCommand::isValid() {
3333
return this->receivedBytes[0] == START_MARKER &&
3434
this->receivedBytes[LENGTH - 1] == END_MARKER;
3535
}
3636

37-
bool Command::isComplete() {
37+
bool LiveCommand::isComplete() {
3838
return this->complete;
3939
}
4040

41-
byte Command::getServoID() {
41+
byte LiveCommand::getServoID() {
4242
return this->receivedBytes[INDEX_SERVO_ID];
4343
}
4444

45-
int Command::getServoPosition() {
45+
int LiveCommand::getServoPosition() {
4646
return this->receivedBytes[INDEX_POSITION_BYTE] |
4747
this->receivedBytes[INDEX_POSITION_SIG_BYTE] << BITS;
4848
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace BlenderServoAnimation {
77

8-
class Command {
8+
class LiveCommand {
99

1010
private:
1111
static const byte START_MARKER = 0x3C;
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
#include "Live.h"
1+
#include "LiveStream.h"
22
#include <Arduino.h>
33

44
using namespace BlenderServoAnimation;
55

6-
int Live::available() {
6+
int LiveStream::available() {
77
return this->readIndex != this->writeIndex;
88
}
99

10-
int Live::peek() {
10+
int LiveStream::peek() {
1111
return this->buffer[this->readIndex];
1212
}
1313

14-
int Live::read() {
14+
int LiveStream::read() {
1515
int value = this->buffer[this->readIndex++];
1616

1717
if (this->readIndex >= BUFFER_SIZE) {
@@ -21,7 +21,7 @@ int Live::read() {
2121
return value;
2222
}
2323

24-
size_t Live::write(uint8_t value) {
24+
size_t LiveStream::write(uint8_t value) {
2525
this->buffer[this->writeIndex++] = value;
2626

2727
if (this->writeIndex >= BUFFER_SIZE) {
@@ -31,7 +31,7 @@ size_t Live::write(uint8_t value) {
3131
return 1;
3232
}
3333

34-
void Live::flush() {
34+
void LiveStream::flush() {
3535
for (int i = 0; i < BUFFER_SIZE; i++) {
3636
this->buffer[i] = 0;
3737
}

src/live/Live.h renamed to src/LiveStream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace BlenderServoAnimation {
77

8-
class Live : public Stream {
8+
class LiveStream : public Stream {
99
private:
1010
static const byte BUFFER_SIZE = 20;
1111

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "servo/Servo.h"
1+
#include "Servo.h"
22
#include <Arduino.h>
33

44
using namespace BlenderServoAnimation;
File renamed without changes.

0 commit comments

Comments
 (0)