public async void Run(IBackgroundTaskInstance taskInstance) { deferral = taskInstance.GetDeferral(); hubUser = $"{cm.hubAddress}/{cm.hubName}"; hubTopicPublish = $"devices/{cm.hubName}/messages/events/"; hubTopicSubscribe = $"devices/{cm.hubName}/messages/devicebound/#"; this.hat = await FEZHAT.CreateAsync(); // https://m2mqtt.wordpress.com/m2mqtt_doc/ client = new MqttClient(cm.hubAddress, 8883, true, MqttSslProtocols.TLSv1_2); client.MqttMsgPublishReceived += Client_MqttMsgPublishReceived; client.Subscribe(new string[] { hubTopicSubscribe }, new byte[] { 0 }); var result = Task.Run(async() => { while (true) { if (!client.IsConnected) { client.Connect(cm.hubName, hubUser, cm.hubPass); } if (client.IsConnected) { client.Publish(hubTopicPublish, temperature.ToJson(hat.GetTemperature())); client.Publish(hubTopicPublish, light.ToJson(hat.GetLightLevel())); } await Task.Delay(30000); // don't leave this running for too long at this rate as you'll quickly consume your free daily Iot Hub Message limit } }); }
public async void Run(IBackgroundTaskInstance taskInstance) { #region Expand to view variable initialisation deferral = taskInstance.GetDeferral(); hat = await FEZHAT.CreateAsync(); deviceClient = ConnectionString.StartsWith("Connection") ? null : DeviceClient.CreateFromConnectionString(ConnectionString); telemetry = new Telemetry("Sydney", Publish, 10); Command_Processing(); #endregion #region Code snippets lab2 and lab3 to go between the #region and #endregion tags while (true) { hat.D2.Color = FEZHAT.Color.Red; await Task.Delay(500); hat.D2.Color = FEZHAT.Color.Green; await Task.Delay(500); hat.D2.Color = FEZHAT.Color.Blue; await Task.Delay(500); } #endregion }
public async Task InitializeHat() { FezHat = await FEZHAT.CreateAsync(); FezHat.D2.TurnOff(); FezHat.D3.TurnOff(); }
public void Init() { var task = FEZHAT.CreateAsync(); task.Wait(); _instance = task.Result; }
private async Task SetupHatAsync() { this.hat = await FEZHAT.CreateAsync(); this.telemetryTimer = new DispatcherTimer(); this.telemetryTimer.Interval = TimeSpan.FromMilliseconds(2000); this.telemetryTimer.Tick += this.TelemetryTimer_Tick; this.telemetryTimer.Start(); }
private async void InitializeLight() { this.hat = await FEZHAT.CreateAsync(); this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(300); this.timer.Tick += Timer_Tick; this.timer.Start(); }
private async void Setup() { hat = await FEZHAT.CreateAsync(); hat.S1.SetLimits(500, 2400, 0, 180); hat.S2.SetLimits(500, 2400, 0, 180); timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(100); timer.Tick += OnTick; }
private async void SetupHat() { this.hat = await FEZHAT.CreateAsync(); this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(500); this.timer.Tick += this.Timer_Tick; this.timer.Start(); }
private async void SetupHat() { _hat = await FEZHAT.CreateAsync(); _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(400) }; _timer.Tick += Timer_Tick; _timer.Start(); }
private async void MainPage_Loaded(object sender, RoutedEventArgs e) { this.hat = await FEZHAT.CreateAsync(); var timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(0.25); timer.Tick += Timer_Tick; timer.Start(); this.timer = timer; }
private async void Start() { redBrush = new SolidColorBrush(Colors.Red); blueBrush = new SolidColorBrush(Colors.Blue); blackBrush = new SolidColorBrush(Colors.Black); hat = await FEZHAT.CreateAsync(); timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 0, 0, 500); timer.Tick += Timer_Tick; timer.Start(); }
private static async void SetupHat() { // Initialize Fez Hat logger.Info("Initializing FEZ HAT"); hat = await FEZHAT.CreateAsync(); // Initialize Timer timer = new Timer(2000); // (TimerCallback, null, 0, 500); timer.Elapsed += Timer_Elapsed; timer.Enabled = true; Program.logger.Info("FEZ HAT Initialized"); }
public async void Run(IBackgroundTaskInstance taskInstance) { deferral = taskInstance.GetDeferral(); hat = await FEZHAT.CreateAsync(); hat.D2.TurnOff(); hat.D3.TurnOff(); telemetry = new Telemetry("Sydney", Publish, 30); iotHubCommand = new IoTHubCommand <string>(deviceClient, telemetry); iotHubCommand.CommandReceived += Commanding_CommandReceived; }
private async Task Init() { hat = await FEZHAT.CreateAsync(); Shades.Add(new ShadeItemViewModel(hat.MotorA, 5, "Left Window", hat.D2)); Shades.Add(new ShadeItemViewModel(hat.MotorB, 5, "Right Window", hat.D3)); // Main Timer - For Temp, light reading and status LEDs timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(100) }; timer.Tick += OnTick; IsMonitoring = true; }
private async void Setup() { this.hat = await FEZHAT.CreateAsync(); this.dist = new UltrasonicDistanceSensor(hat); this.hat.S1.SetLimits(500, 2400, 0, 180); this.hat.S2.SetLimits(500, 2400, 0, 180); this.currentAction = RobotAction.forward; this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(100); this.timer.Tick += this.OnTick; this.timer.Start(); }
// rather perform initialization in loaded event private async void MainPage_Loaded(object sender, RoutedEventArgs e) { // initialize the FEZHAT var fez = await FEZHAT.CreateAsync(); // set the color of the red-green-blue LED labelled // D2 (diode 2) on the board to yellow fez.D2.Color = FEZHAT.Color.Yellow; while (true) { // update the runPressed Run's Text to be that of button DIO18's value runPressed.Text = fez.IsDIO18Pressed().ToString(); // wait 100ms await Task.Delay(100); } }
private async void RunWeatherLoop() { var fez = await FEZHAT.CreateAsync(); while (true) { var light = fez.GetLightLevel(); runLight.Text = light.ToString(); runTemperature.Text = fez.GetTemperature().ToString(); var brightness = 255 * (1 - light); fez.D2.Color = new FEZHAT.Color((byte)brightness, (byte)brightness, (byte)brightness); btnEllipse.Fill = new SolidColorBrush(fez.IsDIO18Pressed() ? Colors.Green : Colors.Red); await Task.Delay(100); } }
private async Task <bool> InitPhysicalDevice() { _fezhat = await FEZHAT.CreateAsync(); if (_fezhat != null) { _fezhat.DIO24On = true; _sampleTimer.Interval = TimeSpan.FromMilliseconds(50); _sampleTimer.Tick += SampleTimer_Tick; _sampleTimer.Start(); return(true); } return(false); }
/// <summary> /// メインページがロードされた処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void MainPage_LoadedAsync(object sender, RoutedEventArgs e) { // ConfigのDeviceIDが未設定の場合 if (Guid.Empty == ChobiIotConfig.DeviceId) { FixDeviceId(); if (_deviceId == "chobiPi") { Debug.Write("Please set devicdId or unique machine name"); throw new ArgumentOutOfRangeException("Please set devicdId or unique machine name"); } } else { _deviceId = ChobiIotConfig.DeviceId.ToString(); } tbDeviceId.Text = _deviceId.ToString(); // fezHatの初期化 _fezhat = await FEZHAT.CreateAsync(); // LEDセンサーをOFFにする _fezhat.D2.TurnOff(); _fezhat.D3.TurnOff(); // Device認証サーバーへ接続します try { var result = await TryConnect(); if (result) { await InitializeUpload(); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } // タイマーの初期化 lastSensorReading = new List <SensorReadingBuffer>(); measureTimer = new DispatcherTimer(); measureTimer.Interval = TimeSpan.FromMilliseconds(measureIntervalMSec); measureTimer.Tick += MeasureTimer_Tick; measureTimer.Start(); }
private async void SetupHat() { if (UseMockedSensors) { this.rnd = new Random(); } else { this.hat = await FEZHAT.CreateAsync(); } this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(500); this.timer.Tick += this.Timer_Tick; this.timer.Start(); }
public MainPage() { this.InitializeComponent(); this.Loaded += OnLoaded; var ai = AnalyticsInfo.VersionInfo; Debug.WriteLine(string.Format("Device Family = {0}", ai.DeviceFamily)); _isRunningOnPi = ai.DeviceFamily == "Windows.IoT"; //_isRunningOnPi = Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Devices.Gpio.GpioController"); BUG? Always returns true regardless of the device. if (_isRunningOnPi) { Task.Run(async() => _fezhat = await FEZHAT.CreateAsync()); _buttonMonitor = new DispatcherTimer(); _buttonMonitor.Interval = new TimeSpan(TimeSpan.TicksPerSecond / 4); _buttonMonitor.Tick += ButtonMonitorOnTick; _buttonMonitor.Start(); } }
private async void SetupAsync() { _hat = await FEZHAT.CreateAsync(); _timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(100) }; bool on = false; _timer.Tick += (s, e) => { _hat.D2.Color = on ? FEZHAT.Color.Red : FEZHAT.Color.Black; on = !on; }; _timer.Start(); }
public async void Run(IBackgroundTaskInstance taskInstance) { var deferral = taskInstance.GetDeferral(); var hat = await FEZHAT.CreateAsync(); for (int i = 0; i < 100; i++) { hat.D3.Color = FEZHAT.Color.Blue; SillyWait(); hat.D3.TurnOff(); SillyWait(); hat.D3.Color = FEZHAT.Color.Red; SillyWait(); hat.D3.TurnOff(); SillyWait(); } hat.Dispose(); deferral.Complete(); }
public async void initFezhat() { _hat = await FEZHAT.CreateAsync(); }
public FEZHATTemperatureRepository() { Log("Initialising FEZHAT mainboard"); mainboard = FEZHAT.CreateAsync().Result; }
public async Task InitializeAsync() { fezHat = await FEZHAT.CreateAsync(); }
public async Task InitiatizeAsync() { hat = await FEZHAT.CreateAsync(); }
private async void SetupAsync() { _hat = await FEZHAT.CreateAsync(); }
public async void CreateFezHAT() { this.hat = await FEZHAT.CreateAsync(); }