Hi,
First of all, @stibbonsthanks very much for making this library, so far it's the only one I got it to work with the latest KSP & Win10.
"Work" might be an overstatement though, I'm trying to test a simple example where a couple of LEDs will light up when clicking on RCS or SAS on the navball, however I'm getting some strange behaviour:
Any of the LEDs will turn on on the first click, however they won't turn off if you click them again, however if you click both (both LEDs on) then you can click again either and switch them off (but only one of them, not both!)
Unfortunately I don't have a second Arduino to try and debug this, here's the code if you'd be kind to have a look:
#include "KerbalSimpit.h"
#include <KerbalSimpitMessageTypes.h>
#include <PayloadStructs.h>
const int SAS_LED = 11;
const int RCS_LED = 12;
KerbalSimpit mySimpit(Serial);
void setup() {
Serial.begin(115200);
// Set initial pin states, and turn on the LED
pinMode(SAS_LED, OUTPUT);
pinMode(RCS_LED, OUTPUT);
digitalWrite(SAS_LED, HIGH);
digitalWrite(RCS_LED, HIGH);
// This loop continually attempts to handshake with the plugin.
// It will keep retrying until it gets a successful handshake.
while (!mySimpit.init()) {
delay(100);
}
digitalWrite(SAS_LED, LOW);
digitalWrite(RCS_LED, LOW);
mySimpit.inboundHandler(messageHandler); // declares the message handler to read incoming messages from Simpit mod
mySimpit.registerChannel(ACTIONSTATUS_MESSAGE); // subscribes to the Action Status message channel
mySimpit.registerChannel(SCENE_CHANGE_MESSAGE); // subscribes to the Scene Change message channel
}
void messageHandler(byte messageType, byte msg[], byte msgSize) { // sets up the message handler to receive messages from Simpit
switch(messageType) {
case ACTIONSTATUS_MESSAGE: // defines the set of actions for messages coming from ACTIONSTATUS_MESSAGE
byte actions = msg[0]; // assigns the ACTIONSTATUS_MESSAGE to the variable actions
if (actions & SAS_ACTION) { // checks to see if SAS is turned on
digitalWrite(SAS_LED, HIGH); // turns on the SAS LED indicator if SAS is on
} else {
digitalWrite(SAS_LED, LOW); // set SAS LED indicator off if SAS is off
}
if (actions & GEAR_ACTION) { // checks to see if Gear is down
digitalWrite(GEAR_LED, HIGH); // turns on Gear LED indicator if gear is down
} else {
digitalWrite(GEAR_LED, LOW); // set the Gear indicator off if gear is up
}
if (actions & LIGHT_ACTION) { // checks to see if Lights are on
digitalWrite(LIGHTS_LED, HIGH); // turns on Lights LED indicator if lights are on
} else {
digitalWrite(LIGHTS_LED, LOW); // set Lights indicator off if lights are off
}
if (actions & RCS_ACTION) { // checks to see if RCS is active
digitalWrite(RCS_LED, HIGH); // turns on the RCS LED indicator if RCS is active
} else {
digitalWrite(RCS_LED, LOW); // set RCS indicator off if RCS is inactive
}
if (actions & BRAKES_ACTION) { // checks to see if Brakes are on
digitalWrite(BRAKES_LED, HIGH); // turns on Brakes LED indicator if brakes are on
} else {
digitalWrite(BRAKES_LED, LOW); // set Brakes indicator off if brakes are off
}
break;
}
}
void loop() {
mySimpit.update(); // necessary updates and loops for called functions
}
I'm using an Arduino UNO (clone CH340), KerbalSimpit v1.4.1.66 and KSP 1.11.1.03066.
Thanks in advance!