Skip to content

Commit 5b465bb

Browse files
author
Patrick Bechon
committed
Merge branch 'develop'
# Conflicts: # extras/docs/quickstart.rst
2 parents 4ada90e + 5d529f3 commit 5b465bb

File tree

12 files changed

+371
-89
lines changed

12 files changed

+371
-89
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* KerbalSimpitEchoNames
2+
A demonstration of reading the SOI name and the vessel name
3+
and echo it back to KSP for debug purpose.
4+
It could also be displayed to a screen if one is available
5+
(not included in this example)
6+
7+
*/
8+
9+
#include "KerbalSimpit.h"
10+
11+
12+
// Declare a KerbalSimpit object that will communicate using the "Serial" device.
13+
KerbalSimpit mySimpit(Serial);
14+
15+
void setup() {
16+
// Open the serial connection.
17+
Serial.begin(115200);
18+
19+
// Set up the build in LED, and turn it on.
20+
pinMode(LED_BUILTIN, OUTPUT);
21+
digitalWrite(LED_BUILTIN, HIGH);
22+
23+
// This loop continually attempts to handshake with the plugin.
24+
// It will keep retrying until it gets a successful handshake.
25+
while (!mySimpit.init()) {
26+
delay(100);
27+
}
28+
// Turn off the built-in LED to indicate handshaking is complete.
29+
digitalWrite(LED_BUILTIN, LOW);
30+
// Display a message in KSP to indicate handshaking is complete.
31+
mySimpit.printToKSP("Connected", PRINT_TO_SCREEN);
32+
// Sets our callback function. The KerbalSimpit library will
33+
// call this function every time a packet is received.
34+
mySimpit.inboundHandler(messageHandler);
35+
// Send a message to the plugin registering for the channels.
36+
mySimpit.registerChannel(SOI_MESSAGE);
37+
mySimpit.registerChannel(VESSEL_NAME_MESSAGE);
38+
}
39+
40+
void loop() {
41+
// Check for new serial messages.
42+
mySimpit.update();
43+
}
44+
45+
void messageHandler(byte messageType, byte msg[], byte msgSize) {
46+
switch(messageType) {
47+
case SOI_MESSAGE: {
48+
// Parse the SOI name
49+
String SOIName = (char *) msg;
50+
SOIName[msgSize] = '\0';
51+
52+
// Echo it to KSP
53+
mySimpit.printToKSP("I'm orbitting " + SOIName, PRINT_TO_SCREEN);
54+
}
55+
break;
56+
case VESSEL_NAME_MESSAGE: {
57+
// Parse the vessel name
58+
String vesselName = (char *) msg;
59+
vesselName[msgSize] = '\0';
60+
61+
// Echo it to KSP
62+
mySimpit.printToKSP("I'm " + vesselName, PRINT_TO_SCREEN);
63+
}
64+
break;
65+
}
66+
}

examples/KerbalSimpitHelloWorld/KerbalSimpitHelloWorld.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void messageHandler(byte messageType, byte msg[], byte msgSize) {
6969
// The message payload will be either "low" or "high".
7070
// We use the strcmp function to check what the string payload
7171
// is, and set the LED status accordingly.
72-
if (strcmp(msg, "low")) {
72+
if (strcmp((char*) msg, "low")) {
7373
digitalWrite(LED_BUILTIN, LOW);
7474
} else {
7575
digitalWrite(LED_BUILTIN, HIGH);
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* KerbalSimpitStressTest
2+
A demonstration of subscribing to all channel and check what is the impact
3+
of taking too long to call mysimpit.update.
4+
*/
5+
#include "KerbalSimpit.h"
6+
7+
// Declare a KerbalSimpit object that will
8+
// communicate using the "Serial" device.
9+
KerbalSimpit mySimpit(Serial);
10+
11+
// Store last time the log was sent to KSP
12+
unsigned long lastTimeLogging = 0;
13+
const long intervalLogging = 5000;
14+
15+
// Store number of messages received
16+
int msgNbr = 0;
17+
18+
void setup() {
19+
// Open the serial connection.
20+
Serial.begin(115200);
21+
22+
// Set up the build in LED, and turn it on.
23+
pinMode(LED_BUILTIN, OUTPUT);
24+
digitalWrite(LED_BUILTIN, HIGH);
25+
// This loop continually attempts to handshake with the plugin.
26+
// It will keep retrying until it gets a successful handshake.
27+
while (!mySimpit.init()) {
28+
delay(100);
29+
}
30+
// Turn off the built-in LED to indicate handshaking is complete.
31+
digitalWrite(LED_BUILTIN, LOW);
32+
// Display a message in KSP to indicate handshaking is complete.
33+
mySimpit.printToKSP("Connected", PRINT_TO_SCREEN);
34+
// Sets our callback function. The KerbalSimpit library will
35+
// call this function every time a packet is received.
36+
mySimpit.inboundHandler(messageHandler);
37+
38+
// Here you can register all the channels you want to use.
39+
// mySimpit.registerChannel(ALTITUDE_MESSAGE);
40+
// ...
41+
42+
// By default, register all available channels (even some non existant ones)
43+
for(byte b = 0; b <= 128; b++){
44+
mySimpit.registerChannel(b);
45+
}
46+
}
47+
48+
void loop() {
49+
// Check for new serial messages.
50+
mySimpit.update();
51+
52+
// Emulate a time consuming treatement. Increase/descrease this value to see the impact on the number of recevied/lost messages.
53+
delay(10);
54+
55+
unsigned long currentMillis = millis();
56+
if (currentMillis - lastTimeLogging >= intervalLogging) {
57+
lastTimeLogging = currentMillis;
58+
59+
mySimpit.printToKSP("Number of msg " + String(msgNbr));
60+
msgNbr = 0;
61+
62+
mySimpit.printToKSP("Number of lost msg " + String(mySimpit.packetDroppedNbr));
63+
mySimpit.packetDroppedNbr = 0;
64+
}
65+
}
66+
67+
void messageHandler(byte messageType, byte msg[], byte msgSize) {
68+
//Ignore all messages, just count them
69+
msgNbr ++;
70+
}

extras/docs/quickstart.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,10 @@ The examples_ directory of the library contains several example sketches
124124
that demonstrate the different functionality of the library.
125125

126126
.. _examples: https://github.com/Simpit-team/KerbalSimpitRevamped-Arduino/tree/main/examples
127+
128+
When you first install Simpit, you have to modify the *Settings.cfg* file that is found in the *GameData\KerbalSimpit* folder.
129+
You can copy the provided ``Settings.cfg.sample`` as a baseline, and you must at least define the port name to use. More information in :any:`troubleshooting`.
130+
131+
Simpit allows several controllers to be used at the same time. For this, you can define several *SerialPort* blocks in the *Settings.cfg* file. All controllers are managed independently.
132+
133+
Simpit also allows you to open/close a port while the game is running. This allows you to reprogram the Arduino while KSP is running (you have to close the port, upload the program, open the port again).

extras/docs/troubleshooting.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,34 @@ Here is an example.
8181
System.Threading.ThreadHelper.ThreadStart () (at <ad04dee02e7e4a85a1299c7ee81c79f6>:0)
8282
UnityEngine.UnhandledExceptionHandler:<RegisterUECatcher>m__0(Object, UnhandledExceptionEventArgs)
8383

84+
When I add more functionalities to my controller, it starts to behave strangely (messages lost, corrupted, etc.)
85+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8486

87+
It is probable that the Arduino serial buffer size is too small given the time between each call to ``simpit.update`` and the number of messages sent. You can test this by displaying ``mySimpit.packetDroppedNbr``. If it is non-zero, it means that some messages were corruped.
8588

89+
To fix it, you have several solutions :
90+
* Increase the serial buffer size in ``HardwareSerial.h``. To find the right file to modify, see here : https://forum.arduino.cc/t/solved-serial-buffer-size/581828/10. There should be a log line in KSP.log indicating the buffer size when an Arduino connect. The default is 64 bytes and the recommandation is at least 256.
91+
* Reduce the number of channels you subscribe to
92+
* Call ``simpit.update`` more frequently. For instance if you have a controller with several parts, you can call ``simpit.update`` between each part update instead of updating all the parts and only then call ``simpit.update``.
8693

94+
To test that this is not the root cause of your issue, you can use the KerbalSimpitStressTest example. Subscribe to all the channels you want to use, and test several values of delay to see if some messages are lost. Then try on you controller to measure what is the delay between two calls to ``simpit.update`` and compare the two values.
95+
96+
97+
I have some issues with custom action groups (CAG) when using Action Group Extended (AGExt)
98+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99+
100+
There is some know issues when using AGExt.
101+
102+
For stock CAG (below 10), AGExt seems to disregard activating empty CAG. This means that the controller cannot activate any CAG between 1-10 even when the those CAGs can be activated via keyboard since the game allow to activate empty CAG.
103+
104+
There is also an issue that in some cases the toggling of a CAG is not working when the CAG content was not set at launch but is modified during flight.
105+
The root cause might be the content of the stock CAG not being the same as the AGExt CAG with the same number.
106+
Simpit is only using the AGExt CAG, not the stock one, when AGExt is installed.
107+
In this case, you should check (and modify) CAG content using AGExt GUI only, not the stock one, to avoid this issue.
108+
109+
For non-stock CAG (11 and above), there seem to be an issue with empty CAGs.
110+
AGExt allow to activate empty CAG, and the value of the CAG seems to be shared between several vessels (behavior not consistent with stock CAG).
111+
Meaning that if craft A and B have an empty CAG 11, it can be toggled on any craft and when switching craft, the value is kept instead of being tied to the vessel.
112+
If the CAG is populated on both craft, switching from one to the other works as expected.
113+
114+
There is no known workaround currently, the issue seems to be in the way AGExt handle those edgecases. AGExt should not be installed when not needed.

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=KerbalSimpit
2-
version=2.1.0
2+
version=2.2.0
33
author=Rogor, LRTNZ <simpit.team@gmail.com>
44
maintainer=Rogor, LRTNZ <simpit.team@gmail.com>
55
sentence=A library for interfacing with the Kerbal Space Program video game.

src/Helpers.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ void KerbalSimpit::setCameraMode(byte mode)
4242
{
4343
_send(CAMERA_CONTROL_MODE, &mode, 1);
4444
}
45+
46+
void KerbalSimpit::cycleNavBallMode()
47+
{
48+
byte payload = 0;
49+
_send(NAVBALLMODE_MESSAGE, &payload, 1);
50+
}

0 commit comments

Comments
 (0)