HansonServo/animation.h

71 lines
1.8 KiB
C
Raw Normal View History

#ifndef ANIMATION_FILE_H
#define ANIMATION_FILE_H
#include <Arduino.h>
#include "FS.h"
#include "FFat.h"
#include <unordered_map>
#define NUM_CHANNELS 5
#define FRAMES_PER_SECOND 50
#define MAX_DURATION_SECONDS 10
#define MAX_FRAMES (FRAMES_PER_SECOND * MAX_DURATION_SECONDS)
struct AnimationHeader {
char magic[4]; // 03 ANIM tag
uint16_t frameCount; // 45 Number of total frames
uint8_t version; // 6
uint8_t frameRate; // 7 Frames per second
uint8_t reserved[8]; // 815
};
struct __attribute__((packed)) CurveSegment {
uint8_t motorID;
2025-10-08 07:38:44 +00:00
uint16_t startTime;// centiseconds (0.01s) MAX 655.35 seconds
uint16_t endTime;// centiseconds (0.01s) MAX 655.35 seconds
// remapped from -1 to 1 → 065535
2025-10-08 07:38:44 +00:00
uint16_t startPointY;
uint16_t startHandleX;
uint16_t startHandleY;
uint16_t endHandleX;
uint16_t endHandleY;
uint16_t endPointY;
};
class Animation {
public:
Animation();
void setFrame(uint16_t frameIndex, uint16_t channel, uint16_t value);
uint16_t getFrame(uint16_t frameIndex, uint16_t channel) const;
bool getFramePositions(uint16_t frameIndex, uint16_t* outPositions);
void addCurveSegment(const CurveSegment& segment);
void clearCurves(uint8_t motorID);
void clearAllCurves();
2025-10-08 07:38:44 +00:00
void printCurves();
uint16_t getMotorPosition(uint8_t motorID, uint16_t timeCS);
void clear();
2025-10-08 07:38:44 +00:00
//uint16_t* getRawData(); // Optional: for bulk access
//size_t getSize() const;
bool saveToFile(const char* filename);
bool loadFromFile(const char* filename);
uint16_t getFrameCount() const;
2025-10-08 07:38:44 +00:00
void setFrameCount(uint16_t count);
void createBasicSCurve();
void createEaseOutCurve();
AnimationHeader header;
private:
2025-10-08 07:38:44 +00:00
//uint16_t data[MAX_FRAMES][NUM_CHANNELS];
std::unordered_map<uint8_t, std::vector<CurveSegment>> curves;
};
#endif