public static void RemoveServo(IServo servo) { if (!Instance) { return; } if (Instance.ServoGroups == null) { return; } int num = 0; foreach (ControlGroup group in Instance.ServoGroups) { if (group.Name == servo.Group.Name) { group.RemoveControl(servo); } num += group.Servos.Count; } if (Gui.WindowManager.Instance) { //disable GUI when last servo removed Gui.WindowManager.Instance.GUIEnabled &= num > 0; } Logger.Log("[ServoController] AddServo finished successfully", Logger.Level.Debug); }
public static void RemoveServo(IServo servo) { if (!Instance) return; if (Instance.ServoGroups == null) return; int num = 0; foreach (ControlGroup group in Instance.ServoGroups) { if (group.Name == servo.Group.Name) { group.RemoveControl(servo); } num += group.Servos.Count; } if (Gui.ControlsGUI.IRGUI) { //disable GUI when last servo removed Gui.ControlsGUI.IRGUI.enabled = num > 0; } Logger.Log("[ServoController] AddServo finished successfully", Logger.Level.Debug); }
public ServoPreset(IServo servo) { this.servo = servo; this.presets = new List <float> { -20f, 0f, 20f, 120f }; }
public void AddControl(IServo control) { servos.Add(control); control.Group.Name = Name; control.Input.Forward = ForwardKey; control.Input.Reverse = ReverseKey; stale = true; }
public ControlGroup(IServo servo) : this() { Name = servo.Group.Name; ForwardKey = servo.Input.Forward; ReverseKey = servo.Input.Reverse; Speed = servo.RawServo.customSpeed.ToString("g"); servos.Add(servo); }
public void Update() { if (!HighLogic.LoadedSceneIsEditor) { return; } if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftControl)) //Returns true during the frame the user pressed the given mouse button. //It will not return true until the user has released the mouse button and pressed it again. { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { GameObject hitObject = hit.transform.gameObject; if (hitObject == null) { return; } Part part = hitObject.GetComponentInParent <Part>(); if (part == null) { return; } var servos = part.ToServos(); if (servos.Count > 0) { currentGrabbedServo = servos[0]; isGrabbing = true; startingMousePos = Input.mousePosition; startingServoPos = currentGrabbedServo.Mechanism.Position; } } } if (Input.GetMouseButtonUp(0)) //Returns true during the frame the user releases the given mouse button. { currentGrabbedServo = null; isGrabbing = false; } if (isGrabbing || currentGrabbedServo != null) { var deltaPos = (Input.mousePosition.y - startingMousePos.y) / (Screen.height * 0.25f); var newPos = startingServoPos - deltaPos * (currentGrabbedServo.Mechanism.MaxPositionLimit - currentGrabbedServo.Mechanism.MinPositionLimit); newPos = Mathf.Clamp(newPos, currentGrabbedServo.Mechanism.MinPositionLimit, currentGrabbedServo.Mechanism.MaxPositionLimit); currentGrabbedServo.Motor.MoveTo(newPos); } }
public static void AddServo(IServo servo) { if (!Instance) { return; } if (Instance.ServoGroups == null) { Instance.ServoGroups = new List <ControlGroup>(); } if (Gui.ControlsGUI.IRGUI) { Gui.ControlsGUI.IRGUI.enabled = true; } ControlGroup controlGroup = null; if (!string.IsNullOrEmpty(servo.Group.Name)) { foreach (ControlGroup cg in Instance.ServoGroups) { if (servo.Group.Name == cg.Name) { controlGroup = cg; break; } } if (controlGroup == null) { var newGroup = new ControlGroup(servo); Instance.ServoGroups.Add(newGroup); Logger.Log("[ServoController] AddServo adding new ControlGroup", Logger.Level.Debug); return; } } if (controlGroup == null) { if (Instance.ServoGroups.Count < 1) { Instance.ServoGroups.Add(new ControlGroup()); } controlGroup = Instance.ServoGroups[Instance.ServoGroups.Count - 1]; } controlGroup.AddControl(servo); Logger.Log("[ServoController] AddServo finished successfully", Logger.Level.Debug); }
public static void Main() { //_servo = new Servo(N.PWMChannels.PWM_PIN_D9, NamedServoConfigs.HiTecStandard); //_servo = new Servo(N.PWMChannels.PWM_PIN_D9, NamedServoConfigs.JXHV180); _servo = new Servo(N.PWMChannels.PWM_PIN_D9, NamedServoConfigs.BlueBirdBMS120); _button = new PushButton((H.Cpu.Pin) 0x15, CircuitTerminationType.Floating); _button.Clicked += (object sender, Microsoft.SPOT.EventArgs e) => { Debug.Print("Button Clicked"); ToggleServo(); }; Thread.Sleep(Timeout.Infinite); }
public static void AddServo(IServo servo) { if (!Instance) return; if (Instance.ServoGroups == null) Instance.ServoGroups = new List<ControlGroup>(); if (Gui.ControlsGUI.IRGUI) { Gui.ControlsGUI.IRGUI.enabled = true; } ControlGroup controlGroup = null; if (!string.IsNullOrEmpty(servo.Group.Name)) { foreach (ControlGroup cg in Instance.ServoGroups) { if (servo.Group.Name == cg.Name) { controlGroup = cg; break; } } if (controlGroup == null) { var newGroup = new ControlGroup(servo); Instance.ServoGroups.Add(newGroup); Logger.Log("[ServoController] AddServo adding new ControlGroup", Logger.Level.Debug); return; } } if (controlGroup == null) { if (Instance.ServoGroups.Count < 1) { Instance.ServoGroups.Add(new ControlGroup()); } controlGroup = Instance.ServoGroups[Instance.ServoGroups.Count - 1]; } controlGroup.AddControl(servo); Logger.Log("[ServoController] AddServo finished successfully", Logger.Level.Debug); }
private async Task Initialize() { _isActive = true; _manager = await PinManager.CreateAsync(); _ledPin1 = _manager.CreatePin <IGpioOutputPin>(5); _ledPin2 = _manager.CreatePin <IGpioOutputPin>(25); _ledPin3 = _manager.CreatePin <IGpioOutputPin>(12); _button = new SwitchButton(_manager.CreatePin <IGpioInputPin>(26, DriveMode.InputPullUp)); _button.ActiveAction = () => { _isActive = !_isActive; }; _display = new SingleDigitDisplayDevice(_manager.CreatePin <IGpioOutputPin>(17), _manager.CreatePin <IGpioOutputPin>(18), _manager.CreatePin <IGpioOutputPin>(27)); _servo = new Servo(_manager.CreatePin <IPwmPin>(13)); _servo.DesiredAngle = 0; await _manager.InitializeAsync(); }
public void ToggleServoRange(IServo s) { if (lines == null || lines.Count == 0) { return; } LinePrimitive aid; if (lines.TryGetValue(s, out aid)) { //aid.enabled = !aid.enabled; lines.Remove(s); aid.gameObject.DestroyGameObjectImmediate(); } else { //Draw the lines DrawServoRange(s); } }
public void DrawServoRange(IServo s) { if (lines.ContainsKey(s)) { UpdateServoRange(s); lines [s].enabled = true; return; } if (s.RawServo.rotateJoint) { var obj = new GameObject("Servo IRBuildAid object"); //obj.layer = s.RawServo.gameObject.layer; obj.layer = 1; obj.transform.position = s.RawServo.FixedMeshTransform.position; obj.transform.parent = s.RawServo.FixedMeshTransform; obj.transform.rotation = Quaternion.LookRotation(s.RawServo.FixedMeshTransform.TransformDirection(-s.RawServo.rotateAxis), s.RawServo.FixedMeshTransform.TransformDirection(s.RawServo.zeroUp)); var aid = obj.AddComponent <CircularInterval> (); //CircularInterval uses Local Space aid.transform.parent = obj.transform; aid.transform.rotation = obj.transform.rotation; aid.width = 0.05f; aid.UpdateColor(mainLineColor1); if (s.Motor.IsAxisInverted) { aid.SetMainLineColors(mainLineColor2, mainLineColor1); } else { aid.SetMainLineColors(mainLineColor1, mainLineColor2); } aid.UpdateWidth(0.05f); aid.arcAngle = (s.Mechanism.MaxPositionLimit - s.Mechanism.MinPositionLimit); aid.offsetAngle = s.Mechanism.MinPositionLimit; aid.currentPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.Position); aid.defaultPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.DefaultPosition); aid.presetPositionsColor = presetPositionsColor; if (s.RawServo.PresetPositions != null) { aid.SetPresetPositions(s.RawServo.PresetPositions); } aid.currentPositionColor = s.RawServo.isMotionLock ? currentPositionLockedColor : currentPositionColor; aid.endPoint1Color = endPoint1Color; aid.endPoint2Color = endPoint2Color; aid.enabled = true; lines.Add(s, aid); } else { var obj = new GameObject("Servo IRBuildAid object"); //obj.layer = s.RawServo.gameObject.layer; obj.layer = 1; obj.transform.position = s.RawServo.FixedMeshTransform.position; obj.transform.parent = s.RawServo.FixedMeshTransform; obj.transform.rotation = Quaternion.LookRotation(s.RawServo.FixedMeshTransform.TransformDirection(-s.RawServo.translateAxis), s.RawServo.FixedMeshTransform.TransformDirection(s.RawServo.zeroUp)); var aid = obj.AddComponent <BasicInterval> (); //BasicInterval uses worldSpace aid.transform.parent = obj.transform; aid.transform.rotation = obj.transform.rotation; aid.transform.position = obj.transform.position + obj.transform.right * 0.5f; aid.width = 0.05f; aid.length = (s.Mechanism.MaxPositionLimit - s.Mechanism.MinPositionLimit); aid.lineVector = aid.transform.forward * aid.length; aid.offset = s.Mechanism.MinPositionLimit; aid.currentPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.Position); aid.defaultPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.DefaultPosition); aid.UpdateColor(mainLineColor1); if (s.Motor.IsAxisInverted) { aid.SetMainLineColors(mainLineColor2, mainLineColor1); } else { aid.SetMainLineColors(mainLineColor1, mainLineColor2); } aid.UpdateWidth(0.05f); aid.presetPositionsColor = presetPositionsColor; if (s.RawServo.PresetPositions != null) { aid.SetPresetPositions(s.RawServo.PresetPositions); } aid.currentPositionColor = s.RawServo.isMotionLock ? currentPositionLockedColor : currentPositionColor; aid.endPoint1Color = endPoint1Color; aid.endPoint2Color = endPoint2Color; lines.Add(s, aid); } }
public void Init(bool motionLock, IServo servo, Interpolator interpolator) { IsMotionLock = motionLock; this.servo = servo; this.interpolator = interpolator; }
private void DrawServoPosition(IServo servo, GUILayoutOption rowHeight) { var customStyle = new GUIStyle(GUI.skin.textField) { normal = { textColor = servo.Mechanism.IsAxisInverted ? Color.yellow : Color.white }, alignment = TextAnchor.MiddleCenter, fontStyle = servo.Mechanism.IsAxisInverted ? FontStyle.Italic : FontStyle.Normal }; var posFormat = Math.Abs(servo.Mechanism.MaxPosition - servo.Mechanism.MinPosition) > 10 ? "{0:#0.0#}" : "{0:#0.0##}"; string focusedControlName = GUI.GetNameOfFocusedControl (); string thisControlName = "Position " + servo.UID; string tmp = DrawTextField (thisControlName, servo.Mechanism.Position, posFormat, customStyle, GUILayout.Width (40), rowHeight); var valueChanged = (thisControlName == focusedControlName && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)); float tmpValue; if (float.TryParse (tmp, out tmpValue) && valueChanged) { //focus changers are handled elsewhere tmpValue = Mathf.Clamp(tmpValue, servo.Mechanism.MinPositionLimit, servo.Mechanism.MaxPositionLimit); if (Math.Abs(servo.Mechanism.Position - tmpValue) > 0.005) servo.Mechanism.MoveTo(tmpValue); lastFocusedTextFieldValue = ""; } }
private void DrawPresetSelector(IServo servo, GUILayoutOption rowHeight) { int floor, ceiling; servo.Preset.GetNearestPresets(out floor, out ceiling); if (GUILayout.Button(new GUIContent(TextureLoader.PrevIcon, "Previous Preset" + ((floor >= 0) ? ": " + servo.Preset[floor] : "")), buttonStyle, GUILayout.Width(18), rowHeight)) { servo.Preset.MovePrev(); } SetTooltipText(); DrawServoPosition(servo, rowHeight); if (GUILayout.Button(new GUIContent(TextureLoader.NextIcon, "Next Preset" + ((ceiling >= 0) ? ": " + servo.Preset[ceiling] : "")), buttonStyle, GUILayout.Width(18), rowHeight)) { servo.Preset.MoveNext(); } SetTooltipText(); }
private void DrawEditPresetButton(IServo servo, GUIStyle presetButtonStyle, GUILayoutOption rowHeight) { bool servoPresetsOpen = guiPresetsEnabled && (Equals(servo, associatedServo)); bool toggleVal = GUILayout.Toggle(servoPresetsOpen, new GUIContent(TextureLoader.PresetsIcon, "Edit Presets"), presetButtonStyle, GUILayout.Width(22), rowHeight); if (servoPresetsOpen != toggleVal) { if (guiPresetsEnabled && Equals(associatedServo, servo)) guiPresetsEnabled = !guiPresetsEnabled; else { associatedServo = servo; if (!guiPresetsEnabled) guiPresetsEnabled = true; } } SetTooltipText(); }
public ServoPreset(ModuleIRServo rawServo, IServo servo) { this.rawServo = rawServo; this.servo = servo; }
public void RemoveControl(IServo control) { servos.Remove(control); stale = true; }
public ServoPreset(MuMechToggle rawServo, IServo servo) { this.rawServo = rawServo; this.servo = servo; }
public static void MoveServo(ControlGroup from, ControlGroup to, IServo servo) { to.AddControl(servo); from.RemoveControl(servo); }
public ControlGroup(IServo servo, Vessel v) : this(servo) { vessel = v; }
public DrawingMechanism(IServo leftServo, IServo rightServo) { this.leftServo = leftServo; this.rightServo = rightServo; }
public void UpdateServoRange(IServo s) { if (!lines.ContainsKey(s)) { return; } if (s.RawServo.rotateJoint) { var currentRange = (CircularInterval)lines [s]; currentRange.arcAngle = (s.Mechanism.MaxPositionLimit - s.Mechanism.MinPositionLimit); currentRange.offsetAngle = s.Mechanism.MinPositionLimit; currentRange.currentPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.Position); currentRange.defaultPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.DefaultPosition); if (s.RawServo.PresetPositions != null) { currentRange.SetPresetPositions(s.RawServo.PresetPositions); } if (s.Motor.IsAxisInverted) { currentRange.SetMainLineColors(mainLineColor2, mainLineColor1); } else { currentRange.SetMainLineColors(mainLineColor1, mainLineColor2); } currentRange.currentPositionColor = s.RawServo.isMotionLock ? currentPositionLockedColor : currentPositionColor; currentRange.endPoint1Color = endPoint1Color; currentRange.endPoint2Color = endPoint2Color; } else { var currentRange = (BasicInterval)lines [s]; currentRange.length = (s.Mechanism.MaxPositionLimit - s.Mechanism.MinPositionLimit); currentRange.lineVector = currentRange.transform.forward * currentRange.length; currentRange.offset = s.Mechanism.MinPositionLimit; currentRange.currentPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.Position); currentRange.defaultPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.DefaultPosition); if (s.RawServo.PresetPositions != null) { currentRange.SetPresetPositions(s.RawServo.PresetPositions); } if (s.Motor.IsAxisInverted) { currentRange.SetMainLineColors(mainLineColor2, mainLineColor1); } else { currentRange.SetMainLineColors(mainLineColor1, mainLineColor2); } currentRange.currentPositionColor = s.RawServo.isMotionLock ? currentPositionLockedColor : currentPositionColor; currentRange.endPoint1Color = endPoint1Color; currentRange.endPoint2Color = endPoint2Color; } }
internal static void WindowEnd() { if (Disabled) { return; //If the Drag and Drop is Disabled then just go back } // Draw the Yellow insertion strip Rect insertRect; if (DraggingItem && ServoDragging != null && ServoOver != null) { //What is the insert position of the dragged servo int insertIndex = ServoOver.ID + (ServoOverUpper ? 0 : 1); if ((ServoDragging.GroupID != ServoOver.GroupID) || (ServoDragging.ID != insertIndex && (ServoDragging.ID + 1) != insertIndex)) { //Only in here if the drop will cause the list to change float rectResMoveY; //is it dropping in the list or at the end if (insertIndex < Servos.Where(x => x.GroupID == ServoOver.GroupID).ToList().Count) { rectResMoveY = Servos.Where(x => x.GroupID == ServoOver.GroupID).ToList()[insertIndex].ServoRect.y; } else { rectResMoveY = Servos.Where(x => x.GroupID == ServoOver.GroupID).ToList().Last().ServoRect.y + Servos.Where(x => x.GroupID == ServoOver.GroupID) .ToList() .Last() .ServoRect.height; } //calculate and draw the graphic insertRect = new Rect(12, rectResMoveY + 26 - ScrollPosition.y, WindowRect.width - 34, 9); GUI.Box(insertRect, "", StyleDragInsert); } } else if (DraggingItem && GroupDragging != null && GroupOver != null) { //What is the insert position of the dragged group int insertIndex = GroupOver.ID + (GroupOverUpper ? 0 : 1); if (GroupDragging.ID != insertIndex && (GroupDragging.ID + 1) != insertIndex) { //Only in here if the drop will cause the list to change float rectResMoveY; //is it dropping in the list or at the end if (insertIndex < Groups.Count) { rectResMoveY = Groups[insertIndex].GroupRect.y; } else { rectResMoveY = Groups.Last().GroupRect.y + Groups.Last().GroupRect.height; } //calculate and draw the graphic insertRect = new Rect(12, rectResMoveY + 26 - ScrollPosition.y, WindowRect.width - 34, 9); GUI.Box(insertRect, "", StyleDragInsert); } } else if (DraggingItem && ServoDragging != null && GroupOver != null && Servos.All(x => x.GroupID != GroupOver.ID)) { //This is the case for an empty Group //is it dropping in the list or at the end float rectResMoveY = GroupOver.GroupRect.y + GroupOver.GroupRect.height; //calculate and draw the graphic insertRect = new Rect(12, rectResMoveY + 26 - ScrollPosition.y, WindowRect.width - 34, 9); GUI.Box(insertRect, "", StyleDragInsert); } //What is the mouse over if (MousePosition.y > 32 && MousePosition.y < WindowRect.height - 8) { //inside the scrollview //check what group GroupOver = Groups.FirstOrDefault(x => x.GroupRect.Contains(MousePosition + ScrollPosition - new Vector2(8, 29))); GroupIconOver = Groups.FirstOrDefault(x => x.IconRect.Contains(MousePosition + ScrollPosition - new Vector2(8, 29))); if (GroupOver != null) { GroupOverUpper = ((MousePosition + ScrollPosition - new Vector2(8, 29)).y - GroupOver.GroupRect.y) < GroupOver.GroupRect.height / 2; } //or servo ServoOver = Servos.FirstOrDefault(x => x.ServoRect.Contains(MousePosition + ScrollPosition - new Vector2(8, 29))); ServoIconOver = Servos.FirstOrDefault(x => x.IconRect.Contains(MousePosition + ScrollPosition - new Vector2(8, 29))); if (ServoOver != null) { ServoOverUpper = ((MousePosition + ScrollPosition - new Vector2(8, 29)).y - ServoOver.ServoRect.y) < ServoOver.ServoRect.height / 2; } } else { //Otherwise empty the variables GroupOver = null; ServoOver = null; GroupIconOver = null; ServoIconOver = null; } //MouseDown - left mouse button if (Event.current.type == EventType.mouseDown && Event.current.button == 0) { if (GroupIconOver != null) { //If we click on the drag icon then start the drag GroupDragging = GroupOver; DraggingItem = true; } else if (ServoIconOver != null) { //If we click on the drag icon then start the drag ServoDragging = ServoOver; DraggingItem = true; } } //did we release the mouse if (Event.current.type == EventType.mouseUp && Event.current.button == 0) { if (GroupDragging != null && GroupOver != null) { //were we dragging a group if (GroupDragging.ID != (GroupOver.ID + (GroupOverUpper ? 0 : 1))) { //And it will cause a reorder Logger.Log(string.Format("Reordering:{0}-{1}", GroupDragging.ID, (GroupOver.ID - (GroupOverUpper ? 1 : 0)))); //where are we inserting the dragged item int insertAt = (GroupOver.ID - (GroupOverUpper ? 1 : 0)); if (GroupOver.ID < GroupDragging.ID) { insertAt += 1; } //move em around ServoController.ControlGroup g = ServoController.Instance.ServoGroups[GroupDragging.ID]; ServoController.Instance.ServoGroups.RemoveAt(GroupDragging.ID); ServoController.Instance.ServoGroups.Insert(insertAt, g); } } else if (ServoDragging != null && ServoOver != null) { //were we dragging a servo //where are we inserting the dragged item int insertAt = (ServoOver.ID + (ServoOverUpper ? 0 : 1)); if (ServoOver.GroupID == ServoDragging.GroupID && ServoDragging.ID < ServoOver.ID) { insertAt -= 1; } Logger.Log(string.Format("Reordering:({0}-{1})->({2}-{3})", ServoDragging.GroupID, ServoDragging.ID, ServoOver.GroupID, insertAt)); //move em around IServo s = ServoController.Instance.ServoGroups[ServoDragging.GroupID].Servos[ServoDragging.ID]; ServoController.Instance.ServoGroups[ServoDragging.GroupID].Servos.RemoveAt(ServoDragging.ID); ServoController.Instance.ServoGroups[ServoOver.GroupID].Servos.Insert(insertAt, s); } else if (ServoDragging != null && GroupOver != null && Servos.All(x => x.GroupID != GroupOver.ID)) { //dragging a servo to an empty group const int INSERT_AT = 0; IServo s = ServoController.Instance.ServoGroups[ServoDragging.GroupID].Servos[ServoDragging.ID]; ServoController.Instance.ServoGroups[ServoDragging.GroupID].Servos.RemoveAt(ServoDragging.ID); ServoController.Instance.ServoGroups[GroupOver.ID].Servos.Insert(INSERT_AT, s); } //reset the dragging stuff DraggingItem = false; GroupDragging = null; ServoDragging = null; } //If we are dragging and in the bottom or top area then scrtoll the list if (DraggingItem && RectScrollBottom.Contains(MousePosition)) { ControlsGUI.SetEditorScrollYPosition(ScrollPosition.y + (Time.deltaTime * 40)); } if (DraggingItem && RectScrollTop.Contains(MousePosition)) { ControlsGUI.SetEditorScrollYPosition(ScrollPosition.y - (Time.deltaTime * 40)); } }
public bool Equals(IServo other) { var servo = other as IRServo; return(servo != null && Equals(servo)); }