void GetMotorTemp() { Task.Run(() => { bool worked = false; double temperature = 0; lock ( MotorLock ) { if (MotorCom.Open(MotorComPort)) { temperature = MotorCom.GetTemp(); MotorCom.Close(); worked = true; } else { Console.WriteLine("unable to open comport for GetMotorTemp"); return; } } if (worked) { //TODO: handle dual humidities for MotorHumidityLbl Action <double> update_action = (t) => { MotorBoardTempLbl.Content = "MOTOR BOARD TEMP: " + t.ToString("0.00") + "C/F?"; }; Dispatcher.BeginInvoke(update_action, temperature); } }); }
void PingMotor() { //TODO: add gui for motor ping. Task.Run(() => { bool worked = false; bool pinged = false; lock ( MotorLock ) { if (MotorCom.Open(MotorComPort)) { pinged = MotorCom.Ping(); MotorCom.Close(); worked = true; } else { Console.WriteLine("unable to open comport for GetMotorTemp"); return; } } if (worked) { //if (pinged) //Console.WriteLine("Motor ping success"); } }); }
void GetMotorHumidity() { Task.Run(() => { bool worked = false; double humidity = 0; lock ( MotorLock ) { if (MotorCom.Open(MotorComPort)) { humidity = MotorCom.GetHumidity(); MotorCom.Close(); worked = true; } else { Console.WriteLine("unable to open comport for GetMotorHumidity"); return; } } if (worked) { //TODO: handle dual humidities for MotorHumidityLbl //double MotorBoardHumidity = 0; //double BmsBoardHumidity = 0; Action <double> update_action = (h) => { MotorBoardHumidity = h; UpdateHumidityDisplay(); }; Dispatcher.BeginInvoke(update_action, humidity); } }); }
void SetKey(bool key_on) { Task.Run(() => { bool worked = false; lock ( MotorLock ) { if (MotorCom.Open(MotorComPort)) { MotorCom.SetKey(key_on); MotorCom.Close(); worked = true; } else { Console.WriteLine("failed to SetKey"); } } if (worked) { Action <bool> update_action = (k) => { KeyLbl.Content = k ? "KEY ON" : "KEY OFF"; }; Dispatcher.BeginInvoke(update_action, key_on); } }); }
/// <summary> /// Set motor Speed between 0 and 1.0. /// </summary> /// <param name="speed"></param> void SetSpeed(double speed) { Task.Run(() => { bool worked = false; if (speed < 0) { speed = 0; } lock ( MotorLock ) { if (MotorCom.Open(MotorComPort)) { MotorCom.SetSpeed(speed); MotorCom.Close(); worked = true; } else { Console.WriteLine("failed to SetSpeed"); } } if (worked) { Action <double> update_action = (s) => { BoatSpeedLbl.Content = speed.ToString("0.00"); }; Dispatcher.BeginInvoke(update_action, speed); } }); }
void SetDirection(MotorControllerCom.Direction direction) { Task.Run(() => { bool worked = false; lock ( MotorLock ) { if (MotorCom.Open(MotorComPort)) { MotorCom.SetDirection(direction); MotorCom.Close(); worked = true; } else { Console.WriteLine("failed to SetDirection"); } } if (worked) { string dir_string = "ERROR"; switch (direction) { case MotorControllerCom.Direction.Forward: dir_string = "FORWARD"; break; case MotorControllerCom.Direction.Reverse: dir_string = "REVERSE"; break; case MotorControllerCom.Direction.NoDirection: dir_string = "NO DIRECTION"; break; } Action <MotorControllerCom.Direction> update_action = (d) => { UpdateDirection(d); }; Dispatcher.BeginInvoke(update_action, direction); } }); }
void MotorBeep() { //todo: add this. lock (MotorLock) { if (MotorCom.Open(MotorComPort)) { MotorCom.Beep(); MotorCom.Close(); } else { Console.WriteLine("unable to open comport for MotorBeep"); return; } } }