public double GetConvertedValue(MeasuringUnits pNewUnit, MeasuringUnits pOldUnit, double pDataPoint)
        {
            switch (pOldUnit)
            {
            case MeasuringUnits.Meter:

                switch (pNewUnit)
                {
                case MeasuringUnits.Meter:
                    return(pDataPoint);

                case MeasuringUnits.Feet:
                    return(MetersToFeet(pDataPoint));
                }
                break;

            case MeasuringUnits.Feet:
                switch (pNewUnit)
                {
                case MeasuringUnits.Meter:
                    return(FeetToMeters(pDataPoint));

                case MeasuringUnits.Feet:
                    return(pDataPoint);
                }
                break;
            }
            return(0);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, what do you want to cook? (1 for Rice, 2 for Beans, 3 for Amala)");
            int  foodInt      = int.Parse(Console.ReadLine());
            Food foodSelected = (Food)foodInt;

            Console.WriteLine($"Okay, you want to cook {foodSelected}. Cooool.");

            Console.WriteLine("Do you want to add an ingredient. (Y for yes and N for no)");
            string            reply       = Console.ReadLine().ToUpper();
            bool              replyBool   = reply == "Y" ? true : false;
            List <Ingredient> Ingredients = new List <Ingredient>();

            while (replyBool)
            {
                Ingredient Ingredient = new Ingredient();
                Console.WriteLine("Enter the name of the ingredient: ");
                string IngredientName = Console.ReadLine();
                Ingredient.name = IngredientName;

                Console.WriteLine("Enter the quantity: ");
                double IngredientQuantity = double.Parse(Console.ReadLine());
                Ingredient.quantity = IngredientQuantity;

                Console.WriteLine("Enter the units: (1 for ounce, 2 for kg, 3 for pinch, 4 for cup and 5 for litre");
                MeasuringUnits unit = (MeasuringUnits)int.Parse(Console.ReadLine());
                Ingredient.unit = unit;

                Ingredients.Add(Ingredient);

                Console.WriteLine("Do you want to add more? (Y for yes and N for no)");
                reply     = Console.ReadLine().ToUpper();
                replyBool = reply == "Y" ? true : false;
            }
            foreach (var Ingredient in Ingredients)
            {
                System.Console.WriteLine($"{Ingredient.quantity} {Ingredient.unit} of {Ingredient.name}");
            }
            Console.WriteLine("Hope it taste nice?");
        }
Exemple #3
0
        /// <summary>
        /// Only triggers a shot ulrasons
        /// </summary>
        /// <param name="units">unit of measure expected</param>
        public void TrigShotUS(MeasuringUnits units)
        {
            this.unit = units;
                // Calcul du mot de commande à partir de l'unité de mesure
                byte commandByte = (byte)(80 + (byte)units);

                // Création d'un buffer et d'une transaction pour l'accès au module en écriture
                byte[] outbuffer = new byte[] { (byte)Registers.Command, commandByte };
                I2CDevice.I2CTransaction WriteUnit = I2CDevice.CreateWriteTransaction(outbuffer);

                // Tableaux des transactions
                I2CDevice.I2CTransaction[] T_WriteUnit = new I2CDevice.I2CTransaction[] { WriteUnit };

                // Exécution de la transactions
                busI2C = new I2CDevice(ConfigSRF08); // Connexion virtuelle de l'objet SRF08 au bus I2C
                busI2C.Execute(T_WriteUnit, TRANSACTIONEXECUTETIMEOUT); // Transaction : Activation US
                busI2C.Dispose(); // Déconnexion virtuelle de l'objet SRF08 du bus I2C
        }
Exemple #4
0
        /// <summary>
        /// Triggers a shot ulrasons, wait for 75ms and return result in the unit of measure
        /// </summary>
        /// <param name="units">unit of measure expected</param>
        /// <returns>range in cm or inches or millisec</returns>
        public UInt16 ReadRange(MeasuringUnits units)
        {
            this.unit = units;
                // Calcul du mot de commande à partir de l'unité de mesure
                byte command = (byte)(80 + (byte)units);

                // Création d'un buffer et d'une transaction pour l'accès au module en écriture
                byte[] outbuffer = new byte[] { (byte)Registers.Command, command };
                I2CDevice.I2CTransaction WriteUnit = I2CDevice.CreateWriteTransaction(outbuffer);

                // Création d'un buffer et d'une transaction pour l'accès au module en lecture
                byte[] inbuffer = new byte[4];
                I2CDevice.I2CTransaction ReadDist = I2CDevice.CreateReadTransaction(inbuffer);

                // Tableaux des transactions
                I2CDevice.I2CTransaction[] T_WriteUnit = new I2CDevice.I2CTransaction[] { WriteUnit };
                I2CDevice.I2CTransaction[] T_ReadDist = new I2CDevice.I2CTransaction[] { ReadDist };

                // Exécution des transactions
                busI2C = new I2CDevice(ConfigSRF08); // Connexion virtuelle de l'objet SRF08 au bus I2C
                busI2C.Execute(T_WriteUnit, TRANSACTIONEXECUTETIMEOUT); // Transaction : Activation US
                Thread.Sleep(75); // attente echo US
                busI2C.Execute(T_ReadDist, TRANSACTIONEXECUTETIMEOUT); // Transaction : Lecture distance
                UInt16 range = (UInt16)((UInt16)(inbuffer[3] << 8) + inbuffer[2]); // Calcul de la distance
                busI2C.Dispose(); // Déconnexion virtuelle de l'objet SRF08 du bus I2C
                return range;
        }