예제 #1
0
    public void DrawPin(Pin pin, bool editorPin = false, int arduinoBoard = 0)
    {
        GUILayout.BeginHorizontal();

        // TODO : get les type de pin que 1 fois et pas faire tout le temps en refresh
        string[] boardPins = BoardsTypeList.Boards.GetBoardFromId(arduinoBoard).GetPins();
        pin.currentPin = EditorGUILayout.Popup(pin.currentPin, boardPins, "ToolbarDropDown", GUILayout.MaxWidth(40));

        //old version for arduino
        // pin.currentPin = EditorGUILayout.Popup(pin.currentPin, EditorPin.arduinoUnoPins, "ToolbarDropDown", GUILayout.MaxWidth(40));

        pin.pinMode = (PinMode)EditorGUILayout.EnumPopup(pin.pinMode, "ToolbarDropDown", GUILayout.MaxWidth(55));
        pin.CheckChanges();
        GUILayout.BeginHorizontal();

        EditorGUIUtility.fieldWidth -= 22;
        serializedObject.ApplyModifiedProperties();

        switch (pin.pinMode)
        {
        case PinMode.Output:
            if (GUILayout.Button("HIGH", "toolbarButton"))
            {
                pin.SendPinValue(255, "d");
            }
            if (GUILayout.Button("LOW", "toolbarButton"))
            {
                pin.SendPinValue(0, "d");
            }
            break;

        case PinMode.Input_pullup:
            if (GUILayout.Button("Read", "toolbarButton", GUILayout.MaxWidth(55)))
            {
                pin.SendRead(digital: "d");
            }
            GUILayout.Label(pin.lastReadValue.ToString(), "TE Toolbarbutton");
            UpdateReadPins(pin.arduinoName, pin.currentPin, pin.lastReadValue);
            break;

        case PinMode.PWM:
            GUILayout.BeginHorizontal("TE Toolbarbutton");
            pin.sendValue = EditorGUILayout.IntSlider(pin.sendValue, 0, 255);
            pin.SendPinValue(pin.sendValue, "a");
            GUILayout.EndHorizontal();
            break;

        case PinMode.Servo:
            GUILayout.BeginHorizontal("TE Toolbarbutton");
            pin.sendValue = EditorGUILayout.IntSlider(pin.sendValue, 0, 180);
            pin.SendPinValue(pin.sendValue, "a");
            GUILayout.EndHorizontal();
            break;

        case PinMode.Analog:
            if (GUILayout.Button("Read", "toolbarButton", GUILayout.MaxWidth(55)))
            {
                pin.SendRead(action: ParseReadData);
            }
            GUILayout.Label(pin.lastReadValue.ToString(), "TE Toolbarbutton");
            UpdateReadPins(pin.arduinoName, pin.currentPin, pin.lastReadValue);
            break;
        }
        EditorGUIUtility.fieldWidth += 22;

        if (editorPin)
        {
            if (GUILayout.Button("-", "toolbarButton", GUILayout.Width(22)))
            {
                UduinoManagerEditor.Instance.RemovePin(pin);
            }
        }
        GUILayout.EndHorizontal();

        GUILayout.EndHorizontal();
    }
예제 #2
0
    public void DrawPin(Pin pin, bool editorPin = false)
    {
        GUILayout.BeginHorizontal();
        pin.currentPin = EditorGUILayout.Popup(pin.currentPin, EditorPin.arduinoUnoPins, "ToolbarDropDown", GUILayout.MaxWidth(40));
        pin.pinMode    = (PinMode)EditorGUILayout.EnumPopup(pin.pinMode, "ToolbarDropDown", GUILayout.MaxWidth(55));
        pin.CheckChanges();
        GUILayout.BeginHorizontal();

        EditorGUIUtility.fieldWidth -= 22;
        serializedObject.ApplyModifiedProperties();

        switch (pin.pinMode)
        {
        case PinMode.Output:
            if (GUILayout.Button("HIGH", "toolbarButton"))
            {
                pin.SendPinValue(255, "d");
            }
            if (GUILayout.Button("LOW", "toolbarButton"))
            {
                pin.SendPinValue(0, "d");
            }
            break;

        case PinMode.Input_pullup:
            if (GUILayout.Button("Read", "toolbarButton", GUILayout.MaxWidth(55)))
            {
                pin.SendRead(digital: "d");
            }
            GUILayout.Label(pin.lastReadValue.ToString(), "TE Toolbarbutton");
            UpdateReadPins(pin.arduinoName, pin.currentPin, pin.lastReadValue);
            break;

        case PinMode.PWM:
            GUILayout.BeginHorizontal("TE Toolbarbutton");
            pin.sendValue = EditorGUILayout.IntSlider(pin.sendValue, 0, 255);
            pin.SendPinValue(pin.sendValue, "a");
            GUILayout.EndHorizontal();
            break;

        case PinMode.Servo:
            GUILayout.BeginHorizontal("TE Toolbarbutton");
            pin.sendValue = EditorGUILayout.IntSlider(pin.sendValue, 0, 180);
            pin.SendPinValue(pin.sendValue, "a");
            GUILayout.EndHorizontal();
            break;

        case PinMode.Analog:
            if (GUILayout.Button("Read", "toolbarButton", GUILayout.MaxWidth(55)))
            {
                pin.SendRead();
            }
            GUILayout.Label(pin.lastReadValue.ToString(), "TE Toolbarbutton");
            UpdateReadPins(pin.arduinoName, pin.currentPin, pin.lastReadValue);
            break;
        }
        EditorGUIUtility.fieldWidth += 22;

        if (editorPin)
        {
            if (GUILayout.Button("-", "toolbarButton", GUILayout.Width(22)))
            {
                //TODO : struff here
                UduinoManagerEditor.Instance.RemovePin(pin);
            }
        }
        GUILayout.EndHorizontal();

        GUILayout.EndHorizontal();
    }