Skip to content

Instantly share code, notes, and snippets.

@awstanley
Created January 4, 2015 23:57
Show Gist options
  • Save awstanley/33a4982e07110fbf866c to your computer and use it in GitHub Desktop.
Save awstanley/33a4982e07110fbf866c to your computer and use it in GitHub Desktop.
This is some old/test docking code which never got tested. There are potential limitations here, but the aim behind the system was to set flight mode on/off, so that the system could then trigger a "dock" command prior to connecting. The undock sequence would happen AFTER it had been released (connector goes off). Newer code is here: https://gis…
// OnOff code seems to be global...
ITerminalAction GetOnOffAction(IMyTerminalBlock block, bool enable)
{
ITerminalAction Action;
if (enable)
{
Action = block.GetActionWithName("Toggle block On");
}
else
{
Action = block.GetActionWithName("Toggle block Off");
}
return Action;
}
// Set all by type
void SetBlockStateByType<T>(bool enable)
{
var blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<T>(blocks);
if(blocks.Count > 0)
{
ITerminalAction Action = GetOnOffAction(blocks[0], enable);
foreach(IMyTerminalBlock target in blocks)
{
Action.Apply(target);
}
}
}
void SetFlightMode(bool enable)
{
SetBlockStateByType<IMyThrust>(enable);
SetBlockStateByType<IMyGyro>(enable);
// anything else you need on/off ...
}
// To dock:
// SetFlightMode(false);
// Our undock:
// SetFlightMode(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment