コード例 #1
0
ファイル: Form1.cs プロジェクト: SnowCat6/GPIOReadGraph
        public void updateData(bool bUpdateDelay = false)
        {
            Dictionary <string, gpioPin> m;

            lock (m_GPIO_values)
            {
                m = new Dictionary <string, gpioPin>(m_GPIO_values);
            }

            if (m_GPIO_DataTable.Rows.Count < m.Count)
            {
                m_GPIO_DataTable.Rows.Add(m.Count - m_GPIO_DataTable.Rows.Count);
            }

            int rowIndex = 0;

            foreach (KeyValuePair <String, gpioPin> i in m)
            {
                gpioPin pin = i.Value;
                if (bUpdateDelay && pin.isChanged())
                {
                    lock (m_GPIO_values)
                    {
                        pin = m_GPIO_values[i.Key];
                        pin.tickChange();
                        m_GPIO_values[i.Key] = pin;
                    }
                    m_GPIO_DataTable.InvalidateRow(rowIndex);
                }
                ++rowIndex;
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: SnowCat6/GPIOReadGraph
        public void setRowPin(int rowIndex, gpioPin pin)
        {
            String pinKey;

            lock (m_GPIO_values)
            {
                pinKey = m_GPIO_values.Keys.ElementAt(rowIndex);
                m_GPIO_values[pinKey] = pin;
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: SnowCat6/GPIOReadGraph
        void cellMenu_ItemModeClicked(object sender, EventArgs e)
        {
            ToolStripItem    item = sender as ToolStripItem;
            ContextMenuStrip menu = item.GetCurrentParent() as ContextMenuStrip;

            int     nRowIndex = m_GPIO_DataTable.CurrentRow.Index;
            gpioPin pin       = getRowPin(nRowIndex);

            String[] mode = (string[])item.Tag;

            setPinValue(pin, pin.getPinIndex(mode[0]), int.Parse(mode[1]));
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: SnowCat6/GPIOReadGraph
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int rowIndex = e.RowIndex;

            if (rowIndex < 0)
            {
                return;
            }
            DataGridView view = (DataGridView)sender;

            gpioPin pin = getRowPin(rowIndex);

            pin.rowDisable = pin.rowDisable == false;
            setRowPin(rowIndex, pin);
            view.InvalidateRow(rowIndex);
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: SnowCat6/GPIOReadGraph
        public String makeGPIOstring()
        {
            Dictionary <string, gpioPin> pins;

            lock (m_GPIO_values)
            {
                pins = new Dictionary <string, gpioPin>(m_GPIO_values);
            }

            String clipState = String.Empty;

            clipState += "PIN ID\t";
            clipState += String.Join("\t", gpioPin.g_pins) + "\r\n";

            foreach (KeyValuePair <string, gpioPin> key in pins)
            {
                String  value = String.Empty;
                gpioPin pin   = key.Value;

                if (pin.rowDisable)
                {
                    value = "\tignore";
                }
                else
                {
                    for (int ix = 0; ix < gpioPin.g_pins.Length; ++ix)
                    {
                        string v = pin.pinToString(ix);
                        value += "\t";
                        if (ix > 0 || v.Length > 0)
                        {
                            value += v.Length > 0 ? v : "-";
                        }
                        else
                        {
                            value += pin.Value;
                        }
                    }
                }
                clipState += String.Format("GPIO{0}{1}\r\n", key.Key, value);
            }
            return(clipState);
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: SnowCat6/GPIOReadGraph
        private void dataGridView1_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
        {
            int          rowIndex  = e.RowIndex;
            int          cellIndex = e.ColumnIndex;
            DataGridView view      = (DataGridView)sender;

            if (rowIndex >= m_GPIO_values.Count)
            {
                e.Value = String.Empty;
                return;
            }

            gpioPin pin = getRowPin(rowIndex);

            String           cName = view.Columns[cellIndex].Name;
            DataGridViewCell cell  = view.Rows[rowIndex].Cells[cellIndex];

            String cellValue = pin.Value;

            switch (cName)
            {
            case "GPIO":
                cellValue = pin.pinID;
                break;

            case "Value":
                cellValue = pin.Value;
                break;

            default:
                cellValue = pin.pinToString(pin.getPinIndex(cName));
                break;
            }
            if (e.Value == null || e.Value.ToString() != cellValue)
            {
                e.Value = cellValue;
            }
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: SnowCat6/GPIOReadGraph
        void setPinValue(gpioPin pin, int nPin, int nValue)
        {
            StringBuilder value = new StringBuilder(pin.Value);

            if (nPin > 2)
            {
                --nPin;
            }
            value.Remove(2, 1);

            value[nPin] = nValue.ToString()[0];

            int nLen = value.Length;

            for (int ix = 0; ix < nLen - 1; ++ix)
            {
                value.Insert(ix * 2 + 1, ' ');
            }

            String cmd = String.Format(sellCmdSetPin, pin.pinID, value);

            if (false)
            {
                CShellConsolde shell = new CShellConsolde();
                shell.bShowlog = true;

                string[] cmds = new string[] { cmd, "exit" };
                shell.RunCommand(cmds, getAdbPath(), "shell su");
                //               shell.WaitForExit();
                shell.Close();
            }
            else
            {
                m_Command.RunCommand(new string [] { cmd });
            }
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: SnowCat6/GPIOReadGraph
        /// <summary>
        /// onConsoleChange
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void onConsoleChange(object sender, EventArgs e)
        {
            // this code will run on main (UI) thread
            DataReceivedEventArgs ev = (DataReceivedEventArgs)e;

            if (ev.Data == null)
            {
                return;
            }

            Match m;

            m = cmdparsePins.Match(ev.Data);
            if (m.Groups.Count > 1)
            {
                string          columns = m.Groups[1].Value;
                Regex           r       = new Regex("\\[([^\\]]+)\\]");
                MatchCollection coll    = r.Matches(columns);
                if (coll.Count == gpioPin.g_pins.Length)
                {
                    return;
                }

                List <string> colNames = new List <string>();
                foreach (Match m2 in coll)
                {
                    colNames.Add(m2.Groups[1].Value);
                }
                gpioPin.g_pins = colNames.ToArray <string>();
                Invoke((MethodInvoker) delegate { makeGridTable(); });
            }

            if (ev.Data == "nextLoop")
            {
                m_Command.RunCommand(new string[] { shellCmd });

                m_bUpdateTableAllow = true;
                currentResponceCounter++;

//                Invoke((MethodInvoker)delegate { updateData(false); });
                if (m_QueryDelay > 0)
                {
                    System.Threading.Thread.Sleep(m_QueryDelay);
                }
                return;
            }
            if (ev.Data.Length > 0)
            {
                currentCommandResponce = ev.Data;
            }

            m = cmdparse.Match(ev.Data);
            if (m.Groups.Count != 3)
            {
                return;
            }

            String pinID  = m.Groups[1].Value;
            String pinCFG = m.Groups[2].Value;

            lock (m_GPIO_values)
            {
                gpioPin pin;
                try
                {
                    pin = m_GPIO_values[pinID];
                    pin.setValue(pinCFG);
                }
                catch (Exception)
                {
                    pin = new gpioPin(pinCFG, pinID);
                }
                m_GPIO_values[pinID] = pin;
            }
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: SnowCat6/GPIOReadGraph
        /* table */

        private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            int rowIndex  = e.RowIndex;
            int cellIndex = e.ColumnIndex;

            if (rowIndex < 0 || cellIndex < 0)
            {
                return;
            }

            gpioPin pin = getRowPin(rowIndex);

            if (pin.rowDisable)
            {
                e.CellStyle.BackColor = Color.LightGray;
                return;
            }

            String cellValue = pin.Value;
            Color  bkColor   = Color.White;
            Color  textColor = Color.Black;

            DataGridView view  = (DataGridView)sender;
            String       cName = view.Columns[cellIndex].Name;

            //           DataGridViewCell cell = view.Rows[rowIndex].Cells[cellIndex];

            switch (cName)
            {
            case "GPIO":
                try
                {
                    bkColor = m_GPIO_color[pin.Value];
                }
                catch (Exception) { }
                break;

            case "Value":
                if (pin.isChanged())
                {
                    bkColor   = Color.Red;
                    textColor = Color.White;
                }
                break;

            default:
                if (pin.Value.Length != gpioPin.g_pins.Length)
                {
                    if (pin.isChanged())
                    {
                        bkColor   = Color.Red;
                        textColor = Color.White;
                    }
                    break;
                }
                int nPin = pin.getPinIndex(cName);
                if (nPin >= 0 && pin.IsChangedPin(nPin))
                {
                    bkColor   = Color.Red;
                    textColor = Color.White;
                }
                break;
            }

            e.CellStyle.BackColor = bkColor;
            e.CellStyle.ForeColor = textColor;
        }