From 0cce6075b930297b60738b4eedcc70aab1b012d1 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Thu, 14 Nov 2024 11:40:40 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=BC=20Only=20write=20angles=20once?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp32/include/spot.h | 2 +- esp32/lib/ESP32-sveltekit/MotionService.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/esp32/include/spot.h b/esp32/include/spot.h index 21287cd..4dc3fee 100644 --- a/esp32/include/spot.h +++ b/esp32/include/spot.h @@ -68,7 +68,7 @@ class Spot { // communicate void emitTelemetry() { - if (updatedMotion) EXECUTE_EVERY_N_MS(100, { _motionService.syncAngles(); }); + if (updatedMotion) EXECUTE_EVERY_N_MS(100, { _motionService.emitAngles(); }); // _peripherals.loop(); EXECUTE_EVERY_N_MS(1000, { _peripherals.emitIMU(); }); // _peripherals.emitSonar(); diff --git a/esp32/lib/ESP32-sveltekit/MotionService.h b/esp32/lib/ESP32-sveltekit/MotionService.h index 20bdff8..3183360 100644 --- a/esp32/lib/ESP32-sveltekit/MotionService.h +++ b/esp32/lib/ESP32-sveltekit/MotionService.h @@ -90,12 +90,16 @@ class MotionService { socket.emit(MODE_EVENT, output, String(originId).c_str()); } - void syncAngles(const String &originId = "", bool sync = false) { + void emitAngles(const String &originId = "", bool sync = false) { char output[100]; snprintf(output, sizeof(output), "[%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f]", angles[0], angles[1], angles[2], angles[3], angles[4], angles[5], angles[6], angles[7], angles[8], angles[9], angles[10], angles[11]); socket.emit(ANGLES_EVENT, output, originId.c_str()); + } + + void syncAngles(const String &originId = "", bool sync = false) { + emitAngles(originId, sync); _servoController->setAngles(angles); }