fixed bit packing issue with keyframe data
parent
3b810e79c5
commit
a31cefd3f6
|
|
@ -52,13 +52,15 @@ void setup() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sweep.clear();
|
sweep.clear();
|
||||||
// sweep.createSampleSweep(4);
|
sweep.createSampleSweep(4);
|
||||||
// sweep.saveToFile("/sweep.anim");
|
sweep.saveToFile("/sweep.anim");
|
||||||
// sweep.clear();
|
// sweep.clear();
|
||||||
// sweep.createStaggeredSweep(4);
|
// sweep.createStaggeredSweep(4);
|
||||||
// sweep.saveToFile("/stagger.anim");
|
// sweep.saveToFile("/stagger.anim");
|
||||||
// delay(9999);
|
//delay(9999);
|
||||||
|
sweep.printKeyframes();
|
||||||
|
|
||||||
|
|
||||||
// anim.clear();
|
// anim.clear();
|
||||||
// if (!sweep.loadFromFile("/sweep.anim")) {
|
// if (!sweep.loadFromFile("/sweep.anim")) {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,21 @@ const std::vector<Keyframe>& Animation::getKeyframes() const {
|
||||||
return keyframes;
|
return keyframes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Animation::printKeyframes() {
|
||||||
|
const std::vector<Keyframe>& frames = getKeyframes();
|
||||||
|
Serial.println("Keyframes:");
|
||||||
|
for (size_t i = 0; i < frames.size(); ++i) {
|
||||||
|
const Keyframe& kf = frames[i];
|
||||||
|
Serial.print(" [");
|
||||||
|
Serial.print(i);
|
||||||
|
Serial.print("] Motor ID: ");
|
||||||
|
Serial.print(kf.motorId);
|
||||||
|
Serial.print(", Frame: ");
|
||||||
|
Serial.print(kf.frame);
|
||||||
|
Serial.print(", Position: ");
|
||||||
|
Serial.println(kf.position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Animation::clear() {
|
void Animation::clear() {
|
||||||
memset(data, 0, sizeof(data));
|
memset(data, 0, sizeof(data));
|
||||||
|
|
@ -77,7 +91,7 @@ bool Animation::saveToFile(const char* filename) {
|
||||||
file.write((uint8_t*)&header, sizeof(header));
|
file.write((uint8_t*)&header, sizeof(header));
|
||||||
file.write((uint8_t*)data, sizeof(data));
|
file.write((uint8_t*)data, sizeof(data));
|
||||||
|
|
||||||
// Write keyframe count
|
// Write keyframe count
|
||||||
uint16_t keyframeCount = keyframes.size();
|
uint16_t keyframeCount = keyframes.size();
|
||||||
file.write((uint8_t*)&keyframeCount, sizeof(keyframeCount));
|
file.write((uint8_t*)&keyframeCount, sizeof(keyframeCount));
|
||||||
|
|
||||||
|
|
@ -88,6 +102,8 @@ bool Animation::saveToFile(const char* filename) {
|
||||||
file.write((uint8_t*)&kf.position, sizeof(kf.position));
|
file.write((uint8_t*)&kf.position, sizeof(kf.position));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -118,6 +134,7 @@ bool Animation::loadFromFile(const char* filename) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Read keyframe count
|
// Read keyframe count
|
||||||
uint16_t keyframeCount;
|
uint16_t keyframeCount;
|
||||||
if (file.read((uint8_t*)&keyframeCount, sizeof(keyframeCount)) != sizeof(keyframeCount)) {
|
if (file.read((uint8_t*)&keyframeCount, sizeof(keyframeCount)) != sizeof(keyframeCount)) {
|
||||||
|
|
@ -138,6 +155,7 @@ bool Animation::loadFromFile(const char* filename) {
|
||||||
keyframes.push_back(kf);
|
keyframes.push_back(kf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -174,6 +192,7 @@ void Animation::createSampleSweep(uint8_t seconds) {
|
||||||
addKeyframe(ch, sweepFrames - 1, 1023); // Peak
|
addKeyframe(ch, sweepFrames - 1, 1023); // Peak
|
||||||
addKeyframe(ch, totalFrames - 1, 0); // Return to 0
|
addKeyframe(ch, totalFrames - 1, 0); // Return to 0
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animation::createStaggeredSweep(uint8_t seconds) {
|
void Animation::createStaggeredSweep(uint8_t seconds) {
|
||||||
|
|
|
||||||
10
animation.h
10
animation.h
|
|
@ -6,6 +6,7 @@
|
||||||
#include "FFat.h"
|
#include "FFat.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
#define NUM_CHANNELS 5
|
#define NUM_CHANNELS 5
|
||||||
#define FRAMES_PER_SECOND 50
|
#define FRAMES_PER_SECOND 50
|
||||||
#define MAX_DURATION_SECONDS 10
|
#define MAX_DURATION_SECONDS 10
|
||||||
|
|
@ -19,14 +20,14 @@ struct AnimationHeader {
|
||||||
uint8_t reserved[8]; // 8–15
|
uint8_t reserved[8]; // 8–15
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct __attribute__((packed)) Keyframe {
|
||||||
struct Keyframe {
|
|
||||||
uint8_t motorId;
|
uint8_t motorId;
|
||||||
uint16_t frame;
|
uint16_t frame;
|
||||||
uint16_t position;
|
uint16_t position;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Animation {
|
class Animation {
|
||||||
public:
|
public:
|
||||||
Animation();
|
Animation();
|
||||||
|
|
@ -37,7 +38,7 @@ public:
|
||||||
|
|
||||||
void addKeyframe(uint8_t motorId, uint16_t frame, uint16_t position);
|
void addKeyframe(uint8_t motorId, uint16_t frame, uint16_t position);
|
||||||
const std::vector<Keyframe>& getKeyframes() const;
|
const std::vector<Keyframe>& getKeyframes() const;
|
||||||
|
void printKeyframes();
|
||||||
void clear();
|
void clear();
|
||||||
uint16_t* getRawData(); // Optional: for bulk access
|
uint16_t* getRawData(); // Optional: for bulk access
|
||||||
size_t getSize() const;
|
size_t getSize() const;
|
||||||
|
|
@ -50,7 +51,8 @@ public:
|
||||||
private:
|
private:
|
||||||
AnimationHeader header;
|
AnimationHeader header;
|
||||||
uint16_t data[MAX_FRAMES][NUM_CHANNELS];
|
uint16_t data[MAX_FRAMES][NUM_CHANNELS];
|
||||||
std::vector<Keyframe> keyframes;
|
std::vector<Keyframe> keyframes;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue