diff --git a/src/flight-controller/receiver.cpp b/src/flight-controller/receiver.cpp index 5d5e873..3d8ef36 100644 --- a/src/flight-controller/receiver.cpp +++ b/src/flight-controller/receiver.cpp @@ -44,3 +44,11 @@ void FlushRadioBuffer() { } bool IsDroneArmed() { return armed; } + +int GetDroneThrottle() { return throttle; } + +int GetDroneRoll() { return roll; } + +int GetDronePitch() { return pitch; } + +int GetDroneYaw() { return yaw; } diff --git a/src/flight-controller/receiver.h b/src/flight-controller/receiver.h index e69c41a..3c62e3a 100644 --- a/src/flight-controller/receiver.h +++ b/src/flight-controller/receiver.h @@ -1,4 +1,10 @@ #pragma once +// Reference variables: bool IsDroneArmed(); -void FlushRadioBuffer(); \ No newline at end of file +int GetDroneThrottle(); +int GetDroneRoll(); +int GetDronePitch(); +int GetDroneYaw(); + +void FlushRadioBuffer(); diff --git a/src/flight-controller/view.cpp b/src/flight-controller/view.cpp index ff02954..a732821 100644 --- a/src/flight-controller/view.cpp +++ b/src/flight-controller/view.cpp @@ -47,5 +47,8 @@ void UpdateView() { Image ledDisplay = Image(LED_DISPLAY_SIZE, LED_DISPLAY_SIZE); viewBatteryLevel(ledDisplay); DisplayArmed(IsDroneArmed(), ledDisplay); + DisplayThrottle(GetDroneThrottle(), ledDisplay); + DisplayPitchRoll(GetDroneRoll(), GetDronePitch(), ledDisplay); + DisplayYaw(GetDroneYaw(), ledDisplay); uBit.display.print(ledDisplay); } diff --git a/src/hand-controller/view.cpp b/src/hand-controller/view.cpp index d90cab2..2457bd8 100644 --- a/src/hand-controller/view.cpp +++ b/src/hand-controller/view.cpp @@ -8,40 +8,14 @@ // MicroBit display const uint16_t LED_DISPLAY_SIZE = 5; -const int LED_ON = 255; - -static void displayThrottle(Image &ledDisplay) { - int throttle = GetThrottle(); - if (throttle == 0) { - return; - } else { - int y = floor(4 - (throttle / 25)); - ledDisplay.setPixelValue(0, y, LED_ON); - } -} - -static uint16_t angleToDisplayCoord(int angle) { - return static_cast(std::round((angle + 45) / 22.5)); -} - -static void displayPitchRoll(Image &ledDisplay) { - uint16_t x = angleToDisplayCoord(GetRoll()); - uint16_t y = angleToDisplayCoord(GetPitch()); - ledDisplay.setPixelValue(x, y, LED_ON); -} - -static void displayYaw(Image &ledDisplay) { - uint16_t x = static_cast(GetYaw() / 30 + 2); - ledDisplay.setPixelValue(x, 0, LED_ON); -} void UpdateDisplay() { uBit.display.clear(); Image ledDisplay = Image(LED_DISPLAY_SIZE, LED_DISPLAY_SIZE); DisplayArmed(IsArmed(), ledDisplay); - displayThrottle(ledDisplay); - displayPitchRoll(ledDisplay); - displayYaw(ledDisplay); + DisplayThrottle(GetThrottle(), ledDisplay); + DisplayPitchRoll(GetRoll(), GetPitch(), ledDisplay); + DisplayYaw(GetYaw(), ledDisplay); uBit.display.print(ledDisplay); } diff --git a/src/utilites.cpp b/src/utilites.cpp index aaf9934..56c6fb2 100644 --- a/src/utilites.cpp +++ b/src/utilites.cpp @@ -3,6 +3,12 @@ static int pulseDirection = 15; static int armedPulse = 0; +static const int LED_ON = 255; + +static uint16_t angleToDisplayCoord(int angle) { + return static_cast(std::round((angle + 45) / 22.5)); +} + static void updatePulse() { armedPulse += pulseDirection; @@ -20,4 +26,24 @@ void DisplayArmed(bool isArmed, Image &ledDisplay) { } else { armedPulse = 0; } +} + +void DisplayThrottle(int throttle, Image &ledDisplay) { + if (throttle == 0) { + return; + } else { + int y = floor(4 - (throttle / 25)); + ledDisplay.setPixelValue(0, y, LED_ON); + } +} + +void DisplayPitchRoll(int roll, int pitch, Image &ledDisplay) { + uint16_t x = angleToDisplayCoord(roll); + uint16_t y = angleToDisplayCoord(pitch); + ledDisplay.setPixelValue(x, y, LED_ON); +} + +void DisplayYaw(int yaw, Image &ledDisplay) { + uint16_t x = static_cast(yaw / 30 + 2); + ledDisplay.setPixelValue(x, 0, LED_ON); } \ No newline at end of file diff --git a/src/utilities.h b/src/utilities.h index 6cf22f5..18d581e 100644 --- a/src/utilities.h +++ b/src/utilities.h @@ -1,4 +1,10 @@ #pragma once #include -void DisplayArmed(bool isArmed, Image &ledDisplay); \ No newline at end of file +void DisplayArmed(bool isArmed, Image &ledDisplay); + +void DisplayThrottle(int throttle, Image &ledDisplay); + +void DisplayPitchRoll(int roll, int pitch, Image &ledDisplay); + +void DisplayYaw(int yaw, Image &ledDisplay); \ No newline at end of file