Ejemplo n.º 1
0
        public void RetrieveCommands(UserSettings.UNIT_TYPE Unit_Type, bool isInitialize)
        {
            using (SQLiteConnection connection = new SQLiteConnection(App.Database))
            {
                var commands = connection.Table <BluetoothCmd>();
                System.Diagnostics.Debug.WriteLine(commands.Count().ToString());

                if (!commands.Any())
                {
                    throw new Exception("Could not load command list");
                }

                foreach (var command in commands)
                {
                    Add(command);
                    InitCommandTypes();
                    System.Diagnostics.Debug.WriteLine("Id: " + command.Id + " isSelected:" + command.isSelected);
                }

                if (isInitialize)
                {
                    InitCommandBytes();
                    InitExpressions(Unit_Type);
                }
            }
        }
Ejemplo n.º 2
0
        // see if these methods are needed or not
        // MARKER 4

        public void InitExpressions(UserSettings.UNIT_TYPE Unit_Type)
        {
            StringBuilder sb = new StringBuilder();

            foreach (BluetoothCmd b in this) // Init expressions
            {
                b.InitExpression(b, Unit_Type, sb);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///  Initializes a given commands math expression based on supplied unit type
        /// </summary>
        /// <param name="bthcmd"></param>
        /// <param name="Unit_Type"></param>
        /// <param name="sb"></param>
        public void InitExpression(BluetoothCmd bthcmd, UserSettings.UNIT_TYPE Unit_Type, StringBuilder sb)
        {
            InitUnitType(bthcmd, Unit_Type);

            if (string.IsNullOrEmpty(sExpression))
            {
                return;
            }

            string varvalue;

            e         = null;
            arguments = null;

            e         = new Expression(sExpression.Trim());
            arguments = new List <Argument>();

            for (int idx = 0; idx < bthcmd.Command_Types.Length; idx++)
            {
                varvalue = ProcessValues.GetVariable(idx);
                arguments.Add(new Argument(varvalue));
                e.addArguments(arguments[idx]);
                //arguments[idx].setArgumentValue(0); // ToDo: initial value?
            }

            min      = bthcmd.Value_Min;
            max      = bthcmd.Value_Max;
            decimals = bthcmd.Decimals;

            if (decimals < 0)
            {
                decimals = 0;
            }
            else if (decimals > MAX_DECIMALS)
            {
                decimals = MAX_DECIMALS;
            }

            if (decimals == 0)
            {
                formatter = VALUE_FORMATTER;
            }
            else
            {
                sb.Clear();
                sb.Append(VALUE_FORMATTER);
                sb.Append(".");

                for (int i = 0; i < decimals; i++)
                {
                    sb.Append(VALUE_FORMATTER);
                }

                formatter = sb.ToString();
            }
        }
Ejemplo n.º 4
0
 public static void InitUnitType(BluetoothCmd bthcmd, UserSettings.UNIT_TYPE Unit_Type)
 {
     if (Unit_Type == UserSettings.UNIT_TYPE.IMPERIAL)
     {
         unitsImperial.InitType(bthcmd);
     }
     else
     {
         unitsMetric.InitType(bthcmd);
     }
 }
Ejemplo n.º 5
0
        public void Page_Appearing(object sender, EventArgs e)
        {
            UpdateControls();
            UpdateUserSettings();

            // Call listview generation only if units have changed
            if (oUserSettings.GetUserUnits() != UnitType_Last)
            {
                UnitType_Last = oUserSettings.GetUserUnits();
                UpdateListViewItems();
            }
        }
Ejemplo n.º 6
0
 public void InitUserSettings(out UserSettings usersettings)
 {
     usersettings  = App.GetUserSettings();
     UnitType_Last = UserSettings.UNIT_TYPE.NONE;
 }
Ejemplo n.º 7
0
        public void CreateTestCommands(UserSettings.UNIT_TYPE Unit_Type, bool isInitialize)
        {
            // Format 01##01
            // 01 = Service
            // https://en.wikipedia.org/wiki/OBD-II_PIDs#Service_05

            Add(new BluetoothCmd()
            {
                Id   = 0,
                Name = "IGN",
                Expression_Imperial = "",
                Units_Imperial      = "",
                Decimals            = 0,
                Cmd            = "ATIGN",
                Rate           = 1000,
                isRxBytes      = false,
                isSelected     = true,
                Selection_Type = SELECTION_TYPE.USER,
                Command_Types  = new[] { COMMAND_TYPE.DEFAULT }
            });

            Add(new BluetoothCmd()
            {
                Id   = 1,
                Name = "TEMP",
                Expression_Imperial = "(a * 100 / 255)",
                Units_Imperial      = "F",
                Expression_Metric   = "(a * 100 / 255)",
                Units_Metric        = "C",
                Cmd            = "01051",
                Rate           = 2000,
                Decimals       = 2,
                Value_Min      = -60,
                Value_Max      = 300,
                isRxBytes      = true,
                Bytes          = 1,
                isSelected     = true,
                Selection_Type = SELECTION_TYPE.USER,
                Command_Types  = new[] { COMMAND_TYPE.DEFAULT }
            });

            Add(new BluetoothCmd()
            {
                Id   = 2,
                Name = "VSS",
                Expression_Imperial = "(a * 1)",
                Units_Imperial      = "MPH",
                Expression_Metric   = "(a * 1)",
                Units_Metric        = "KPH",
                Cmd            = "010D1",
                Rate           = 1000,
                Decimals       = 2,
                Value_Min      = 0,
                Value_Max      = 300,
                isRxBytes      = true,
                Bytes          = 1,
                isSelected     = true,
                Selection_Type = SELECTION_TYPE.USER,
                Command_Types  = new[] { COMMAND_TYPE.VSS }
            });

            Add(new BluetoothCmd()
            {
                Id   = 3,
                Name = "TPS",
                Expression_Imperial = "(a * 1)",
                Units_Imperial      = "%",
                Expression_Metric   = "(a * 1)",
                Units_Metric        = "%",
                Cmd            = "010D1",
                Rate           = 1000,
                Decimals       = 0,
                Value_Min      = 0,
                Value_Max      = 100,
                isRxBytes      = true,
                Bytes          = 1,
                isSelected     = false,
                Selection_Type = SELECTION_TYPE.USER,
                Command_Types  = new[] { COMMAND_TYPE.TPS }
            });

            Add(new BluetoothCmd()
            {
                Id   = 4,
                Name = "MAF",
                Expression_Imperial = "(a * 1)",
                Units_Imperial      = "G/S",
                Expression_Metric   = "(a * 1)",
                Units_Metric        = "G/S",
                Cmd            = "010D1",
                Rate           = 1000,
                Decimals       = 2,
                Value_Min      = 0,
                Value_Max      = 10000,
                isRxBytes      = true,
                Bytes          = 1,
                isSelected     = false,
                Selection_Type = SELECTION_TYPE.USER,
                Command_Types  = new[] { COMMAND_TYPE.MAF }
            });

            Add(new BluetoothCmd()
            {
                Id   = 5,
                Name = "RPM",
                Expression_Imperial = "(a * 1)",
                Units_Imperial      = "x1000",
                Expression_Metric   = "(a * 1)",
                Units_Metric        = "x1000",
                Cmd           = "010D1",
                Rate          = 500,
                Decimals      = 0,
                Value_Min     = 0,
                Value_Max     = 10000,
                isRxBytes     = true,
                Bytes         = 1,
                isSelected    = false,
                Command_Types = new[] { COMMAND_TYPE.DEFAULT }
            });

            Add(new BluetoothCmd()
            {
                Id   = 6,
                Name = "Mileage",
                Expression_Imperial = "(14.7*b*1740.572)/(3600*c/100)",
                Units_Imperial      = "MPG",
                Expression_Metric   = "(14.7*b*1740.572)/(3600*c/100)",
                Units_Metric        = "KPG",
                Cmd           = "",
                Rate          = 2000,
                Decimals      = 1,
                Value_Min     = 0,
                Value_Max     = 100,
                isRxBytes     = false,
                Bytes         = 0,
                isSelected    = false,
                Command_Types = new[] { COMMAND_TYPE.MPG, COMMAND_TYPE.VSS, COMMAND_TYPE.MAF }
            });

            if (isInitialize)
            {
                InitCommandBytes();
                InitExpressions(Unit_Type);
            }
        }