Ejemplo n.º 1
0
        public static void updateUIWithDeserializedData(CrownRootObject crownRootObject)
        {
            //CrownRootObject crownRootObject = JsonConvert.DeserializeObject<CrownRootObject>(msg);
            UnityEngine.Debug.Log("Message received 2 : " + crownRootObject.message_type + "\n");
            if (crownRootObject.message_type == "deactivate_plugin")
            {
                return;
            }

            try
            {
                if (crownRootObject.message_type == "crown_turn_event")
                {
                    // received a crown turn event from Craft crown
                    multiplicator += 1.0f * crownRootObject.delta / 180;
                    if (multiplicator < 0)
                    {
                        multiplicator = 0;
                    }
                    if (multiplicator > 3)
                    {
                        multiplicator = 3;
                    }
                    UnityEngine.Debug.Log("Multiplicator is now at : " + multiplicator + "\n");
                }

                if (crownRootObject.message_type == "crown_press_event")
                {
                    // received a crown turn event from Craft crown
                    if (recording)
                    {
                        recording = false;
                    }
                    else
                    {
                        recording = true;
                    }
                }
            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }
        }
Ejemplo n.º 2
0
        private async Task Receive()
        {
            byte[] buffer = new byte[receiveChunkSize];
            while (this.client.State == WebSocketState.Open)
            {
                var result = await this.client.ReceiveAsync(new ArraySegment <byte>(buffer), CancellationToken.None);

                if (result.MessageType == WebSocketMessageType.Close)
                {
                    await this.client.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None);
                }
                else
                {
                    var             message         = Encoding.ASCII.GetString(buffer, 0, result.Count);
                    CrownRootObject crownRootObject = JsonConvert.DeserializeObject <CrownRootObject>(message);
                    this.OnNewMessage(crownRootObject);
                }
            }
        }
Ejemplo n.º 3
0
        public static void wrapperUpdateUI(string msg)
        {
            UnityEngine.Debug.Log("msg :" + msg + "\n");
            CrownRootObject crownRootObject = JsonConvert.DeserializeObject <CrownRootObject>(msg);

            UnityEngine.Debug.Log("Message received : " + crownRootObject.message_type + "\n");
            if ((crownRootObject.message_type == "crown_turn_event"))
            {
                crownObjectList.Add(crownRootObject);
                UnityEngine.Debug.Log("msg :" + msg + "\n");
            }
            else if (crownRootObject.message_type == "crown_press_event")
            {
                crownObjectList.Add(crownRootObject);
                UnityEngine.Debug.Log("msg :" + msg + "\n");
            }
            else if (crownRootObject.message_type == "register_ack")
            {
                // save the session id as this is used for any communication with Logi Options
                sessionId = crownRootObject.session_id;
                //toolChange("nothing");
                lastcontext = "";

                if (sendContextChange)
                {
                    sendContextChange = false;
                    MyWebSocket.toolChange("nothing");
                }
                else
                {
                    toolChange("nothing");
                }
            }
            else if (crownRootObject.message_type == "deactivate_plugin" || crownRootObject.message_type == "activate_plugin")
            {
                // our app has been activated or deactivated
            }
            else if (crownRootObject.message_type == "crown_touch_event")
            {
                // crown touch event
                UnityEngine.Debug.Log("crown touch event :" + msg + "\n");
            }
        }
Ejemplo n.º 4
0
        public static void updateUIWithDeserializedData(CrownRootObject crownRootObject)
        {
            //CrownRootObject crownRootObject = JsonConvert.DeserializeObject<CrownRootObject>(msg);

            int progressValue = 0;

            if (crownRootObject.message_type == "deactivate_plugin")
            {
                return;
            }

            try
            {
                if (crownRootObject.message_type == "crown_turn_event")
                {
                    // received a crown turn event from Craft crown
                    Trace.Write("++ crown ratchet delta :" + crownRootObject.ratchet_delta + " slot delta = " + crownRootObject.delta + "\n");

                    switch (crownRootObject.task_options.current_tool)
                    {
                    case "ProgressBar":
                        progressValue = m_form2.progressBar1.Value + crownRootObject.delta;

                        if (progressValue < 0)
                        {
                            progressValue = 0;
                        }

                        if (progressValue > 1000)
                        {
                            progressValue = 1000;
                        }

                        m_form2.progressBar1.Invoke(new Action(() => m_form2.progressBar1.Value = progressValue));
                        break;

                    case "NumericUpDown":
                        int numericValue = (int)m_form2.numericUpDown1.Value + crownRootObject.delta;

                        if (numericValue < 0)
                        {
                            numericValue = 0;
                        }

                        if (numericValue > 1000)
                        {
                            numericValue = 1000;
                        }

                        m_form2.numericUpDown1.Invoke(new Action(() => m_form2.numericUpDown1.Value = numericValue));
                        break;

                    case "ListBox":
                        int listIndex = 0;
                        m_form2.listBox1.Invoke(new Action(() => listIndex = m_form2.listBox1.SelectedIndex));
                        listIndex = listIndex + crownRootObject.ratchet_delta;

                        if (listIndex < 0)
                        {
                            listIndex = 0;
                        }

                        if (listIndex > 950)
                        {
                            listIndex = 950;
                        }
                        m_form2.listBox1.Invoke(new Action(() => m_form2.listBox1.SelectedIndex = listIndex));
                        break;

                    case "TextBox":
                        switch (crownRootObject.task_options.current_tool_option)
                        {
                        case "textBoxHeight":
                            int textbox_height = 0;
                            m_form2.textBox1.Invoke(new Action(() => textbox_height = m_form2.textBox1.Height));
                            textbox_height = textbox_height + crownRootObject.delta;

                            m_form2.textBox1.Invoke(new Action(() => m_form2.textBox1.Height = textbox_height));
                            break;

                        case "textBoxWidth":
                            int textbox_width = 0;
                            m_form2.textBox1.Invoke(new Action(() => textbox_width = m_form2.textBox1.Width));
                            textbox_width = textbox_width + crownRootObject.delta;

                            m_form2.textBox1.Invoke(new Action(() => m_form2.textBox1.Width = textbox_width));
                            break;

                        default:
                            break;
                        }
                        break;

                    case "ComboBox":
                        int comboIndex = 0;
                        m_form2.comboBox1.Invoke(new Action(() => comboIndex = m_form2.comboBox1.SelectedIndex));
                        comboIndex = comboIndex + crownRootObject.delta;

                        if (comboIndex < 0)
                        {
                            comboIndex = 0;
                        }

                        if (comboIndex > 950)
                        {
                            comboIndex = 950;
                        }
                        m_form2.listBox1.Invoke(new Action(() => m_form2.comboBox1.SelectedIndex = comboIndex));
                        break;

                    case "CheckedListBox":
                        int checkedListIndex = 0;
                        m_form2.checkedListBox1.Invoke(new Action(() => checkedListIndex = m_form2.checkedListBox1.SelectedIndex));
                        checkedListIndex = checkedListIndex + crownRootObject.delta;

                        if (checkedListIndex < 0)
                        {
                            checkedListIndex = 0;
                        }

                        if (checkedListIndex > 1000)
                        {
                            checkedListIndex = 1000;
                        }
                        m_form2.listBox1.Invoke(new Action(() => m_form2.checkedListBox1.SelectedIndex = checkedListIndex));
                        break;

                    case "TrackBar":
                        int trackIndex = 0;
                        m_form2.trackBar1.Invoke(new Action(() => trackIndex = m_form2.trackBar1.Value));
                        trackIndex = trackIndex + crownRootObject.delta;

                        if (trackIndex < 0)
                        {
                            trackIndex = 0;
                        }

                        if (trackIndex > 100)
                        {
                            trackIndex = 100;
                        }
                        m_form2.trackBar1.Invoke(new Action(() => m_form2.trackBar1.Value = trackIndex));
                        break;

                    case "TabControl":
                        int tabIndex = 0;
                        m_form2.tabControl1.Invoke(new Action(() => tabIndex = m_form2.tabControl1.SelectedIndex));
                        tabIndex = tabIndex + crownRootObject.ratchet_delta;

                        if (tabIndex < 0)
                        {
                            tabIndex = 0;
                        }

                        if (tabIndex > 10)
                        {
                            tabIndex = 10;
                        }
                        m_form2.tabControl1.Invoke(new Action(() => m_form2.tabControl1.SelectedIndex = tabIndex));
                        break;

                    case "RichTextBox":
                        float richTextIndex = 0;
                        m_form2.richTextBox1.Invoke(new Action(() => richTextIndex = m_form2.richTextBox1.Font.Size));
                        richTextIndex = richTextIndex + crownRootObject.delta;

                        if (richTextIndex < 5)
                        {
                            richTextIndex = 5;
                        }

                        if (richTextIndex > 100)
                        {
                            richTextIndex = 100;
                        }
                        m_form2.richTextBox1.Invoke(new Action(() => m_form2.richTextBox1.Font = new Font(m_form2.richTextBox1.Font.FontFamily, richTextIndex)));
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }
        }