Пример #1
0
        private Weight ReadWeight()
        {
            _readLock.Wait();
            try
            {
                int           raw        = ReadRaw();
                double        unitValue  = (raw - TareValue) / _settings.CalibrationValue;
                IWeightSystem baseWeight = null;
                if (_settings.CalibrationWeightSystem == WeightSystem.Metric)
                {
                    baseWeight = new MetricWeight(unitValue, _settings.CalibrationMetricUnit);
                }
                else if (_settings.CalibrationWeightSystem == WeightSystem.Imperial)
                {
                    baseWeight = new ImperialWeight(unitValue, _settings.CalibrationImperialUnit);
                }
                else
                {
                    throw new Exception("HX711 was uncalibrated or not calibrated properly and can't convert to a weight!");
                }

                return(new Weight(baseWeight));
            }
            finally
            {
                _readLock.Release();
            }
        }
Пример #2
0
        public void TestConvertImperialToMetric()
        {
            var result = ImperialWeight.FromStonePoundsAndOunces(12, 8, 5.9136M);

            Assert.AreEqual(176.37M, result.TotalPounds);
            Assert.AreEqual(12, result.Stone);
            Assert.AreEqual(8, result.Pounds);
            Assert.AreEqual(5.9136M, result.Ounces);
            Assert.AreEqual(80M, result.TotalKilos);
        }
Пример #3
0
        public WeightConversionTableViewModel(IActionSheetController sheetController, INavigationService navigationService, ISchedulerService scheduler, IViewModelFactory viewModelFactory)
            : base(navigationService, scheduler)
        {
            if (viewModelFactory == null)
            {
                throw new ArgumentNullException(nameof(viewModelFactory));
            }

            Title             = "Weight Conversion";
            ShowNavigationBar = true;
            Intent            = TableIntent.Form;

            SeparatorStyle = TableCellSeparatorStyle.SingleLine;
            _topSection    = AddSection("Converter");

            var poundsCell = new NumericEntryCellViewModel()
            {
                Label = "Pounds", IsInteger = false
            };
            var kilosCell = new NumericEntryCellViewModel()
            {
                Label = "Kilos", IsInteger = false
            };


            poundsCell.Values.ObserveOn(Scheduler.UiScheduler)
            .Where(e => e.HasValue)
            .Subscribe((e) =>
            {
                // We have a new pounds value, we need to process this and push the related kilos value to the kilos cell.
                kilosCell.Value = WeightConverter.ToKilosFromPounds(e.Value);
            });

            _topSection.AddCell(poundsCell);


            kilosCell.Values.ObserveOn(Scheduler.UiScheduler)
            .Where(e => e.HasValue)
            .Subscribe((e) =>
            {
                poundsCell.Value = ImperialWeight.FromKilos(e.Value).TotalPounds;
            });

            _topSection.AddCell(kilosCell);
        }