KerbalSimpit Class Documentation

class KerbalSimpit

The KerbalSimpit class manages a serial connection to KSP.

It automates the handshaking process, and provides utility functions to encapsulate most message types in and out of the game.

Public Functions

KerbalSimpit(Stream &serial)

Default constructor.

Parameters
  • serial: The serial instance this instance will use to communicate with the plugin. Usually “Serial”.

bool init()

Initialise the serial connection.

Performs handshaking with the plugin. Note that the KSPit library does not* call the begin() method on the serial object. You’ll need to ensure you’ve run Serial.begin(115200) (or similar) before calling this method.

void inboundHandler(void (*messageHandler)(byte messageType, byte msg[], byte msgSize))

Specify a callback function to handle messages received from the plugin.

See
messageHandler
Parameters
  • messageHandler: The callback function.

void registerChannel(byte channelID)

Subscribe to a channel of messages coming from the plugin.

This function sends a channel subscription message to the plugin, indicating that this device would like to receive messages send to a given channel.

Parameters
  • channelID: The ID of the channel to subscribe to.

void deregisterChannel(byte channelID)

Unsubscribe from a channel of messages coming from the plugin.

This function sends a channel subscription message to the plugin, indicating that no further messages for the given channel should be sent to this device.

Parameters
  • channelID: The ID of the channel to unsubscribe from.

template <typename T>
void send(byte messageType, T &msg)

Send a formatted KSPit packet.

Sends the given message as payload of a KSPit message.

Parameters
  • messageType: The ID of the message channel.
  • msg: Any object to be sent. The expected object depends on the message type. No type checking is done by this library.

void send(byte messageType, byte msg[], byte msgSize)

Send a formatted KSPit packet.

Sends the given message as payload of a KSPit message.

Parameters
  • messageType: The ID of the message channel.
  • msg: A byte array representing the message contents.
  • msgSize: The size of msg.

void update()

Regular library update function.

This function polls the serial device for new data, and performs other tasks that must be done regularly. The function should be called from an Arduino sketch loop() method.

void activateCAG(byte actiongroup)

Activate Custom Action Group.

Sends a message to activate the given Custom Action Group.

Parameters
  • actiongroup: The ID of the Custom Action Group to activate.

void deactivateCAG(byte actiongroup)

Deactivate Custom Action Group.

Sends a message to deactivate the given Custom Action Group.

Parameters
  • actiongroup: The ID of the Custom Action Group to deactivate.

void toggleCAG(byte actiongroup)

Toggle Custom Action Group.

Sends a message to toggle the state of the given Custom Action Group.

Parameters
  • actiongroup: The ID of the Custom Action Group to toggle.

void activateAction(byte action)

Activate Action Group.

Sends a message to activate the given standard Action Group(s).

Parameters
  • action: A bitfield representing one or more Action Groups to activate.

void deactivateAction(byte action)

Deactivate Action Group.

Sends a message to deactivate the given standard Action Group(s).

Parameters
  • action: A bitfield representing one or more Action Groups to deactivate.

void toggleAction(byte action)

Toggle Action Group.

Sends a message to toggle the state of the given standard Action Group(s).

Parameters
  • action: A bitfield representing one or more Action Groups to toggle.

void setSASMode(byte mode)

Set SAS mode Send a message to set the desired Autopilot (SAS) mode.

Parameters
  • mode: The mode to set. Possible modes are listed in the AutopilotMode enum.


This documentation was built using ArduinoDocs.