Beispiel #1
0
        public ViewModel()
        {
            var cfg = new Settings("settings.json");

            //Simulator = new MockSimulatorImpl();
            Simulator = new FlightSimulator();
            if (Simulator is FlightSimulator fs)
            {
                SimulatorStatus     = "Not connected to flight simulator.  Please restart the application to attempt connecting again.";
                fs.PropertyChanged += (s, e) => {
                    if (fs.Connected)
                    {
                        SimulatorStatus = $"Connected to {fs.SimulatorName}.";
                    }
                    else
                    {
                        SimulatorStatus = "Disconnected from flight simulator.  Please restart the application to connect again.";
                    }
                };

                fs.Initialize();
            }

            MessageSource = new MQTTMessageProvider(Simulator);
            if (MessageSource is MQTTMessageProvider mqtt)
            {
                mqtt.PropertyChanged += (s, e) => {
                    if (e.PropertyName == "State")
                    {
                        switch (mqtt.State)
                        {
                        case MQTTMessageState.Offline:
                            MessageStatus = "MQTT connection offline.";
                            break;

                        case MQTTMessageState.Pairing:
                            MessageStatus = $"Tell Alexa, \"ask Virtual Copilot to pair with {NNumber.Phonetic(mqtt.PairingKey)}.\"";
                            break;

                        case MQTTMessageState.Listening:
                            MessageStatus = "Listening for commands.";
                            break;
                        }
                    }
                };

                Task.Run(() => mqtt.Initialize(cfg));
            }
        }
Beispiel #2
0
 public MQTTMessageProvider(ISimulator Simulator) : base(Simulator)
 {
     State      = MQTTMessageState.Offline;
     PairingKey = NNumber.Generate();
 }