2025-09-28 06:59:29 +00:00
|
|
|
|
#ifndef ANIMATION_FILE_H
|
|
|
|
|
|
#define ANIMATION_FILE_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
#include "FS.h"
|
|
|
|
|
|
#include "FFat.h"
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
2025-09-28 08:37:32 +00:00
|
|
|
|
|
2025-09-28 06:59:29 +00:00
|
|
|
|
#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]; // 0–3 ANIM tag
|
|
|
|
|
|
uint16_t frameCount; // 4–5 Number of total frames
|
|
|
|
|
|
uint8_t version; // 6
|
|
|
|
|
|
uint8_t frameRate; // 7 Frames per second
|
|
|
|
|
|
uint8_t reserved[8]; // 8–15
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-28 08:37:32 +00:00
|
|
|
|
struct __attribute__((packed)) Keyframe {
|
2025-09-28 06:59:29 +00:00
|
|
|
|
uint8_t motorId;
|
|
|
|
|
|
uint16_t frame;
|
|
|
|
|
|
uint16_t position;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-28 08:37:32 +00:00
|
|
|
|
|
2025-09-28 06:59:29 +00:00
|
|
|
|
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 addKeyframe(uint8_t motorId, uint16_t frame, uint16_t position);
|
|
|
|
|
|
const std::vector<Keyframe>& getKeyframes() const;
|
2025-09-28 08:37:32 +00:00
|
|
|
|
void printKeyframes();
|
2025-09-28 06:59:29 +00:00
|
|
|
|
void clear();
|
|
|
|
|
|
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;
|
|
|
|
|
|
void createSampleSweep(uint8_t seconds);
|
|
|
|
|
|
void createStaggeredSweep(uint8_t seconds);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
AnimationHeader header;
|
|
|
|
|
|
uint16_t data[MAX_FRAMES][NUM_CHANNELS];
|
2025-09-28 08:37:32 +00:00
|
|
|
|
std::vector<Keyframe> keyframes;
|
|
|
|
|
|
|
2025-09-28 06:59:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|