Jump to content

Mofates

Members
  • Posts

    4
  • Joined

  • Last visited

Reputation

0 Neutral
  1. @LRTNZyes, of course it should have been an unsigned long! I have no idea what part of my brain saw a squirrel while I was writing that. : )
  2. I sorted out my comm issues between KSP and my controller. I threw together a basic sketch that 'tries' to do what you were attempting. It will blink the builtinLED when the fuel level is below 10.0. PLEASE make sure that you have the correct COM port assigned in the settings.cfg file in the plugindata directory D:\SteamLibrary\SteamApps\common\Kerbal Space Program\GameData\KerbalSimpit\PluginData #include <KerbalSimpitMessageTypes.h> #include <PayloadStructs.h> #include <KerbalSimpit.h> KerbalSimpit mySimpit(Serial); float fuel = 10.0; unsigned int lastBlink = 0; int blinkPeriod = 500; bool blinkBool = false; void setup() { // put your setup code here, to run once: Serial.begin(115200); pinMode(LED_BUILTIN,OUTPUT); digitalWrite(LED_BUILTIN,LOW); //TURN THE LED OFF UNTIL WE CONNECT WITH KSP delay(100); while(!mySimpit.init()); { delay(100); } digitalWrite(LED_BUILTIN,HIGH); // SHOWS WERE CONNECTED! delay(500); mySimpit.inboundHandler(messageHandler); mySimpit.registerChannel(10); // 10 is the value for LF -- Outputs a resourceMessage } void loop() { // put your main code here, to run repeatedly: mySimpit.update(); checkFuelLevel(); } void messageHandler(byte messageType, byte msg[], byte msgSize) { if (msgSize == sizeof(resourceMessage)) { resourceMessage myLF; myLF = parseResource(msg); //float percentLF = myLF.available / myLF.total; fuel = myLF.available; } } void checkFuelLevel(){ unsigned int nowCheck = millis(); if( fuel < 10.0 ){ // CHECK FOR FUEL LOW if( nowCheck > ( lastBlink + blinkPeriod ) ){ lastBlink = nowCheck; digitalWrite(LED_BUILTIN, blinkBool); blinkBool = !blinkBool; } }else{ digitalWrite(LED_BUILTIN,HIGH); } }
  3. I have recently only been able to achieve Controller to KSP communications. My controller works fine but I can no longer get data from the KSP Client. just a suggestion - loops and timing checks are much better than repeated hard coded delays.
  4. Wasabi, The Wheel_Message is used to control rovers or wheel motors (Think -- ground based vehicles). The Rotation_Message is for just that - rotational parameters (think space/airborne). myWheel.throttle = buttonCurrent[i]; myWheel.steer = buttonCurrent[j]; myWheel.mask = 3; mySimpit.send(WHEEL_MESSAGE, myWheel);
×
×
  • Create New...