HansonServo/nodegraph.h

58 lines
1.0 KiB
C++

#pragma once
#include <vector>
#include <cstdint>
#include <Arduino.h>
#define TYPE_NODE 0x01
#define TYPE_SERVONODE 0x02
#define TYPE_CURVENODE 0x03
#define TYPE_NOISENODE 0x04
// Base Node class
struct Node {
uint8_t id;
uint8_t type;
uint16_t x;
uint16_t y;
virtual void evaluate(uint32_t tick) = 0;
virtual ~Node() {}
};
// CurveNode: evaluates a curve at a given tick
struct CurveNode : public Node {
uint8_t curveID;
uint16_t outputValue;
void evaluate(uint32_t tick) override;
};
// ServoNode: sends a value to a motor
struct ServoNode : public Node {
uint8_t motorID;
uint16_t inputValue;
void evaluate(uint32_t tick) override;
};
// NodeGraph container
struct NodeConnection {
uint8_t fromID;
uint8_t toID;
};
class NodeGraph {
public:
std::vector<Node*> nodes;
std::vector<NodeConnection> connections;
void tick(uint32_t currentTick);
};
// Loader function
void loadNodeGraph(const uint8_t* packet, size_t length, NodeGraph& graph);
String printNodeGraph(const NodeGraph& graph);