private async void MainPage_Loaded(object s, RoutedEventArgs e) { disconnected(); _mqtt = new MqttClient("m11.cloudmqtt.com", 12360, false, MqttSslProtocols.None); _mqtt.ConnectionClosed += (sender, args) => { disconnected(); }; _mqtt.MqttMsgSubscribed += (sender, args) => { connected(); }; _mqtt.MqttMsgPublishReceived += (sender, args) => { var msg = Encoding.ASCII.GetString(args.Message); switch (msg) { case "happy": { _animator.drawFrame(0); } break; case "sad": { _animator.drawFrame(1); } break; case "indifferent": { _animator.drawFrame(2); } break; } _clear.schedule(() => _backpack.clear(), 5000); }; Task.Run(() => { _mqtt.Connect("1", "mike", "cloudmqtt"); _mqtt.Subscribe(new[] {"mqttdotnet/pubtest/#"}, new[] {MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE}); }); _backpack = new Adafrut8x8LEDBackpack(); await _backpack.initializeAsync(); _animator = new BackpackAnimator(_backpack, EmoticonsFrameGenerator.getAnimationFrames()); }
private async void MainPage_Loaded(object sender, RoutedEventArgs e) { btnStart.IsEnabled = true; btnStop.IsEnabled = false; _backpack = new Adafrut8x8LEDBackpack(); await _backpack.initializeAsync(); _animator = new BackpackAnimator(_backpack, SpaceInvaderAnimationFrameGenerator.getAnimationFrames()); }