Exemplo n.º 1
0
        private async Task DoCommandAsync(Command command, bool wait)
        {
            if (command == null)
            {
                return;
            }
            CurrCommandState = CommandState.Busy;

            Variables.Init(command.Set);
            var cmd = command.Replace;

            if (!string.IsNullOrEmpty(command.Compute))
            {
                var commandlist = command.Compute.Split(new char[] { ' ' });
                cmd = "";
                foreach (var strcommand in commandlist)
                {
                    var calculateResult = BleEditor.ValueCalculate.Calculate(strcommand, double.NaN, null, Variables);
                    cmd += calculateResult.S ?? calculateResult.D.ToString();
                }

                Variables.CopyToPrev();
            }
            if (!string.IsNullOrEmpty(command.ReplaceFile))
            {
                // Is like SerialFiles\\Espruino_Modules_Smartibot.js in the Assets directory
                var filename = command.ReplaceFile;
                try
                {
                    StorageFolder InstallationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
                    string        fname = @"Assets\" + filename;
                    var           f     = await InstallationFolder.GetFileAsync(fname);

                    var fcontents = File.ReadAllText(f.Path);
                    cmd = fcontents;
                }
                catch (Exception)
                {
                }
            }
            if (!String.IsNullOrEmpty(cmd))
            {
                AddInputTextToUI(cmd);
                SendDataToListener(cmd);
                if (wait)
                {
                    await Task.Delay(100);       // wait until the device has the chance to handle the command.
                }
            }
            CurrCommandState = CommandState.Ready;

            // And do the follow-on command, if any.
            if (!string.IsNullOrEmpty(command.OnChange))
            {
                await DoCommandAsync(command.OnChange);
            }
        }
Exemplo n.º 2
0
        public string DoCompute()
        {
            Variables.SetCurrValue(Parameters);

            var list = Compute.Split(new char[] { ' ' });
            var cmd  = "";

            foreach (var strcommand in list)
            {
                var calculateResult = BleEditor.ValueCalculate.Calculate(strcommand, double.NaN, null, Variables);
                cmd += calculateResult.S ?? calculateResult.D.ToString();
            }
            Variables.CopyToPrev();
            return(cmd);
        }