Exemplo n.º 1
0
        private void Probe_DataChanged(object sender, GenericEventArgs <float> e)
        {
            var data = e.Data.ToString();

            ProbePublisher?.Publish(HelenApi.CreateDataMessage(Settings.ApiId, data));
            ConsoleExtensions.WriteDebugLocation(data, 0);
            Messenger.PrintDebugInfo();
        }
Exemplo n.º 2
0
 public void Connect()
 {
     if (!IsConnected && !connectInProgress)
     {
         Task.Run(() =>
         {
             connectInProgress = true;
             try
             {
                 Client.Connect(Guid.ToString());
             }
             catch (Exception)
             {
                 ConsoleExtensions.WriteDebugLocation($"Connected to broker: failed", 1);
             }
             finally
             {
                 connectInProgress = false;
                 OnConnectionStatusChanged();
             }
         });
     }
 }
Exemplo n.º 3
0
 public void PrintDebugInfo()
 {
     ConsoleExtensions.WriteDebugLocation($"Connected to broker: {IsConnected}", 1);
 }
Exemplo n.º 4
0
        private static bool HandleInput(AppSettings settings, SensorManager manager)
        {
            string input = Console.ReadLine();

            if (input.Equals("exit", StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }
            else if (input.Equals("help", StringComparison.InvariantCultureIgnoreCase))
            {
                PrintOptions(settings);
            }
            else if (input.Equals("clear", StringComparison.InvariantCultureIgnoreCase))
            {
                Console.Clear();
            }
            else if (input.Equals("reset", StringComparison.InvariantCultureIgnoreCase))
            {
                ConsoleExtensions.WriteLine("Please confirm this action by typing 'yes please'");
                if (Console.ReadLine() == "yes please")
                {
                    settings.ResetToDefaults();
                    manager.UpdateFromSettings(settings);
                    settings.SaveSettings();
                }
            }
            else if (input.StartsWith("msg: "))
            {
                var msg = input.Substring(4).Trim();
                manager.ProbePublisher.Publish(msg);
            }
            else if (input.Equals("stop", StringComparison.InvariantCultureIgnoreCase))
            {
                manager.Probe.Stop();
                ConsoleExtensions.WriteDebugLocation("       ", 0);
            }
            else if (input.Equals("start", StringComparison.InvariantCultureIgnoreCase))
            {
                manager.Probe.Start();
            }
            else if (input.Equals("list probes", StringComparison.InvariantCultureIgnoreCase) && manager.Probe is Probes.LinuxTempProbe)
            {
                var lprobe = manager.Probe as Probes.LinuxTempProbe;
                foreach (var name in lprobe.GetOneWireDeviceNames())
                {
                    ConsoleExtensions.WriteLine("  " + name);
                }
            }
            else
            {
                if (ReadProperty(settings, input))
                {
                    manager.UpdateFromSettings(settings);
                    settings.SaveSettings();
                }
                else
                {
                    ConsoleExtensions.WriteLine("Unrecognized command");
                }
            }
            return(true);
        }