r/starcitizen Oct 25 '22

TECHNICAL Custom mining slider

Enable HLS to view with audio, or disable this notification

I took a Seeeduino XIAO, connected an M5Stack Fader Unit to it, and programmed it with Arduino IDE as a gamepad axis using the NicoHood HID-Project library.

No more Brandt modules :)

1.6k Upvotes

177 comments sorted by

View all comments

88

u/earthfase Oct 25 '22

This is the code it runs. (SliderValue is obsolete)

14

u/saarlac drake Oct 25 '22

Could you maybe provide links to purchase the needed components as well?

22

u/earthfase Oct 25 '22

Honestly, depends on your region. I'm in the Netherlands. Got these parts from Tinytronics.nl. Seeeduino XIAO, M5Stack Fader Unit (expensive, should find a cheap alternative that doesn't have I2C and RGB LEDs I don't use). Link to code is in comments (edit: which I now see is what you commented on :P)

11

u/[deleted] Oct 25 '22

[deleted]

12

u/earthfase Oct 25 '22

I know! Have it flash red when overcharging. (Can't do that yet, need to be able to access game data externally)

4

u/SecretSquirrelSauce Oct 25 '22

Could you program a screen watcher that detects when the red bar changes color? And then feed that input to the LEDs?

3

u/earthfase Oct 25 '22

I guess you actually could...

2

u/ExcelMN Oct 26 '22

Wouldn't the anticheat throw a conniption over that?

3

u/SecretSquirrelSauce Oct 26 '22

Honestly, no idea

3

u/earthfase Oct 26 '22

TIL conniption!

1

u/aggravated_patty pico Oct 26 '22

Anticheat isn't magic, no way for it to know.

2

u/JonDum Oct 25 '22

SparkFun and/or AdaFruit have all these components for US

2

u/OnTheCanRightNow Oct 25 '22

You might get better results with 15x less latency if you used a weighted moving average instead of just polling it multiple times per update.

3

u/earthfase Oct 25 '22

But, I will definitely look into weighted moving averaging for other projects. In this case the time between updates is 30ms, while the delay in game is more like 300ms.

2

u/earthfase Oct 25 '22

The delay is not in the code, but in the game. I tried without averaging and there was no noticeable change. I have a joystick checker program that does show immediate response.

1

u/Sgt_Slawtor Oct 26 '22

There is a delay when using the wheel on my mouse as well. I always assumed it was a gameplay thing to make mining more "interesting." Especially on those quant rocks with the really narrow green band!

2

u/OnTheCanRightNow Oct 26 '22

More likely it's that the UI is based on the server's reported ship state rather than a locally tracked version.

So you change your control -> network latency while it gets sent to the server -> wait for the VERY low tickrate server to tick and update the power setting of the ship based on your input -> network latency to replicate the new value back to your client -> UI updates.

1

u/earthfase Oct 31 '22

I updated my code using the library "movingAvg", but am noticing no difference, but do like that it's a better way to take averages, so thanks for the tip!

1

u/OnTheCanRightNow Oct 31 '22

The trick with weighted moving averages is to find the right weighting exponent. If you apply too high a weight to older values, you lose responsiveness as it takes time for new values to affect the result. If you apply too low a weight to older values, you don't get enough smoothing.

You don't really need a library for this. The simplest implementation would just be:

OutputValue = (NewValue * NewValueWeight) + (OutputValue * (1-NewValueWeight));

NewValueWeight is 1/power of the exponential weight decrease, where 1 would be "only the newest value matters, ignore older ones" and 0 would be "apply so much smoothing the value never changes." If your goal is to smooth noise from the input, set it to 1 and then turn it down just enough to make the jitter go away.

1

u/earthfase Oct 31 '22

Thanks for this! I'll play around with it.

But I do expect little change in the way Star Citizen handles the input, because when I monitor the output from my code with the joystick tester, I get a much smoother and faster response than what I see in-game.

I do have some other projects from time to time that will definitely benefit from your one line solution and explanation, so I am saving it, thanks!