2025-10-14 16:39:54 +00:00
|
|
|
|
#pragma once
|
2025-09-28 06:59:29 +00:00
|
|
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
#include "FS.h"
|
|
|
|
|
|
#include "FFat.h"
|
2025-10-08 16:04:29 +00:00
|
|
|
|
#include <unordered_map>
|
2025-10-14 16:39:54 +00:00
|
|
|
|
#include "nodegraph.h"
|
2025-09-28 06:59:29 +00:00
|
|
|
|
|
2025-09-28 08:37:32 +00:00
|
|
|
|
|
2025-10-18 15:21:24 +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-10-07 06:26:49 +00:00
|
|
|
|
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
|
2025-10-07 06:26:49 +00:00
|
|
|
|
// remapped from -1 to 1 → 0–65535
|
2025-10-10 15:12:08 +00:00
|
|
|
|
int16_t startPointY;
|
2025-10-08 07:38:44 +00:00
|
|
|
|
uint16_t startHandleX;
|
2025-10-10 15:12:08 +00:00
|
|
|
|
int16_t startHandleY;
|
2025-10-08 07:38:44 +00:00
|
|
|
|
uint16_t endHandleX;
|
2025-10-10 15:12:08 +00:00
|
|
|
|
int16_t endHandleY;
|
|
|
|
|
|
int16_t endPointY;
|
2025-09-28 06:59:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-28 08:37:32 +00:00
|
|
|
|
|
2025-10-07 06:26:49 +00:00
|
|
|
|
|
2025-09-28 06:59:29 +00:00
|
|
|
|
class Animation {
|
|
|
|
|
|
public:
|
|
|
|
|
|
Animation();
|
2025-10-18 15:21:24 +00:00
|
|
|
|
bool isActive() const { return active; }
|
|
|
|
|
|
void setActive(bool state);
|
|
|
|
|
|
|
2025-09-28 06:59:29 +00:00
|
|
|
|
|
|
|
|
|
|
void setFrame(uint16_t frameIndex, uint16_t channel, uint16_t value);
|
|
|
|
|
|
uint16_t getFrame(uint16_t frameIndex, uint16_t channel) const;
|
|
|
|
|
|
|
2025-10-07 06:26:49 +00:00
|
|
|
|
void addCurveSegment(const CurveSegment& segment);
|
|
|
|
|
|
void clearCurves(uint8_t motorID);
|
|
|
|
|
|
void clearAllCurves();
|
2025-10-18 15:21:24 +00:00
|
|
|
|
String printCurves();
|
2025-10-07 06:26:49 +00:00
|
|
|
|
uint16_t getMotorPosition(uint8_t motorID, uint16_t timeCS);
|
|
|
|
|
|
|
2025-09-28 06:59:29 +00:00
|
|
|
|
void clear();
|
2025-10-08 07:38:44 +00:00
|
|
|
|
//uint16_t* getRawData(); // Optional: for bulk access
|
|
|
|
|
|
//size_t getSize() const;
|
2025-09-28 06:59:29 +00:00
|
|
|
|
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();
|
2025-09-28 10:24:46 +00:00
|
|
|
|
AnimationHeader header;
|
2025-10-14 16:39:54 +00:00
|
|
|
|
NodeGraph nodeGraph;
|
|
|
|
|
|
|
2025-09-28 06:59:29 +00:00
|
|
|
|
|
|
|
|
|
|
private:
|
2025-10-08 07:38:44 +00:00
|
|
|
|
//uint16_t data[MAX_FRAMES][NUM_CHANNELS];
|
2025-10-08 16:04:29 +00:00
|
|
|
|
std::unordered_map<uint8_t, std::vector<CurveSegment>> curves;
|
2025-10-18 15:21:24 +00:00
|
|
|
|
bool active = false;
|
2025-09-28 06:59:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
|