using BPASmartClient.Business;
using BPA.Helper;
using BPASmartClient.Model.乐白机器人;
using BPA.Helper;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
namespace BPASmartClient.MorkTJAKAJC.ViewModel
{
public class MonitorViewModel: NotifyBase
{
#region 传感器
///
/// 机器人夹爪传感器
///
public bool RobotSenser { get { return _robotSenser; } set { _robotSenser = value; OnPropertyChanged(); } }
private bool _robotSenser;
///
/// 冰淇淋出口传感器
///
public bool IceCreamSenser { get { return _iceCreamSenser; } set { _iceCreamSenser = value; OnPropertyChanged(); } }
private bool _iceCreamSenser;
///
/// 取餐口检测传感器
///
public bool TakeMealSenser { get { return _takeMealSenser; } set { _takeMealSenser = value; OnPropertyChanged(); } }
private bool _takeMealSenser;
#endregion
///
/// 设备ID
///
int DeviceId;
public MonitorViewModel()
{
Plugin.GetInstance?.GetPlugin()?.GetDevices().ForEach(device =>
{
if (device.Name == "MorkT") DeviceId = device.DeviceId;
});
TaskManage.GetInstance.StartLong(new Action(() =>
{
EventBus.GetInstance.Publish(new LebaiRobot_GetTCPInputEvent() { DeviceId = DeviceId, Pin = 1 },(res)=>
{
if(res != null&& res.Length>0&& res[0] is bool b)
{
RobotSenser = b;
}
});
EventBus.GetInstance.Publish(new LebaiRobot_GetInputEvent() { DeviceId = DeviceId, Pin = 0 }, (res) =>
{
if (res != null && res.Length > 0 && res[0] is bool b)
{
TakeMealSenser = b;
}
});
EventBus.GetInstance.Publish(new LebaiRobot_GetTCPInputEvent() { DeviceId = DeviceId, Pin = 3 }, (res) =>
{
if (res != null && res.Length > 0 && res[0] is bool b)
{
IceCreamSenser = b;
}
});
Thread.Sleep(500);
}), "MorkT-传感器监视");
}
}
public class BoolToColorConvert : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool) value? new SolidColorBrush(Color.FromRgb(144, 238, 144)) : new SolidColorBrush(Color.FromRgb(178, 34, 34));
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}