Skip to content

Commit 76b828f

Browse files
committed
put common types into namespace
1 parent 490e7f3 commit 76b828f

11 files changed

+48
-43
lines changed

examples/MultipleScenesSD/MultipleScenesSD.ino

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

1717
#define SERVO_PIN 3
1818
#define CS_PIN 4
19-
#define SCENE_AMOUNT = 2
19+
#define SCENE_AMOUNT 2
2020

2121
// Servo object to send positions
2222
Servo myServo;

src/BlenderServoAnimation.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include "BlenderServoAnimation.h"
2-
#include "AnimationData.h"
32
#include <Arduino.h>
43

5-
using BlenderServoAnimationLibrary::Scene;
6-
74
BlenderServoAnimation::~BlenderServoAnimation() {
85
if (this->scenes) {
96
delete[] this->scenes;
@@ -322,16 +319,16 @@ Scene *BlenderServoAnimation::getCurrentScene() {
322319
return this->scene;
323320
}
324321

325-
void BlenderServoAnimation::onPositionChange(pcb positionCallback) {
326-
this->servoManager.setPositionCallback(positionCallback);
322+
void BlenderServoAnimation::onPositionChange(PositionCallback callback) {
323+
this->servoManager.setPositionCallback(callback);
327324
}
328325

329-
void BlenderServoAnimation::onModeChange(mcb modeCallback) {
330-
this->modeCallback = modeCallback;
326+
void BlenderServoAnimation::onModeChange(ModeCallback callback) {
327+
this->modeCallback = callback;
331328
}
332329

333-
void BlenderServoAnimation::onSceneChange(scb sceneCallback) {
334-
this->sceneCallback = sceneCallback;
330+
void BlenderServoAnimation::onSceneChange(SceneCallback callback) {
331+
this->sceneCallback = callback;
335332
}
336333

337334
void BlenderServoAnimation::changeMode(byte mode) {

src/BlenderServoAnimation.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "AnimationData.h"
22
#include "Scene.h"
33
#include "ServoManager.h"
4-
#include "typedefs.h"
4+
#include "CommonTypes.h"
55
#include <Arduino.h>
66
#include <stdarg.h>
77

@@ -11,6 +11,9 @@
1111
using BlenderServoAnimationLibrary::AnimationData;
1212
using BlenderServoAnimationLibrary::Scene;
1313
using BlenderServoAnimationLibrary::ServoManager;
14+
using BlenderServoAnimationLibrary::ModeCallback;
15+
using BlenderServoAnimationLibrary::PositionCallback;
16+
using BlenderServoAnimationLibrary::SceneCallback;
1417

1518
class BlenderServoAnimation {
1619

@@ -31,9 +34,9 @@ class BlenderServoAnimation {
3134

3235
void addScene(const byte *data, int size, byte fps, int frames);
3336
void addScene(Stream &stream, byte fps, int frame);
34-
void onPositionChange(pcb positionCallback);
35-
void onModeChange(mcb modeCallback);
36-
void onSceneChange(scb sceneCallback);
37+
void onPositionChange(PositionCallback callback);
38+
void onModeChange(ModeCallback callback);
39+
void onSceneChange(SceneCallback callback);
3740
void run(unsigned long currentMicros = micros());
3841
void play();
3942
void playSingle(byte index);
@@ -65,8 +68,8 @@ class BlenderServoAnimation {
6568

6669
bool *playedIndexes = nullptr;
6770

68-
mcb modeCallback = nullptr;
69-
scb sceneCallback = nullptr;
71+
ModeCallback modeCallback = nullptr;
72+
SceneCallback sceneCallback = nullptr;
7073

7174
byte mode = MODE_DEFAULT;
7275

src/CommonTypes.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <Arduino.h>
2+
3+
#ifndef BlenderServoAnimationLibrary_CommonTypes_H
4+
#define BlenderServoAnimationLibrary_CommonTypes_H
5+
6+
namespace BlenderServoAnimationLibrary {
7+
8+
typedef void (*ModeCallback)(byte, byte); // Mode callback
9+
typedef void (*PositionCallback)(byte, int); // Position callback
10+
typedef void (*SceneCallback)(byte, byte); // Scene callback
11+
12+
} // BlenderServoAnimationLibrary
13+
14+
#endif

src/Scene.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#include "Scene.h"
2-
#include "Command.h"
3-
#include "Servo.h"
42
#include <Arduino.h>
53

64
using BlenderServoAnimationLibrary::Scene;

src/Servo.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#include "Servo.h"
2-
#include "typedefs.h"
32
#include <Arduino.h>
43

54
using BlenderServoAnimationLibrary::Servo;
65

7-
Servo::Servo(byte id, pcb positionCallback, byte threshold) {
6+
Servo::Servo(byte id, PositionCallback callback, byte threshold) {
87
this->id = id;
9-
this->positionCallback = positionCallback;
8+
this->positionCallback = callback;
109
this->setThreshold(threshold);
1110
}
1211

@@ -53,8 +52,8 @@ bool Servo::isNeutral() {
5352
return this->currentPosition == this->neutralPosition;
5453
}
5554

56-
void Servo::setPositionCallback(pcb positionCallback) {
57-
this->positionCallback = positionCallback;
55+
void Servo::setPositionCallback(PositionCallback callback) {
56+
this->positionCallback = callback;
5857
}
5958

6059
void Servo::setThreshold(byte value) {

src/Servo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "typedefs.h"
1+
#include "CommonTypes.h"
22
#include <Arduino.h>
33

44
#ifndef BlenderServoAnimationLibrary_Servo_H
@@ -9,13 +9,13 @@ namespace BlenderServoAnimationLibrary {
99
class Servo {
1010

1111
public:
12-
Servo(byte id, pcb positionCallback, byte threshold = 0);
12+
Servo(byte id, PositionCallback callback, byte threshold = 0);
1313

1414
void move(int position, bool useOffset = true);
1515
void moveTowardsNeutral();
1616
void setThreshold(byte value);
1717
void setOffset(int offset);
18-
void setPositionCallback(pcb positionCallback);
18+
void setPositionCallback(PositionCallback callback);
1919

2020
bool isNeutral();
2121

@@ -32,7 +32,7 @@ class Servo {
3232
int currentPosition = -1;
3333
int offset = 0;
3434

35-
pcb positionCallback = nullptr;
35+
PositionCallback positionCallback = nullptr;
3636

3737
bool positionExceedsThreshold(int position);
3838
};

src/ServoManager.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "ServoManager.h"
2-
#include "Servo.h"
32
#include <Arduino.h>
43

54
using BlenderServoAnimationLibrary::Servo;
@@ -11,11 +10,11 @@ ServoManager::~ServoManager() {
1110
}
1211
}
1312

14-
void ServoManager::setPositionCallback(pcb positionCallback) {
15-
this->positionCallback = positionCallback;
13+
void ServoManager::setPositionCallback(PositionCallback callback) {
14+
this->positionCallback = callback;
1615

1716
for (byte i = 0; i < this->servoAmount; i++) {
18-
this->servos[i]->setPositionCallback(positionCallback);
17+
this->servos[i]->setPositionCallback(callback);
1918
}
2019
}
2120

src/ServoManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "AnimationData.h"
22
#include "Command.h"
33
#include "Servo.h"
4-
#include "typedefs.h"
4+
#include "CommonTypes.h"
55
#include <Arduino.h>
66

77
#ifndef BlenderServoAnimationLibrary_ServoManager_H
@@ -14,7 +14,7 @@ class ServoManager {
1414
public:
1515
~ServoManager();
1616

17-
void setPositionCallback(pcb positionCallback);
17+
void setPositionCallback(PositionCallback callback);
1818
void setDefaultThreshold(byte value);
1919
void setThreshold(byte servoId, byte value);
2020
void setOffset(byte servoId, int offset);
@@ -28,7 +28,7 @@ class ServoManager {
2828

2929
Command command;
3030

31-
pcb positionCallback = nullptr;
31+
PositionCallback positionCallback = nullptr;
3232

3333
byte servoAmount = 0;
3434
byte defaultThreshold = 0;

src/typedefs.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/test_servo/test_servo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ void test_move_towards_neutral_with_offset(void) {
139139

140140
int main(int argc, char **argv) {
141141
UNITY_BEGIN();
142-
// RUN_TEST(test_move);
143-
// RUN_TEST(test_move_towards_neutral);
144-
// RUN_TEST(test_threshold);
145-
// RUN_TEST(test_offset);
142+
RUN_TEST(test_move);
143+
RUN_TEST(test_move_towards_neutral);
144+
RUN_TEST(test_threshold);
145+
RUN_TEST(test_offset);
146146
RUN_TEST(test_move_towards_neutral_with_offset);
147147
UNITY_END();
148148
}

0 commit comments

Comments
 (0)