|
28 | 28 | #include <cstdio>
|
29 | 29 | #include <cstring>
|
30 | 30 | #include <cinttypes>
|
| 31 | +#include <cmath> |
31 | 32 |
|
32 | 33 | namespace mod {
|
33 | 34 |
|
@@ -3782,6 +3783,73 @@ bool getSequenceStageAndEvent(const char *arrayOut[2], uint32_t sequencePosition
|
3782 | 3783 | return true;
|
3783 | 3784 | }
|
3784 | 3785 |
|
| 3786 | +double getStickAngle(int32_t stickXYOut[2]) |
| 3787 | +{ |
| 3788 | + int32_t StickXInt = static_cast<int32_t>(ttyd::system::keyGetStickX(0)); |
| 3789 | + int32_t StickYInt = static_cast<int32_t>(ttyd::system::keyGetStickY(0)); |
| 3790 | + |
| 3791 | + // Check if the stick is at the neutral position |
| 3792 | + if ((StickXInt == 0) && (StickYInt == 0)) |
| 3793 | + { |
| 3794 | + // The stick is currently at the neutral position |
| 3795 | + if (stickXYOut) |
| 3796 | + { |
| 3797 | + stickXYOut[0] = 0; |
| 3798 | + stickXYOut[1] = 0; |
| 3799 | + } |
| 3800 | + return -1000; |
| 3801 | + } |
| 3802 | + |
| 3803 | + if (StickXInt > 127) |
| 3804 | + { |
| 3805 | + StickXInt -= 256; |
| 3806 | + } |
| 3807 | + |
| 3808 | + if (StickYInt > 127) |
| 3809 | + { |
| 3810 | + StickYInt -= 256; |
| 3811 | + } |
| 3812 | + |
| 3813 | + // Store the individual stick values if desired |
| 3814 | + if (stickXYOut) |
| 3815 | + { |
| 3816 | + stickXYOut[0] = StickXInt; |
| 3817 | + stickXYOut[1] = StickYInt; |
| 3818 | + } |
| 3819 | + |
| 3820 | + double StickX = static_cast<double>(StickXInt); |
| 3821 | + double StickY = static_cast<double>(StickYInt); |
| 3822 | + const double PI = 3.14159265358979323846; |
| 3823 | + |
| 3824 | + double StickAngle = (atan2(StickX, StickY)) * (180 / PI); |
| 3825 | + if (StickAngle < 0) |
| 3826 | + { |
| 3827 | + StickAngle += 360; |
| 3828 | + } |
| 3829 | + |
| 3830 | + return StickAngle; |
| 3831 | +} |
| 3832 | + |
| 3833 | +void getStickAngleString(char *stringOut) |
| 3834 | +{ |
| 3835 | + int32_t StickXYAngles[2]; |
| 3836 | + double StickAngle = getStickAngle(StickXYAngles); |
| 3837 | + |
| 3838 | + // Check if the stick is at the neutral position |
| 3839 | + if (StickAngle == -1000) |
| 3840 | + { |
| 3841 | + // The stick is currently at the neutral position |
| 3842 | + strcpy(stringOut, "Neutral"); |
| 3843 | + return; |
| 3844 | + } |
| 3845 | + |
| 3846 | + sprintf(stringOut, |
| 3847 | + "%.2f %" PRId32 " %" PRId32, |
| 3848 | + StickAngle, |
| 3849 | + StickXYAngles[0], |
| 3850 | + StickXYAngles[1]); |
| 3851 | +} |
| 3852 | + |
3785 | 3853 | /*void getButtonsPressedDynamic(uint8_t *buttonArrayOut, uint32_t currentButtonCombo)
|
3786 | 3854 | {
|
3787 | 3855 | uint32_t Counter = 0;
|
|
0 commit comments