fixed bit packing issue with keyframe data

master
Jake 2025-09-28 16:37:32 +08:00
parent 3b810e79c5
commit a31cefd3f6
3 changed files with 33 additions and 10 deletions

View File

@ -52,13 +52,15 @@ void setup() {
return;
}
// sweep.clear();
// sweep.createSampleSweep(4);
// sweep.saveToFile("/sweep.anim");
sweep.clear();
sweep.createSampleSweep(4);
sweep.saveToFile("/sweep.anim");
// sweep.clear();
// sweep.createStaggeredSweep(4);
// sweep.saveToFile("/stagger.anim");
// delay(9999);
//delay(9999);
sweep.printKeyframes();
// anim.clear();
// if (!sweep.loadFromFile("/sweep.anim")) {

View File

@ -39,7 +39,21 @@ const std::vector<Keyframe>& Animation::getKeyframes() const {
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() {
memset(data, 0, sizeof(data));
@ -88,6 +102,8 @@ bool Animation::saveToFile(const char* filename) {
file.write((uint8_t*)&kf.position, sizeof(kf.position));
}
file.close();
return true;
}
@ -118,6 +134,7 @@ bool Animation::loadFromFile(const char* filename) {
return false;
}
// Read keyframe count
uint16_t 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);
}
file.close();
return true;
}
@ -174,6 +192,7 @@ void Animation::createSampleSweep(uint8_t seconds) {
addKeyframe(ch, sweepFrames - 1, 1023); // Peak
addKeyframe(ch, totalFrames - 1, 0); // Return to 0
}
}
void Animation::createStaggeredSweep(uint8_t seconds) {

View File

@ -6,6 +6,7 @@
#include "FFat.h"
#include <vector>
#define NUM_CHANNELS 5
#define FRAMES_PER_SECOND 50
#define MAX_DURATION_SECONDS 10
@ -19,14 +20,14 @@ struct AnimationHeader {
uint8_t reserved[8]; // 815
};
struct Keyframe {
struct __attribute__((packed)) Keyframe {
uint8_t motorId;
uint16_t frame;
uint16_t position;
};
class Animation {
public:
Animation();
@ -37,7 +38,7 @@ public:
void addKeyframe(uint8_t motorId, uint16_t frame, uint16_t position);
const std::vector<Keyframe>& getKeyframes() const;
void printKeyframes();
void clear();
uint16_t* getRawData(); // Optional: for bulk access
size_t getSize() const;
@ -51,6 +52,7 @@ private:
AnimationHeader header;
uint16_t data[MAX_FRAMES][NUM_CHANNELS];
std::vector<Keyframe> keyframes;
};
#endif