[BUG]: CAG not behaving consistently when empty
Tested on latest version of Simpit, KSP1.12 w/ AGExt. Reported by @CodapopKSP
Using the logging, you can see the difference in behavior between AG1-10 and AG11+.
If you put a craft on the pad and a craft on the runway, both with nothing assigned to action groups, and then run that code and have it activate the CAG in the setup, then switch between the two, you'll see a few things:
- AG 1-10 cannot be activated using the arduino if they're empty, but they can be activated using the keyboard. But when switching to the other craft, they turn OFF appropriately, and when returning to the first craft, they turn back ON appropriately. The issue here is they can only be activated by the controller if they are populated.
- The bigger issue is that turning on AG 11+ on one craft and then switching to the other craft reveals them to still be turned on, but only if they're empty. If they're populated, then I believe they all function properly.
So all AGs function properly when populated on both crafts. AG 1-10 are unable to be activated by controller if unpopulated (maybe a feature more than a bug) AG 11+ can be activated but don't change state when switching craft if unpopulated AG 11+ also automatically turn off when exiting flight even if there is no scene change message.
Here is a script to reproduce it
#include "KerbalSimpit.h"
KerbalSimpit mySimpit(Serial);
unsigned long lastDebounceTime_w = 0;
bool Action_Dspl_b[10] = {};
bool Action2_Dspl_b[10] = {};
void setup() {
Serial.begin(115200);
while (!mySimpit.init()) {delay(100);}
mySimpit.printToKSP("Connected", PRINT_TO_SCREEN);
mySimpit.inboundHandler(messageHandler);
mySimpit.registerChannel(CAGSTATUS_MESSAGE);
delay(1000);
mySimpit.toggleCAG(2);
mySimpit.toggleCAG(3);
mySimpit.toggleCAG(12);
mySimpit.toggleCAG(13);
}
void loop() {
mySimpit.update();
if ((millis() - lastDebounceTime_w) > 1000) {
for (int i = 0; i < 4; i++) {
mySimpit.printToKSP("AG" + String(i) + ": " + String(Action_Dspl_b[i]), PRINT_TO_SCREEN);
//mySimpit.printToKSP("AG2" + String(i+10) + ": " + String(Action2_Dspl_b[i]), PRINT_TO_SCREEN);
}
lastDebounceTime_w = millis();
}
}
void messageHandler(byte messageType, byte msg[], byte msgSize) {
switch(messageType) {
case CAGSTATUS_MESSAGE:
if (msgSize == sizeof(cagStatusMessage)) {
cagStatusMessage myAG;
myAG = parseCAGStatusMessage(msg);
for (int i = 1; i < 11; i++) {
Action_Dspl_b[i] = (myAG.is_action_activated(i));
Action2_Dspl_b[i] = (myAG.is_action_activated(i+10));
}
}
break;
}
}
Additional information after some digging. As we use different logic if AGExt is installed of not, we need to consider both cases
If AGExt is not installed
We call directly KSP API. In this case the controller can change the CAG state even when the group is empty, as with the keyboard. Switching vessels seems to work properly (i.e. if you have an empty CAG, it can be switched on an it stays on when you switch to another vessel and you switch back).
So I think there is no issue if AGExt is not installed.
If AGExt is installed
For stock CAG (1-10)
In this case for consistency, we use AGext API for all CAG, the stock on (1-10) and the 11+. AGExt seems to disregard activating empty CAG. This means that the controller cannot activate any CAG (even the 1-10 that we can activate via keyboard, since we are using a different API).
There is also an issue (reported by CaptnUndrpnts) that in some case the toggling of actions is not working when the action group was not set at launch but is modified during flight. I had the same issue with an action group being populated via the stock GUI that was not reflected in the AGExt GUI. When the CAG is populated with the AGExt GUI, I did not find any issue. I believe AGExt is not keeping in sync the content of each CAG with the content of the stock CAG ...
For non stock CAG (11+)
Some different things happened, as mentioned by Coda above.
AGExt allow to activate empty CAG (tested with 11), and the value of the CAG is even shared between several vessels (behavior not consistent with stock CAG). 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.
If the CAG is populated on both craft, switching from one to the other works as expected.
Way forward
The strange behavior seems (to me) to come from AGExt and I'm not sure we can do anything about it on Simpit side, unfortunately ...
I suggest the following :
- State in the documentation that AGExt is supported, but with known issues. We recommend not to install it if not needed.
- Explain in the documentation the 2 known issues with AGExt
- When using empty CAG, the CAG state is not consistent, especially when switching vessels
- The CAG must be populated using AGExt GUI during flight, else it might not be taken into account
- Raise those issue in the AGExt repo, but as there is no active maintainer anymore, I believe this might not be acted upon ...