Example #1
0
        public void TestConvertVoltageToResistance2()
        {
            // Got Resistance 235409.820661915 from voltage 2.3161289870739
            double data = TempUtils.GetThermistorResistenceFromVoltage(3.3, 2.3161289870739, 100000);

            Assert.AreEqual(42479, (int)data);
        }
Example #2
0
        public void TestConvertVoltageToResistence()
        {
            // This was checked with https://www.allaboutcircuits.com/tools/voltage-divider-calculator/
            double data = TempUtils.GetThermistorResistenceFromVoltage(3.3, 1.66, 100000);

            Assert.AreEqual(98795, (int)data);
        }
        public Task <Temps> ReadThermometer(int index)
        {
            // Get a random raw value 0 - 499 kelvin
            int    kelvin  = this.random.Next(0, 500);
            double celcius = TempUtils.KelvinToCelcius(kelvin);
            var    temps   = new Temps
            {
                Kelvin      = kelvin,
                Celcius     = celcius,
                Farenheight = TempUtils.CelciusToFarenheight(celcius),
            };

            return(Task.FromResult(temps));
        }
Example #4
0
        public async Task <Temps> ReadThermometer(int index)
        {
            if (index < 0 || index > 7)
            {
                throw new IndexOutOfRangeException("Index must be from 0-7");
            }

            using (await this.thermometerLock.LockAsync())
            {
                await this.initTask;

                double    sum        = 0;
                const int numSamples = 3;
                for (int i = 0; i < numSamples; i++)
                {
                    var reading = this.mcp.Read(Channels[index]);
                    sum += reading.NormalizedValue;
                    await Task.Delay(100);
                }

                double averageValue = sum / numSamples;

                //Debug.WriteLine($"Reading for thermometer {index} is {reading.RawValue}, Normalized: {reading.NormalizedValue}");

                double voltage    = averageValue * InputVoltage;
                double resistance = TempUtils.GetThermistorResistenceFromVoltage(3.3, voltage, BalancingResistorOhms);
                //Debug.WriteLine($"Got Resistance {resistance} from voltage {voltage}");

                CoefficientSet coefficients = Coefficients[0];

                var temps = new Temps();
                if (double.IsInfinity(resistance))
                {
                    temps.Kelvin = 0;
                }
                else
                {
                    temps.Kelvin = TempUtils.ResistanceToTemp(coefficients.A, coefficients.B, coefficients.C, resistance);
                }

                temps.Celcius     = TempUtils.KelvinToCelcius(temps.Kelvin);
                temps.Farenheight = TempUtils.CelciusToFarenheight(temps.Celcius);

                return(temps);
            }
        }
Example #5
0
        public void TestTheseNumbers()
        {
            double a, b, c;

            a = -1.373357407E-3;
            b = 4.914938378E-4;
            c = -5.890760444E-7;

            double tempK = TempUtils.ResistanceToTemp(a, b, c, 101219);

            Assert.AreEqual(295, Math.Round(tempK));

            double tempC = TempUtils.KelvinToCelcius(tempK);

            Assert.AreEqual(22, Math.Round(tempC));

            double tempF = TempUtils.CelciusToFarenheight(tempC);

            Assert.AreEqual(71, Math.Round(tempF));
        }
Example #6
0
        public void TestAgain()
        {
            // 33500 / 122F
            double a, b, c;

            a = -1.373357407E-3;
            b = 4.914938378E-4;
            c = -5.890760444E-7;

            double tempK = TempUtils.ResistanceToTemp(a, b, c, 33500);

            Assert.AreEqual(325, Math.Round(tempK));

            double tempC = TempUtils.KelvinToCelcius(tempK);

            Assert.AreEqual(51, Math.Round(tempC));

            double tempF = TempUtils.CelciusToFarenheight(tempC);

            Assert.AreEqual(124, Math.Round(tempF));
        }
        public MainWindow(
            [NotNull] IAppSettings appSettings,
            [NotNull] ApplicationUtils applicationUtils,
            [NotNull] IMainWindowViewModel viewModel,
            [NotNull] Provider <MainWindow> mainWindowProvider,
            [NotNull] Provider <InstallApkWindow> installApkWindowProvider,
            [NotNull] Provider <AboutWindow> aboutWindowProvider,
            [NotNull] Provider <AdbInstallWindow> adbInstallWindowProvider,
            [NotNull] NotificationManager notificationManager,
            [NotNull] TempUtils tempUtils,
            [NotNull] GlobalVariables globalVariables,
            [NotNull] Utils utils,
            [NotNull] Provider <IApktool> apktoolProvider
            )
        {
            _settings                 = appSettings;
            _applicationUtils         = applicationUtils;
            _mainWindowProvider       = mainWindowProvider;
            _installApkWindowProvider = installApkWindowProvider;
            _aboutWindowProvider      = aboutWindowProvider;
            _adbInstallWindowProvider = adbInstallWindowProvider;
            _notificationManager      = notificationManager;
            _tempUtils                = tempUtils;
            _globalVariables          = globalVariables;
            _utils           = utils;
            _apktoolProvider = apktoolProvider;

            ViewModel   = viewModel;
            DataContext = ViewModel;

            InitializeComponent();

            _taskBarManager = new TaskBarManager(TaskbarItemInfo = new TaskbarItemInfo());

            _visualProgress = StatusProgress.GetVisualProgress();

            _visualProgress.SetLabelText(MainResources.AllDone);
        }
Example #8
0
        public InstallApkViewModel(
            [NotNull] IAppSettings appSettings,
            [NotNull] NotificationManager notificationManager,
            [NotNull] TempUtils tempUtils,
            [NotNull] GlobalVariables globalVariables,
            [NotNull] Provider <IApktool> apktoolProvider,
            [NotNull] Provider <AdbInstallWindow> adbInstallWindowProvider
            )
        {
            _settings                 = appSettings;
            _notificationManager      = notificationManager;
            _tempUtils                = tempUtils;
            _globalVariables          = globalVariables;
            _apktoolProvider          = apktoolProvider;
            _adbInstallWindowProvider = adbInstallWindowProvider;

            AppTitle = new DelegatedProperty <string>(
                valueResolver: () => Path.GetFileNameWithoutExtension(Apk.Value) + " mod",
                valueApplier: null
                ).DependsOn(Apk).AsReadonly();

            string iconsFolder = Path.Combine(_globalVariables.PathToResources, "icons");

            BitmapSource GetImage(string name) =>
            LFile.ReadAllBytes(Path.Combine(iconsFolder, name)).ToBitmap().ToBitmapSource();

            IconsStorage = new AppIconsStorage
            {
                Icon_xxhdpi = { Value = GetImage("xxhdpi.png") },
                Icon_xhdpi  = { Value = GetImage("xhdpi.png") },
                Icon_hdpi   = { Value = GetImage("hdpi.png") },
                Icon_mdpi   = { Value = GetImage("mdpi.png") }
            };

            // commands
            ChooseApkCommand = new ActionCommand(() =>
            {
                var(success, filePath) = PickerUtils.PickFile(filter: MainResources.AndroidFiles + @" (*.apk)|*.apk");

                if (success)
                {
                    Apk.Value = filePath;
                }
            }, () => !Working.Value).BindCanExecute(Working);
            ChooseSaveCommand = new ActionCommand(() =>
            {
                if (_settings.BackupType == BackupType.LuckyPatcher)
                {
                    var(success, folderPath) = PickerUtils.PickFolder();

                    if (success)
                    {
                        Save.Value = folderPath;
                    }
                }
                else
                {
                    var(success, filePath) = PickerUtils.PickFile(filter: MainResources.Archives + @" (*.tar.gz)|*.tar.gz");

                    if (success)
                    {
                        Save.Value = filePath;
                    }
                }
            }, () => !Working.Value).BindCanExecute(Working);
            ChooseDataCommand = new ActionCommand(() =>
            {
                var(success, filePath) = PickerUtils.PickFile(filter: MainResources.ZipArchives + @" (*.zip)|*.zip");

                if (success)
                {
                    Data.Value = filePath;
                }
            }, () => !Working.Value).BindCanExecute(Working);
            ChooseObbCommand = new ActionCommand(() =>
            {
                var(success, filePaths) = PickerUtils.PickFiles(filter: MainResources.CacheFiles + @" (*.obb)|*.obb");

                if (success)
                {
                    Obb.Value = filePaths;
                }
            }, () => !Working.Value).BindCanExecute(Working);
            StartCommand = new ActionCommand(StartCommand_Execute, () => !Working.Value).BindCanExecute(Working);
        }