private void FHub_OnDeviceAttached(Object Sender, wclWeDoIo Device) { if (Device.DeviceType == wclWeDoIoDeviceType.iodMotor) { if (FMotor1 == null) { { FMotor1 = (wclWeDoMotor)Device; EnablePlay1(true); } } else { if (FMotor2 == null) { { FMotor2 = (wclWeDoMotor)Device; EnablePlay2(true); } } } } if (FCurrent == null) { if (Device.DeviceType == wclWeDoIoDeviceType.iodCurrentSensor) { FCurrent = (wclWeDoCurrentSensor)Device; FCurrent.OnCurrentChanged += FCurrent_OnCurrentChanged; } } if (FVoltage == null) { if (Device.DeviceType == wclWeDoIoDeviceType.iodVoltageSensor) { FVoltage = (wclWeDoVoltageSensor)Device; FVoltage.OnVoltageChanged += FVoltage_OnVoltageChanged; } } }
private void FmMain_Load(Object sender, EventArgs e) { cbDirection1.SelectedIndex = 0; cbDirection2.SelectedIndex = 0; FManager = new wclBluetoothManager(); FWatcher = new wclWeDoWatcher(); FWatcher.OnHubFound += FWatcher_OnHubFound; FHub = new wclWeDoHub(); FHub.OnConnected += FHub_OnConnected; FHub.OnDisconnected += FHub_OnDisconnected; FHub.OnDeviceAttached += FHub_OnDeviceAttached; FHub.OnDeviceDetached += FHub_OnDeviceDetached; FHub.OnHighCurrentAlert += FHub_OnHighCurrentAlert; FHub.OnLowVoltageAlert += FHub_OnLowVoltageAlert; FMotor1 = null; FMotor2 = null; FCurrent = null; FVoltage = null; }
private void FHub_OnDeviceDetached(Object Sender, wclWeDoIo Device) { if (Device.DeviceType == wclWeDoIoDeviceType.iodMotor) { if (FMotor1 != null && FMotor1.ConnectionId == Device.ConnectionId) { FMotor1 = null; EnablePlay1(false); } if (FMotor2 != null && FMotor2.ConnectionId == Device.ConnectionId) { FMotor2 = null; EnablePlay2(false); } } if (Device.DeviceType == wclWeDoIoDeviceType.iodCurrentSensor) { FCurrent = null; } if (Device.DeviceType == wclWeDoIoDeviceType.iodVoltageSensor) { FVoltage = null; } }
private void UpdateTabs() { wclWeDoHub Hub = GetHub(); if (Hub == null) { RemoveTabs(); } else { AddPage(tsHubInfo); UpdateHubInfo(Hub); wclWeDoCurrentSensor Current = FRobot.GetCurrentSensor(Hub); if (Current != null && Current.Attached) { AddPage(tsCurrent); UpdateCurrent(Current); } wclWeDoVoltageSensor Voltage = FRobot.GetVoltageSensor(Hub); if (Voltage != null && Voltage.Attached) { AddPage(tsVoltage); UpdateVoltage(Voltage); } wclWeDoRgbLight Rgb = FRobot.GetRgbDevice(Hub); if (Rgb != null && Rgb.Attached) { AddPage(tsRgb); UpdateRgb(Rgb); } wclWeDoPiezo Piezo = FRobot.GetPiezoDevice(Hub); if (Piezo != null && Piezo.Attached) { AddPage(tsPiezo); UpdatePiezo(Piezo); } wclWeDoMotionSensor Motion = GetMotionSensor(0); if (Motion != null && Motion.Attached) { AddPage(tsMotion1); UpdateMotion(Motion); } Motion = GetMotionSensor(1); if (Motion != null && Motion.Attached) { AddPage(tsMotion2); UpdateMotion(Motion); } wclWeDoTiltSensor Tilt = GetTiltSensor(0); if (Tilt != null && Tilt.Attached) { AddPage(tsTilt1); UpdateTilt(Tilt); } Tilt = GetTiltSensor(1); if (Tilt != null && Tilt.Attached) { AddPage(tsTilt2); UpdateTilt(Tilt); } wclWeDoMotor Motor = GetMotor(0); if (Motor != null && Motor.Attached) { AddPage(tsMotor1); UpdateMotor(Motor); } Motor = GetMotor(1); if (Motor != null && Motor.Attached) { AddPage(tsMotor2); UpdateMotor(Motor); } } }
private void UpdateCurrent(wclWeDoCurrentSensor Sensor) { UpdateDeviceInfo(laCurrentVersion, laCurrentDeviceType, laCurrentConnectionId, Sensor); laCurrent.Text = Sensor.Current.ToString() + " mA"; }