diff --git a/examples/MultipleScenesSD/MultipleScenesSD.ino b/examples/MultipleScenesSD/MultipleScenesSD.ino index 861f969..c38e803 100644 --- a/examples/MultipleScenesSD/MultipleScenesSD.ino +++ b/examples/MultipleScenesSD/MultipleScenesSD.ino @@ -16,7 +16,7 @@ #define SERVO_PIN 3 #define CS_PIN 4 -#define SCENE_AMOUNT 2 +#define SCENE_AMOUNT = 2 // Servo object to send positions Servo myServo; diff --git a/src/BlenderServoAnimation.cpp b/src/BlenderServoAnimation.cpp index 15e7e0f..cfdb090 100644 --- a/src/BlenderServoAnimation.cpp +++ b/src/BlenderServoAnimation.cpp @@ -322,16 +322,16 @@ Scene *BlenderServoAnimation::getCurrentScene() { return this->scene; } -void BlenderServoAnimation::onPositionChange(PositionCallback callback) { - this->servoManager.setPositionCallback(callback); +void BlenderServoAnimation::onPositionChange(pcb positionCallback) { + this->servoManager.setPositionCallback(positionCallback); } -void BlenderServoAnimation::onModeChange(ModeCallback callback) { - this->modeCallback = callback; +void BlenderServoAnimation::onModeChange(mcb modeCallback) { + this->modeCallback = modeCallback; } -void BlenderServoAnimation::onSceneChange(SceneCallback callback) { - this->sceneCallback = callback; +void BlenderServoAnimation::onSceneChange(scb sceneCallback) { + this->sceneCallback = sceneCallback; } void BlenderServoAnimation::changeMode(byte mode) { diff --git a/src/BlenderServoAnimation.h b/src/BlenderServoAnimation.h index a8bcc20..5524443 100644 --- a/src/BlenderServoAnimation.h +++ b/src/BlenderServoAnimation.h @@ -1,7 +1,7 @@ #include "AnimationData.h" #include "Scene.h" #include "ServoManager.h" -#include "CommonTypes.h" +#include "typedefs.h" #include #include @@ -31,9 +31,9 @@ class BlenderServoAnimation { void addScene(const byte *data, int size, byte fps, int frames); void addScene(Stream &stream, byte fps, int frame); - void onPositionChange(PositionCallback callback); - void onModeChange(ModeCallback callback); - void onSceneChange(SceneCallback callback); + void onPositionChange(pcb positionCallback); + void onModeChange(mcb modeCallback); + void onSceneChange(scb sceneCallback); void run(unsigned long currentMicros = micros()); void play(); void playSingle(byte index); @@ -65,8 +65,8 @@ class BlenderServoAnimation { bool *playedIndexes = nullptr; - ModeCallback modeCallback = nullptr; - SceneCallback sceneCallback = nullptr; + mcb modeCallback = nullptr; + scb sceneCallback = nullptr; byte mode = MODE_DEFAULT; diff --git a/src/CommonTypes.h b/src/CommonTypes.h deleted file mode 100644 index f19eac3..0000000 --- a/src/CommonTypes.h +++ /dev/null @@ -1,10 +0,0 @@ -#include - -#ifndef BlenderServoAnimationLibrary_CommonTypes_H -#define BlenderServoAnimationLibrary_CommonTypes_H - -typedef void (*ModeCallback)(byte, byte); -typedef void (*PositionCallback)(byte, int); -typedef void (*SceneCallback)(byte, byte); - -#endif // BlenderServoAnimationLibrary_CommonTypes_H diff --git a/src/Servo.cpp b/src/Servo.cpp index 42bd969..6d86537 100644 --- a/src/Servo.cpp +++ b/src/Servo.cpp @@ -1,10 +1,10 @@ #include "Servo.h" -#include "CommonTypes.h" +#include "typedefs.h" #include using BlenderServoAnimationLibrary::Servo; -Servo::Servo(byte id, PositionCallback callback, byte threshold) { +Servo::Servo(byte id, pcb positionCallback, byte threshold) { this->id = id; this->positionCallback = positionCallback; this->setThreshold(threshold); @@ -53,8 +53,8 @@ bool Servo::isNeutral() { return this->currentPosition == this->neutralPosition; } -void Servo::setPositionCallback(PositionCallback callback) { - this->positionCallback = callback; +void Servo::setPositionCallback(pcb positionCallback) { + this->positionCallback = positionCallback; } void Servo::setThreshold(byte value) { diff --git a/src/Servo.h b/src/Servo.h index cd64150..1470cf3 100644 --- a/src/Servo.h +++ b/src/Servo.h @@ -1,4 +1,4 @@ -#include "CommonTypes.h" +#include "typedefs.h" #include #ifndef BlenderServoAnimationLibrary_Servo_H @@ -9,13 +9,13 @@ namespace BlenderServoAnimationLibrary { class Servo { public: - Servo(byte id, PositionCallback callback, byte threshold = 0); + Servo(byte id, pcb positionCallback, byte threshold = 0); void move(int position, bool useOffset = true); void moveTowardsNeutral(); void setThreshold(byte value); void setOffset(int offset); - void setPositionCallback(PositionCallback callback); + void setPositionCallback(pcb positionCallback); bool isNeutral(); @@ -32,7 +32,7 @@ class Servo { int currentPosition = -1; int offset = 0; - PositionCallback positionCallback = nullptr; + pcb positionCallback = nullptr; bool positionExceedsThreshold(int position); }; diff --git a/src/ServoManager.cpp b/src/ServoManager.cpp index fc547e4..d9eba8f 100644 --- a/src/ServoManager.cpp +++ b/src/ServoManager.cpp @@ -11,11 +11,11 @@ ServoManager::~ServoManager() { } } -void ServoManager::setPositionCallback(PositionCallback callback) { - this->positionCallback = callback; +void ServoManager::setPositionCallback(pcb positionCallback) { + this->positionCallback = positionCallback; for (byte i = 0; i < this->servoAmount; i++) { - this->servos[i]->setPositionCallback(callback); + this->servos[i]->setPositionCallback(positionCallback); } } diff --git a/src/ServoManager.h b/src/ServoManager.h index 3f67bb3..11f8b98 100644 --- a/src/ServoManager.h +++ b/src/ServoManager.h @@ -1,7 +1,7 @@ #include "AnimationData.h" #include "Command.h" #include "Servo.h" -#include "CommonTypes.h" +#include "typedefs.h" #include #ifndef BlenderServoAnimationLibrary_ServoManager_H @@ -14,7 +14,7 @@ class ServoManager { public: ~ServoManager(); - void setPositionCallback(PositionCallback callback); + void setPositionCallback(pcb positionCallback); void setDefaultThreshold(byte value); void setThreshold(byte servoId, byte value); void setOffset(byte servoId, int offset); @@ -28,7 +28,7 @@ class ServoManager { Command command; - PositionCallback positionCallback = nullptr; + pcb positionCallback = nullptr; byte servoAmount = 0; byte defaultThreshold = 0; diff --git a/src/typedefs.h b/src/typedefs.h new file mode 100644 index 0000000..d9e464a --- /dev/null +++ b/src/typedefs.h @@ -0,0 +1,5 @@ +#include + +typedef void (*mcb)(byte, byte); // Mode callback +typedef void (*pcb)(byte, int); // Position callback +typedef void (*scb)(byte, byte); // Scene callback