Exemplo n.º 1
0
        public override void updateChart(BMChart chart, String text)
        {
            if (!(chart is BMLineChart))
            {
                return;
            }
            BMLineChart lineChart = (BMLineChart)chart;

            // Only continue if it's THD values
            //Matcher matcher = burst_pattern.matcher(text);
            //if (!matcher.matches()) return;
            Match matcher = burst_pattern.Match(text);

            if (!matcher.Success)
            {
                return;
            }

            // Parse values
            float[] value = new float[3];
            for (int i = 0; i < value.Length; i++)
            {
                value[i] = float.Parse(matcher.Groups[i + 1].Value.Trim());
            }

            // Insert values as new entries
            int index = lineChart.getEntryCount() / 3;

            lineChart.addEntry("Temperature (" + getTempUnits() + ")", new Entry(index, value[0]));
            lineChart.addEntry("Humidity", new Entry(index, value[1]));
            lineChart.addEntry("Dew Point (" + getTempUnits() + ")", new Entry(index, value[2]));
        }
Exemplo n.º 2
0
        public override void setupChart(BMChart chart, String command)
        {
            if (!(chart is BMLineChart))
            {
                return;
            }
            BMLineChart lineChart = (BMLineChart)chart;

            if (command.Equals("*bur"))
            {
                isDownloadReady = !isDownloadReady;
                // If we sent the "*bur" command, setup the chart
                lineChart.init("", 5);
                lineChart.setLabels(
                    new String[] {
                    "Temperature (" + getTempUnits() + ")",
                    "Humidity",
                    "Dew Point (" + getTempUnits() + ")"
                },
                    new Color[] {
                    Colors.Red,
                    Colors.Blue,
                    Colors.Green
                }
                    );
            }
            else if (new Regex("\\*units[c|f]").IsMatch(command))
            {
                // If we sent the "*units" command, change units
                bool   change   = true;
                String oldUnits = getTempUnits();
                switch (command[command.Length - 1])
                {
                case 'c': if (isInFahrenheit())
                    {
                        _mode -= 100;
                    }
                    break;

                case 'f': if (!isInFahrenheit())
                    {
                        _mode += 100;
                    }
                    break;

                default: change = false; break;
                }
                if (!change)
                {
                    return;
                }
                int     length      = lineChart.getEntryCount() / 3;
                float[] temperature = new float[length];
                float[] humidity    = new float[length];
                float[] dewPoint    = new float[length];
                Log.d("BMTempHumi", "Length: " + length);
                // Store the old temperatures
                for (int i = 0; i < length; i++)
                {
                    temperature[i] = lineChart.getEntry("Temperature (" + oldUnits + ")", i).getY();
                    humidity[i]    = lineChart.getEntry("Humidity", i).getY();
                    dewPoint[i]    = lineChart.getEntry("Dew Point (" + oldUnits + ")", i).getY();
                }
                // Manipulate the graph
                lineChart.setLabels(
                    new String[] {
                    "Temperature (" + getTempUnits() + ")",
                    "Humidity",
                    "Dew Point (" + getTempUnits() + ")"
                },
                    new Color[] {
                    Colors.Red,
                    Colors.Blue,
                    Colors.Green
                }
                    );
                // Manipulate the data
                for (int i = 0; i < length; i++)
                {
                    temperature[i] = (isInFahrenheit())
                            ? temperature[i] * 1.8f + 32.0f
                            : (temperature[i] - 32.0f) / 1.8f;
                    dewPoint[i] = (isInFahrenheit())
                            ? dewPoint[i] * 1.8f + 32.0f
                            : (dewPoint[i] - 32.0f) / 1.8f;
                }
                // Add the temperatures back in
                for (int i = 0; i < length; i++)
                {
                    lineChart.addEntry("Temperature (" + getTempUnits() + ")", new Entry(i, temperature[i]));
                    lineChart.addEntry("Humidity", new Entry(i, humidity[i]));
                    lineChart.addEntry("Dew Point (" + getTempUnits() + ")", new Entry(i, dewPoint[i]));
                }
            }
            else if (new Regex("\\*lint([0-9]+)").IsMatch(command))
            {
                Match matcher = new Regex("\\*lint([0-9]+)").Match(command);
                //matcher.matches();
                int newLoggingInterval = int.Parse(matcher.Groups[1].Value.Trim());
                //BMDatabase database = BMDeviceMap.INSTANCE.getBMDatabase(getAddress());
                //if (loggingInterval != newLoggingInterval)
                //{
                //    database.clear();
                //}
                _loggingInterval = newLoggingInterval;
                //database.setLoggingInterval(loggingInterval);
            }
        }