imu and current frame streaming

protocolv2
Jake 2025-12-11 11:01:17 +08:00
parent 7ddb756497
commit db0297cea9
4 changed files with 53 additions and 28 deletions

View File

@ -119,6 +119,16 @@ void runNodeAnimation() {
);
}
// Emit per-frame event: [frameLo, frameHi, playMode, status=0]
{
uint8_t payload[4];
payload[0] = currentTick & 0xFF;
payload[1] = (currentTick >> 8) & 0xFF;
payload[2] = static_cast<uint8_t>(animState.playMode);
payload[3] = 0; // in-progress
sendPacket(Tag::FRAME, payload, 4);
}
currentTick++;
// Handle animation end (0 = run indefinitely for variable-only animations)
@ -127,6 +137,14 @@ void runNodeAnimation() {
switch (animState.playMode) {
case PLAY_ONCE:
animState.stop();
{
uint8_t done[4];
done[0] = currentTick & 0xFF;
done[1] = (currentTick >> 8) & 0xFF;
done[2] = static_cast<uint8_t>(animState.playMode);
done[3] = 1; // complete
sendPacket(Tag::FRAME, done, 4);
}
break;
case PLAY_LOOP:
// Continue looping
@ -134,6 +152,12 @@ void runNodeAnimation() {
case PLAY_REPEAT:
if (--animState.repeatsRemaining == 0) {
animState.stop();
uint8_t done[4];
done[0] = currentTick & 0xFF;
done[1] = (currentTick >> 8) & 0xFF;
done[2] = static_cast<uint8_t>(animState.playMode);
done[3] = 1; // complete
sendPacket(Tag::FRAME, done, 4);
}
break;
default:

View File

@ -43,6 +43,7 @@ namespace Tag {
// Sensors
constexpr char IMU[4] = {'I','M','U','0'}; // IMU data (heading, roll, pitch)
constexpr char RADAR[4] = {'R','D','A','R'}; // Radar targets
constexpr char FRAME[4] = {'F','R','M','E'}; // Animation frame events (frame, mode, status)
// System
constexpr char STATE[4] = {'S','T','A','T'}; // System state/heartbeat

View File

@ -178,8 +178,8 @@ bool IMU::update() {
}
uint16_t IMU::packPayload(uint8_t* buffer) const {
// Format: heading(2) + roll(2) + pitch(2) as int16 * 100
int16_t h = (int16_t)(heading * 100.0f);
// Format: heading(2, unsigned) + roll(2, signed) + pitch(2, signed), all *100
uint16_t h = (uint16_t)(heading * 100.0f); // 0..36000 fits in uint16
int16_t r = (int16_t)(roll * 100.0f);
int16_t p = (int16_t)(pitch * 100.0f);

View File

@ -106,10 +106,10 @@ public:
bool isRadarStreamEnabled() const { return radarStreamEnabled; }
private:
bool imuStreamEnabled = false;
bool radarStreamEnabled = false;
uint16_t imuInterval = 100;
uint16_t radarInterval = 100;
bool imuStreamEnabled = true;
bool radarStreamEnabled = true;
uint16_t imuInterval = 10;
uint16_t radarInterval = 10;
unsigned long lastIMUSend = 0;
unsigned long lastRadarSend = 0;