HansonServo/animation.h

67 lines
1.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef ANIMATION_FILE_H
#define ANIMATION_FILE_H
#include <Arduino.h>
#include "FS.h"
#include "FFat.h"
#include <vector>
#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;
uint16_t startTime; // centiseconds (0.01s) MAX 655.35 seconds
uint16_t endTime;
// remapped from -1 to 1 → 065535
uint16_t startPoint; // start value
uint16_t startHandle; // start handle
uint16_t endPoint; // end value
uint16_t endHandle; // end handle
};
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();
uint16_t getMotorPosition(uint8_t motorID, uint16_t timeCS);
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);
AnimationHeader header;
private:
uint16_t data[MAX_FRAMES][NUM_CHANNELS];
std::vector<CurveSegment> curves[NUM_CHANNELS]; // One list per motor channel
};
#endif