private async void Start() { _temperatureStepDetermined = false; _currentStatus = null; _currentScreenMode = ScreenMode.MainScreen; _client = new NefitClient(Settings.Default.serial, Settings.Default.accessKey, Settings.Default.password); _client.XmlLog += Log; if (await _client.ConnectAsync()) { tmrUpdate.Enabled = true; tmrUpdate_Tick(this,new EventArgs()); } else if (_client.ConnectionStatus == NefitConnectionStatus.InvalidSerialAccessKey) { MessageBox.Show(@"Authentication error: serial or accesskey invalid, please recheck your credentials", @"Authentication error", MessageBoxButtons.OK, MessageBoxIcon.Error); settingsToolStripMenuItem_Click(this, new EventArgs()); } else if (_client.ConnectionStatus == NefitConnectionStatus.InvalidPassword) { MessageBox.Show(@"Authentication error: password invalid, please recheck your credentials", @"Authentication error", MessageBoxButtons.OK, MessageBoxIcon.Error); settingsToolStripMenuItem_Click(this, new EventArgs()); } }
private async void tmrUpdate_Tick(object sender, EventArgs e) { try { if (_switchBackTicks > 0 && _currentScreenMode == ScreenMode.SetpointScreen) { _switchBackTicks -= 1000; if (_switchBackTicks <= 0) { if (_currentStatus!=null && _displaySetpoint != _currentStatus.TemperatureSetpoint) { _client.SetTemperature(_displaySetpoint); } _currentScreenMode = ScreenMode.MainScreen; Invalidate(); } } if (_client.ConnectionStatus == NefitConnectionStatus.Connected) { UIStatus stat = await _client.GetUIStatusAsync(); //UIStatus stat =_client.ParseUIStatus(); if (stat != null) { _currentStatus = stat; Invalidate(); } if ((_currentProgram == null && stat != null && stat.ClockProgram == ClockProgram.Auto) || (_currentProgram != null && stat != null && _currentProgram.Length > 1 && (DateTime.Now >= _currentProgram[1].Timestamp))) { if (_currentStatus.HedEnabled) { _currentProgram = await _client.ProgramAsync(2); } else { int program = await _client.GetActiveProgramAsync(); if (program >= 0 && program <= 2) { _currentProgram = await _client.ProgramAsync(program); } } Invalidate(); } if (!_temperatureStepDetermined) { _temperatureStep = await _client.EasyTemperatureStepAsync(); if (!double.IsNaN(_temperatureStep)) { _temperatureStepDetermined = true; } else { _temperatureStep = 0.5; } } } } catch { } }